Skip to content

Don't carry --overlay-src across an --args boundary - #840

Closed
syokensyo wants to merge 1 commit into
containers:mainfrom
syokensyo:fix/overlay-src-args-boundary
Closed

syokensyo wants to merge 1 commit into
containers:mainfrom
syokensyo:fix/overlay-src-args-boundary

Conversation

@syokensyo

Copy link
Copy Markdown

Problem

--overlay-src only increments a counter. When the matching overlay option is parsed, the source paths are recovered by indexing backwards from that option's position in argv. If the overlay option comes from an --args file, the recursive parser is working with a different argv, so the backwards indexing runs before the start of the file's argument vector and bwrap crashes:

$ printf '%s--overlay\0/rw\0/work\0/dest\0' '' > overlay.args
$ bwrap --overlay-src /usr --args 3 true 3<overlay.args
Segmentation fault

Change

--overlay-src has to be followed by another --overlay-src or an overlay option within the same argument list. Reject the combination with --args using the error message that is already used for a stray --overlay-src, instead of recursing into the file.

Verification

  • Added a subtest to tests/test-run.sh. Before the change it crashes with exit status 139; after the change it fails cleanly with the expected message.
  • meson test -C _build: 5 passed, 1 skipped (test-seccomp.py, no seccomp in this environment), 0 failed.

Fixes #828

Signed-off-by: syokensyo 8558176+syokensyo@users.noreply.github.com

--overlay-src only increments a counter; when the matching overlay
option is parsed, the source paths are recovered by indexing backwards
from that option's argv. If the overlay option comes from an --args
file, the recursive parser is working with a different argv, so the
backwards indexing reads before the start of the file's argument vector
and crashes.

The requirement that --overlay-src be followed by an overlay option
applies within one argument list, so reject the combination with the
error message already used for a stray --overlay-src, instead of
recursing into the file.

Fixes containers#828
Signed-off-by: syokensyo <8558176+syokensyo@users.noreply.github.com>
@rusty-snake

Copy link
Copy Markdown
Contributor

What is better/different to #829?

@syokensyo

Copy link
Copy Markdown
Author

Thanks — you're right, this is the same fix as #829, and #829 came first. I missed it while triaging #828; sorry for the duplicate.

The code change is identical: the same guard in parse_args_recurse() with the same error message. The differences are only cosmetic: the comment wording, and the test here checks the exact exit status (1) and the full error string instead of using the if ...; then assert_not_reached pattern.

I'll close this in favour of #829 to avoid duplicate work. If the stricter exit-status assertion is useful, I'm happy to add it to #829 instead.

@syokensyo syokensyo closed this Dec 3, 2026
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

2 participants