Repository navigation
cf-execd: Passed the runagent socket request to cf-runagent as one argument - #6506
Dhanu-dynamic wants to merge 1 commit into
Conversation
|
Thank you for submitting a PR! Maybe @craigcomstock can review this? |
larsewi
left a comment
There was a problem hiding this comment.
Rather than building a command string and rejecting characters that ArgSplitCommand() would split on, could you instead build the argv array directly and pass it straight to execv()? Might need a new variant of cf_open().
…gument
HandleRunagentRequest() reads one line from runagent.socket, the host to
hail, and for a non-localhost request built the command string
<bindir>/cf-runagent -b -H <request>
which cf_popen() runs as root after ArgSplitCommand() splits it into argv
on whitespace, treating quotes as delimiters. The request was interpolated
verbatim, so one containing a space, tab or quote appended further
arguments to cf-runagent. A caller allowed on the socket through
runagent_socket_allow_users (cfapache on an Enterprise hub) is only meant
to pick a host, but a request like "host -f /tmp/evil.cf" made cf-runagent
load another policy as root, and injected "-D", "-s" or "--remote-bundles"
reached the remote agents, which the socket interface is documented not to
allow. There is no shell, so this is argument injection, not command
injection.
Build the argv array directly and exec it, so the request is always a
single argument of -H whatever it contains, through a new cf_popen_argv()
that takes a ready-made argument vector; cf_popen_select() now splits the
command string and calls the same code. An empty request is still refused,
because '-H ""' would make cf-runagent fall back to the hosts list from
policy instead of hailing nothing.
The unit test points GetBinDir() at a stub cf-runagent that prints its
argv and checks that requests carrying whitespace or quotes arrive as one
argument.
Changelog: Title
Signed-off-by: Dhanraj E <dhanraj@labs.digiscrypt.com>
46c6a67 to
ac928bf
Compare
|
Makes sense, that's the better fix. Reworked it: the remote path now builds The unit test now points |
HandleRunagentRequest() reads one line from runagent.socket, the host to
hail, and for a non-localhost request built the command string
which cf_popen() runs as root after ArgSplitCommand() splits it into argv
on whitespace, treating quotes as delimiters. The request was interpolated
verbatim, so one containing a space, tab or quote appended further
arguments to cf-runagent. A caller allowed on the socket through
runagent_socket_allow_users (cfapache on an Enterprise hub) is only meant
to pick a host, but a request like "host -f /tmp/evil.cf" made cf-runagent
load another policy as root, and injected "-D", "-s" or "--remote-bundles"
reached the remote agents, which the socket interface is documented not to
allow. There is no shell, so this is argument injection, not command
injection.
Build the argv array directly and exec it, so the request is always a
single argument of
-Hwhatever it contains, through a newcf_popen_argv()that takes a ready-made argument vector;
cf_popen_select()now splits thecommand string and calls the same code. An empty request is still refused,
because
-H ""would make cf-runagent fall back to the hosts list frompolicy instead of hailing nothing.
The unit test points
GetBinDir()at a stub cf-runagent that prints itsargv and checks that requests carrying whitespace or quotes arrive as one
argument.