Bug#1066090: psmisc: killall --older-than doesn't work as documented in a container

2024-03-13 Thread Craig Small
Control: tag 1066090 fixed-upstream

On Wed, 13 Mar 2024 at 00:30, Tim Connors  wrote:

> I'm guessing it's looking at field 22 starttime in /proc/$pid/stat?
> starttime is seconds since boot.  Since the process exists in the
> parent system as well, starttime will surely be seconds since host
> boot?  But /proc/uptime is seconds since container boot.
>
/proc/uptime is sometimes seconds since host boot and sometimes seconds
since container boot.

Generally docker is the former, LXC is the latter but it's not consistent.
You can tell because if you run the uptime command
you'll see the difference. LXC basically overrides the uptime file with a
fuse-mounted file.You'd probably see there
is an issue with things like "ps -o etimes" as well which is where this
first was noticed.

There is already an upstream fix for this[1] in procps which uses
clock_gettime() instead so the start times are correct.
killall would be impacted by the same issue.
 - Craig

1:
https://gitlab.com/procps-ng/procps/-/commit/b5e19c1730bcc68d553f44b5585704e3c92267bf#83c45d853acc8384452b404946e4a0c484b16a4e_1519_1515


Bug#1066090: psmisc: killall --older-than doesn't work as documented in a container

2024-03-12 Thread Tim Connors
Package: psmisc
Version: 23.6-1
Severity: normal

killall --older-than 30s restartx11vnc x11vnc vncserver x0tigervncserver 
websockify

doesn't kill any processes inside my container, whereas it always used
to work on a VM and on hardware.  Removing '--older-than 30s' kills
all such processes.  I strongly suspect the culprit is how
/proc/$pid/stat is interpreted:

--older-than case:

3921851 openat(AT_FDCWD, "/proc/3918880", O_RDONLY|O_DIRECTORY) = 3
3921851 openat(3, "stat", O_RDONLY) = 4
3921851 fcntl(4, F_GETFL)   = 0x8000 (flags O_RDONLY|O_LARGEFILE)
3921851 newfstatat(4, "", {st_mode=S_IFREG|0444, st_size=0, ...}, 
AT_EMPTY_PATH) = 0
3921851 read(4, "3918880 (x11vnc) S 3918875 39184"..., 1024) = 336
3921851 close(4)= 0
3921851 openat(AT_FDCWD, "/proc/uptime", O_RDONLY) = 4
3921851 newfstatat(4, "", {st_mode=S_IFREG|0444, st_size=23, ...}, 
AT_EMPTY_PATH) = 0
3921851 read(4, "82599.37 82599.37\n", 4096) = 18
3921851 close(4)= 0
3921851 close(3)= 0

no such flag:

3960244 openat(AT_FDCWD, "/proc/3918880", O_RDONLY|O_DIRECTORY) = 3
3960244 openat(3, "stat", O_RDONLY) = 4
3960244 fcntl(4, F_GETFL)   = 0x8000 (flags O_RDONLY|O_LARGEFILE)
3960244 newfstatat(4, "", {st_mode=S_IFREG|0444, st_size=0, ...}, 
AT_EMPTY_PATH) = 0
3960244 read(4, "3918880 (x11vnc) S 1 3918464 366"..., 1024) = 332
3960244 close(4)= 0
3960244 pidfd_send_signal(3, SIGTERM, NULL, 0) = 0
3960244 close(3)= 0


I'm guessing it's looking at field 22 starttime in /proc/$pid/stat?
starttime is seconds since boot.  Since the process exists in the
parent system as well, starttime will surely be seconds since host
boot?  But /proc/uptime is seconds since container boot.



-- System Information:
Debian Release: 12.5
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable'), (5, 'testing'), (2, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.5.0-0.deb12.4-amd64 (SMP w/16 CPU threads; PREEMPT)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages psmisc depends on:
ii  libc6  2.36-9+deb12u4
ii  libtinfo6  6.4-4

psmisc recommends no packages.

psmisc suggests no packages.

-- no debconf information