Hi,

On Mon, Jun 30, 2025 at 11:36:59PM +0100, Andrew Bower wrote:
> Running 'w' as a non-root user on i386 segfaults:
> 
> $ gdb w
> GNU gdb (Debian 16.3-1) 16.3
> [...]
> This GDB was configured as "i686-linux-gnu".
> [...]
> (gdb) run
> Starting program: /usr/bin/w
> [Thread debugging using libthread_db enabled]
> Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
>  23:21:56 up 4 min,  0 users,  load average: 0.74, 1.06, 0.52
> USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
> 
> Program received signal SIGSEGV, Segmentation fault.
> Download failed: Invalid argument.  Continuing without source file ./src/w.c.
> 0x00401979 in main (argc=<optimized out>, argv=<optimized out>) at 
> src/w.c:1130
> warning: 1130   src/w.c: No such file or directory
>
> This reliably reproduces in the failing environment but not when run as root 
> or
> on an amd64 host with kernel 6.12.27-1.

The proximate cause seems to be that sessions is undefined and that
sessions_list is then also used, undefined. This part of the bug is
therefore not architecture-specific even if the crash is not generally
reproduced yet.

I attach a patch that fixes the segfault to advance the discussion.
Personally I think this ought to be fixed for trixie.

However, we are unfortunately not out of the woods: elogind is running
on this host and root is able to see the sessions. So is 'who' as
non-root with the newly libsystemd-ised coreutils:

$ w
 21:26:33 up 10 min,  0 users,  load average: 0.00, 0.10, 0.12
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
Segmentation fault
$ debian/procps/usr/bin/w # with patch
 21:26:42 up 11 min,  0 users,  load average: 0.00, 0.10, 0.12
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
$ sudo w
Please touch the FIDO authenticator.
 21:26:50 up 11 min,  1 user,  load average: 0.64, 0.23, 0.16
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
ajb85    pts/0    -                21:26    0.00s  0.03s  0.12s sudo w
$ sudo debian/procps/usr/bin/w # with patch
 21:26:54 up 11 min,  1 user,  load average: 0.59, 0.23, 0.16
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU  WHAT
ajb85    pts/0    -                21:26    0.00s  0.02s  0.06s sudo 
debian/procps/usr/bin/w
$ who
ajb85    seat0        2025-07-23 21:17
ajb85    tty1         2025-07-23 21:17

This secondary issue could of course be an elogingd problem so I am
copying this message to the elogind package tracker for awareness.

Thanks!
>From 3b519356a12c62e322287a2d0ffa0311da70f8a1 Mon Sep 17 00:00:00 2001
From: Andrew Bower <[email protected]>
Date: Wed, 23 Jul 2025 18:27:13 +0100
Subject: [PATCH] Initialise sessions variable in w. (Closes: #1108549)

---
 debian/patches/w_terminal_mode | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/debian/patches/w_terminal_mode b/debian/patches/w_terminal_mode
index 075a14f..e6e5a36 100644
--- a/debian/patches/w_terminal_mode
+++ b/debian/patches/w_terminal_mode
@@ -19,11 +19,14 @@ Description: w: Add terminal mode
      screens so its not real big difference.
   * From/IP won't work for utmp systems
  .
- This patch includes the upstreams original commit and the enhancement.
+ This patch includes the upstream's original commit and the enhancement.
+ .
+ Updated 2025-07-23 to avoid acting on the value of uninitialised sessions
+ variable.
 Author: Craig Small <[email protected]>
 Origin: upstream, https://gitlab.com/procps-ng/procps/-/commit/f53cc24d57085c87ebb1871b92c0069b72a60926
 Applied-Upstream: 4.0.6
-Last-Update: 2025-04-14
+Last-Update: 2025-07-23
 ---
 This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
 --- a/man/w.1
@@ -485,7 +488,7 @@ This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
 +        } else {
 +#if (defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)) && defined(HAVE_SD_SESSION_GET_LEADER)
 +	char **sessions_list;
-+	int sessions;
++	int sessions = 0;
 +	if (sd_booted() > 0)
  		sessions = sd_get_sessions (&sessions_list);
 -		if (sessions < 0 && sessions != -ENOENT)
-- 
2.50.0

Reply via email to