Package: procps
Version: 2:3.3.17-7.1
Severity: wishlist

Hey.

I have a script that matches on any ssh channel multiplexing process
(and then kills it) after printing them.

It basically does:
        pgrep --full --exact --euid "${LOGNAME}" --list-full -- "^ssh: 
${HOME}/\.ssh/mux/.+ \[mux]$"
        printf '\nPress return to kill these processes.\n'
        read tmp
        pkill --full --exact --euid "${LOGNAME}" -- "^ssh: ${HOME}/\.ssh/mux/.+ 
\[mux]$"

Where ".ssh/mux/<socket>" is simply my configured path.

I'm was also pretty sure that this script used to work (but no longer does now),
but I've tested on some ancient Debian, and even there it fails.

The reason seems to be, that there are trailing 0x00.

E.g. I have:
$ cat /proc/34724/cmdline | hd
00000000  73 73 68 3a 20 2f 68 6f  6d 65 2f 63 61 6c 65 73  |ssh: /home/cales|
00000010  74 79 6f 2f 2e 73 73 68  2f 6d 75 78 2f 72 6f 6f  |tyo/.ssh/mux/roo|
00000020  74 40 6c 63 67 2d 6c 72  7a 2d 61 64 6d 69 6e 2e  |t@lcg-lrz-admin.|
00000030  67 72 69 64 2e 6c 72 7a  2e 64 65 3a 32 32 20 5b  |grid.lrz.de:22 [|
00000040  6d 75 78 5d 00 00 00 00  00 00                    |mux]......|
0000004a

$ pgrep --full --exact --euid "${LOGNAME}" --list-full -- "^ssh: 
${HOME}/\.ssh/mux/.+ \[mux]$"
$

$ pgrep --full --exact --euid "${LOGNAME}" --list-full -- "^ssh: 
${HOME}/\.ssh/mux/.+ \[mux].+$"
34724 ssh: /home/calestyo/.ssh/mux/r...@lcg-lrz-admin.grid.lrz.de:22 [mux]     
$
works again, but is of course inferior, as it would posibly match undesired
processes.


In POSIX EREs it should never be possible to match 0x00.

Wouldn't it therefore make sense to e.g. strip any trailing 0x00 from cmdline
and e.g. print a warning if any non-trailing ones are encountered?
Or maybe add some commant line switches, one that allows to ignore trailing
0x00 one, that allows to ignore non-trailing ones.



Thanks,
Chris.



-- System Information:
Debian Release: bookworm/sid
  APT prefers unstable-debug
  APT policy: (500, 'unstable-debug'), (500, 'unstable')
merged-usr: no
Architecture: amd64 (x86_64)

Kernel: Linux 6.0.0-2-amd64 (SMP w/16 CPU threads; PREEMPT)
Kernel taint flags: TAINT_WARN
Locale: LANG=en_DE.UTF-8, LC_CTYPE=en_DE.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages procps depends on:
ii  init-system-helpers  1.64
ii  libc6                2.36-4
ii  libncurses6          6.3+20220423-2
ii  libncursesw6         6.3+20220423-2
ii  libprocps8           2:3.3.17-7.1
ii  libtinfo6            6.3+20220423-2

Versions of packages procps recommends:
ii  psmisc  23.5-3

procps suggests no packages.

-- Configuration Files:
/etc/sysctl.conf changed [not included]

-- no debconf information

Reply via email to