64-bit integer overflow computing user CPU time in calcru1() in kern_resource.c

From: <sthaug_at_nethelp.no>
Date: Sun, 10 Feb 2019 12:03:14 +0100 (CET)
There is a 64-bit integer overflow computing user cpu time in calcru1()
in kern_resource.c. This was discovered because CPU statistics from
the PowerDNS-recursor name server stopped working (essentially, got
"stuck") after a while:

time_t          milliseconds
1547818832      301274008.418503
1547822864      301784302.665002
1547826896      302310096.107672
1547830928      302844638.859146
1547834960      303381189.070208
1547838992      303924399.662413
1547843024      304477529.572919
1547847056      305025750.193424
1547851088      305544141.140036
1547855120      306001630.092938
1547859152      306153010.535298
1547863184      306141696.000000
1547867216      306141696.000000
1547871248      306141696.000000
1547875280      306141696.000000
1547879312      306141696.000000
1547883344      306141696.000000
1547887376      306141696.000000

Note that the number just stops increasing beyond 1547863184.

I complained about this on the Pdns-user mailing list,

https://mailman.powerdns.com/pipermail/pdns-users/2019-January/025739.html

and received help from Bert Hubert of PowerDNS to find

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=227689

and it definitely looks like this is the bug causing the disappearing
CPU statistics graphs.

I fixed the problem by following the link from the FreeBSD bug above to

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=76972

which has an attachment (kern_resource.c.patch.txt) at

https://bz-attachments.freebsd.org/attachment.cgi?id=50537

After adding this patch and rebooting, the problem has not reoccurred.
I assume Bjorn Zeeb's patch has indeed fixed the problem.

Note that the problem was discovered in 11.2-STABLE r338949 - however,
looking at

https://svnweb.freebsd.org/base/head/sys/kern/kern_resource.c?view=markup

exactly the same user CPU time code seems to be present in HEAD, so I
assume the same overflow is also present.

I sent a message about this problem on the FreeBSD-stable mailing list
recently,

https://lists.freebsd.org/pipermail/freebsd-stable/2019-February/090523.html

but with no reaction there I'm now trying FreeBSD-current. I'm hoping
for bz's patch to be applied to HEAD, and at some point an MFC to
11.2-STABLE.

Steinar Haug, Nethelp consulting, sthaug_at_nethelp.no
Received on Sun Feb 10 2019 - 10:03:24 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:20 UTC