Skip to content

various fixes - #2173

Open
giuseppe wants to merge 5 commits into
containers:mainfrom
giuseppe:various-fixes
Open

various fixes#2173
giuseppe wants to merge 5 commits into
containers:mainfrom
giuseppe:various-fixes

Conversation

@giuseppe

Copy link
Copy Markdown
Member

more details in each commit

@eriksjolund PTAL

giuseppe and others added 5 commits August 10, 2026 08:17
Only the first byte of the buffer is ever inspected, so a two byte
buffer is bigger than needed.  Reduce it to a single byte and read
sizeof (buf) accordingly.

Closes: containers#2160

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The 256 byte buffer is much bigger than needed: the code only compares
the leading "unconfined" token.  Size the buffer to that token plus one
byte, which is all the comparison requires.

Closes: containers#2161

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The previous check had a few problems:

- a short read (fewer bytes than "unconfined") returned 0, reporting the
  process as unconfined, when the safe assumption is that it is confined;
- a profile named e.g. "unconfined_foo" matched on the first 10 bytes and
  was reported as unconfined; require the token to be followed by a
  delimiter (end of data, '\n' or ' ');
- the return value was the raw memcmp() result, which can be negative and
  would be misinterpreted by callers as an error;
- the read was not wrapped in TEMP_FAILURE_RETRY, so an EINTR turned into
  a spurious hard error.

Normalize the result to 1 (confined) / 0 (unconfined) and default to
confined whenever the token does not match exactly.

Closes: containers#2165

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mount_masked_dir() aliased the container-owned private_data->maskdir_fd
into a cleanup_close local, which created two owners for the same
descriptor.  On the fstat() failure path the cleanup handler closed the
descriptor while private_data kept the stale number (later double closed
at teardown); on the fs_move_mount_to() failure path the descriptor was
closed explicitly and then a second time by the cleanup handler, with
do_mount() running in between and able to reuse the number.

Stop aliasing: use private_data->maskdir_fd directly for the fallible
operations and let the cleanup_close local own only the newly created
bind mount.  private_data->maskdir_fd is replaced only at the end, once
no further error is possible, so ownership is never shared.

Closes: containers#2170
Closes: containers#2171

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On the fs_move_mount_to() failure path in mount_masked_dir() tmp_err is
always NULL, so the "tmpfs fallback" warning always printed "unknown
error" and the ternary guarding it always took the false branch.

Capture the errno from fs_move_mount_to() into tmp_err so the fallback
warning reports the actual reason.  Save errno before anything else can
clobber it and release any previously stored error first, so tmp_err is
never overwritten (and leaked) while holding an allocation.

Closes: containers#2172

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.

1 participant