Skip to content

contain: retain proc fd directory for descriptor sealing - #294

Open
soul-sol wants to merge 1 commit into
google:masterfrom
soul-sol:harden-inherited-fd-sealing
Open

contain: retain proc fd directory for descriptor sealing#294
soul-sol wants to merge 1 commit into
google:masterfrom
soul-sol:harden-inherited-fd-sealing

Conversation

@soul-sol

Copy link
Copy Markdown

Problem

The final descriptor-sealing pass first tries
close_range(..., CLOSE_RANGE_CLOEXEC), then enumerates /proc/self/fd,
then falls back to scanning descriptor numbers 0 through 1023.

When close_range() is unavailable or denied and mount/chroot setup hides
/proc, inherited descriptors above 1023 are not marked close-on-exec and can
survive into the jailed target.

Change

Open /proc/self/fd before mount namespace setup and retain that directory
stream until the final descriptor-sealing pass. The pass can then enumerate the
complete final descriptor set even when the configured jail does not expose
/proc.

The existing order is preserved:

  1. use close_range() when available;
  2. enumerate the retained or current proc directory;
  3. retain the bounded fallback if neither mechanism is available.

The retained stream is closed by its owner on every containProc() return path.

Verification

  • Baseline with close_range() forced to return EPERM, --disable_proc, and
    an inherited descriptor 1500: the target can observe descriptor 1500.
  • Patched build under the same conditions: descriptor 1500 is closed before
    target execution.
  • Explicit --pass_fd 1500 remains preserved.
  • A closed --pass_fd number reused by the retained proc directory is released
    by the stream owner before target execution.
  • Standalone-once, standalone-execve, PID namespace, --execute_fd, and
    listen-mode paths were exercised.
  • The repository Docker build completes with -Werror.

This is a hardening change for the process-isolation boundary and does not
change the behavior of explicitly passed descriptors.

Signed-off-by: solim <7576268+soul-sol@users.noreply.github.com>
@google-cla

google-cla Bot commented Jul 28, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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