Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 119631 - rcscripts/sh/rc-daemon.sh might kill init (pid 1)
Summary: rcscripts/sh/rc-daemon.sh might kill init (pid 1)
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: Highest critical (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-19 18:39 UTC by Mark Dominik Bürkle
Modified: 2006-01-20 02:48 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Dominik Bürkle 2006-01-19 18:39:57 UTC
(sorry for not searching and creating a "p1/critical" bug, if this is a duplicate)

--- /lib/rcscripts/sh/._cfg0000_rc-daemon.sh    2006-01-20 03:27:34.000000000 +0100
+++ /tmp/._cfg0000_rc-daemon.sh 2006-01-19 18:54:47.000000000 +0100
@@ -145,7 +145,7 @@
                                pkill "-${signal}" -s "${pid}"
                                pgrep -s "${pid}" >/dev/null || return 0
                        else
-                               local pids="$(ps -eo pid,sid | sed -n 's/'${pid}'$//p')"
+                               local pids="$(ps -eo pid,sid | sed -n 's/[[:space:]]'${pid}'$//p')"

                                [[ -z ${pids} ]] && return 0
                                kill -s "${signal}" ${pids} 2>/dev/null
                                e=false


Explanation:

imagine "Your" pid is 2345, and some process/session-id list like

1     0
2345  1
22334 12345
31567 2345
31568 2345
31569 2345

As '12345'(\NL) is matched by '2345$', sed would cut out the "2345" and then output the remainder of the 3rd line as "22334 1" which would lead to
 a) a "foreign" worker-pid being killed and, much worse,
 b) init being killed.
Result would be sth. like "panic - attempt to kill init"...

Regards,
Dominik
Comment 1 Mark Dominik Bürkle 2006-01-19 18:41:56 UTC
btw, I'd prefer to write that sed-command which includes a variable expansion as

  local pids="$( ps -eo pid,sid | sed -n "s/[[:space:]]${pid}\$//p" )"
Comment 2 Mark Dominik Bürkle 2006-01-19 20:09:38 UTC
line 300 should be changed as well:

-  npids="${npids} $(ps -eo pid,ppid | sed -n 's/'"${pid}"'$//p')"
+  npids="${npids} $( ps -eo pid,ppid | sed -n "s/[[:space:]]${pid}\$//p" )"
Comment 3 Roy Marples (RETIRED) gentoo-dev 2006-01-20 02:48:21 UTC
Thanks for the patch!

Fixed in baselayout-1.12.0_pre15