Skip to content

Reject --overlay-src that is followed by --args - #829

Open
sarankumar1325 wants to merge 1 commit into
containers:mainfrom
sarankumar1325:overlay-src-args
Open

sarankumar1325 wants to merge 1 commit into
containers:mainfrom
sarankumar1325:overlay-src-args

Conversation

@sarankumar1325

Copy link
Copy Markdown

Fixes #828.

--overlay, --tmp-overlay and --ro-overlay read their --overlay-src paths back from argv (argv[1 - 2 * i] in make_setup_overlay_src_ops()). next_overlay_src_count is global, but argv belongs to one argument list. So when --overlay-src is on the command line and the --overlay comes from an --args file, the lookup reads before the start of the file's argument vector and bwrap crashes:

$ printf -- '--overlay\0/rw\0/work\0/dest\0' > args.bin
$ bwrap --overlay-src /usr --args 3 true 3< args.bin
Segmentation fault (core dumped)

This PR makes --args fail with the existing "--overlay-src must be followed by another --overlay-src or one of --overlay, --tmp-overlay, or --ro-overlay" error while --overlay-src options are pending. That matches the documented rule: the option after --overlay-src here is --args, not an overlay option. The other direction (--overlay-src at the end of an --args file, --overlay on the command line) already failed with that error once the file was parsed. Putting --overlay-src and its --overlay in the same file still works.

With this change the command above prints the error and exits with status 1.

Test: new case in tests/test-run.sh right after the existing --args test. It segfaults on main and passes with the fix. meson test locally: test-run.sh 62 ok, test-sandbox.py 68 ok, test-utils, pidns and userns ok; test-seccomp.py skipped (no python3-seccomp on my box).

I used an AI assistant for this change. I reproduced the crash, reviewed the patch and ran the tests myself.

The --overlay, --tmp-overlay and --ro-overlay options read their
--overlay-src paths back from argv, counting backwards from their own
position. next_overlay_src_count is global, but argv is per argument
list, so an --overlay-src on the command line followed by an --overlay
inside an --args file made make_setup_overlay_src_ops() index before
the start of the file's argument vector and crash with SIGSEGV.

Fail with the usual "--overlay-src must be followed by ..." error when
--args is reached while --overlay-src options are pending, the same as
for any other option in that position.

Fixes: containers#828
Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault parsing --overlay-src when the matching --overlay is in a --args file

1 participant