Bug#1053731: atop crashes with a floating point exception when atopaccdt service fails

2023-12-23 Thread Witold Baryluk
Package: atop
Version: 2.9.0-2
Followup-For: Bug #1053731
X-Debbugs-Cc: witold.bary...@gmail.com



Version 2.9.0-2

This is still broken in current version:

Program received signal SIGFPE, Arithmetic exception.
0x555685d0 in acctprocnt () at ./acctproc.c:673
673 ./acctproc.c: No such file or directory.
(gdb) bt
#0  0x555685d0 in acctprocnt () at ./acctproc.c:673
#1  0x55562038 in engine () at ./atop.c:787
#2  main (argc=, argv=) at ./atop.c:563
(gdb) 


This is a default configuration (zero modifications, just install
packages). First time startup. Subsequent startups also fail the same
way. This causes systemd unit atop.service to be always in failed state,
and restarting it does not help.

atopacct.service also fails to start. But I am not sure if this is
because atop fails, or reverse.


Regards,
Witold



Bug#1053731: atop crashes with a floating point exception when atopaccdt service fails

2023-10-09 Thread Vladimir Petko
Package: atop
Severity: wishlist
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu mantic ubuntu-patch
X-Debbugs-Cc: vladimir.pe...@canonical.com

Dear Maintainer,

When the atopacctd service crashes, it may leave a 0-length shadow file.
atopacctd() routine tries to read it and fails. It returns 1 (success)
and sets maxshadowrec size to the size from the 'current' file. The rest
of the code assumes that the shadow file read was successful and tries
to use an empty acct structure, causing a division by zero.
This was reproduced during armhf autopkgtest in Ubuntu because atopacctd did
not have sufficient permissions to run.
The issue was fixed upstream and the commit was applied as a patch.

In Ubuntu, the attached patch was applied to achieve the following:

  * d/p/atopacctd_return_error.patch: apply upstream patch to fix SIGFPE in
acctprocnt() (LP: #1725896, LP: #2037910).


Thanks for considering the patch.


-- System Information:
Debian Release: bookworm/sid
  APT prefers lunar-updates
  APT policy: (500, 'lunar-updates'), (500, 'lunar-security'), (500, 'lunar'), 
(100, 'lunar-backports')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.2.0-34-generic (SMP w/32 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
diff -Nru atop-2.9.0/debian/patches/atopacctd_return_error.patch 
atop-2.9.0/debian/patches/atopacctd_return_error.patch
--- atop-2.9.0/debian/patches/atopacctd_return_error.patch  1970-01-01 
12:00:00.0 +1200
+++ atop-2.9.0/debian/patches/atopacctd_return_error.patch  2023-10-05 
15:25:12.0 +1300
@@ -0,0 +1,31 @@
+Description: Avoid floating point exception when atopacctd fails
+ When the atopacctd service crashes, it may leave a 0-length shadow file.
+ atopacctd() routine tries to read it and fails. It returns 1 (success)
+ and sets maxshadowrec size to the size from the 'current' file. The rest
+ of the code assumes that the shadow file read was successful and tries
+ to use an empty acct structure, causing a division by zero.
+Author: Gerlof Langeveld 
+Bug: https://github.com/Atoptool/atop/issues/277
+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/atop/+bug/2037910
+Applied-Upstream: 
https://github.com/Atoptool/atop/commit/f72f7c06278ec9ad2209975eca67c2e3c0b3a44b
+Last-Update: 2023-10-08
+--- a/acctproc.c
 b/acctproc.c
+@@ -430,7 +430,6 @@ atopacctd(int swon)
+   {
+   if ( swon && !acctvers(acctfd) )
+   {
+-
+   int maxcnt = 40;
+
+   if ( fork() == 0 )
+@@ -453,7 +452,8 @@ atopacctd(int swon)
+   , 1);
+
+   regainrootprivs();
+-  return 1;
++  maxshadowrec = 0;
++  return -1;  // try other
+   }
+   }
+
diff -Nru atop-2.9.0/debian/patches/series atop-2.9.0/debian/patches/series
--- atop-2.9.0/debian/patches/series2023-07-02 02:37:19.0 +1200
+++ atop-2.9.0/debian/patches/series2023-10-05 15:25:12.0 +1300
@@ -15,3 +15,4 @@
 no-atopgpud
 handle-default-file
 default
+atopacctd_return_error.patch