You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
proc_config: decompress without a shell, and without naming the file twice
The zcat fallback built a command string and ran it through popen, which
runs /bin/sh. A shell expands $( ) inside double quotes, so a resolved
path containing one executed: a directory named r$(touch FILE) holding
proc/config.gz, passed as KASLD_SYSROOT, created FILE. The comment above
it argued the double-quoting was sufficient, which is not a property
shells have.
It was not a rare path either. No musl toolchain ships zlib, so HAVE_ZLIB
is empty on all seventeen cross builds and the shell form was the only
decompressor there.
Open the file once and identify it by descriptor thereafter. zcat reads
standard input when given no file argument, so the child gets the open fd
and never the name — no command string, no argument vector, nothing left
to quote. Where zlib is linked, gzdopen adopts the same descriptor, so
both paths differ only in what they hand it to.
That also closes the gap between the check and the use: access() tested
one name and the decompressor opened it again, and open() reports the same
EACCES/EPERM the exit classifier already keys on, so kasld_access,
kasld_resolve and the path buffer are all unnecessary now.
execvp rather than execv, since zcat is /bin/zcat on some systems and
/usr/bin/zcat on others; PATH belongs to the user running kasld, the same
trust the shell form already assumed. The child is reaped so an absent
zcat is distinguishable from a file that was not gzip, with the
empty-output test still deciding.
0 commit comments