Repository navigation
fix(util): close received descriptors on invalid messages - #388
Open
FranprzDev wants to merge 1 commit into
Open
FranprzDev wants to merge 1 commit into
FranprzDev wants to merge 1 commit into
Conversation
|
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Make descriptor ownership explicit at the
recvMsg()boundary:MSG_CMSG_CLOEXEC, so they do not become inheritable just because they were passed over a socket.-1.recvmsg()can install descriptors even when its payload is too short. The old early return loses those descriptors. It also accepts a truncated control message as successful. This is descriptor-lifetime hardening, not a claim of a demonstrated sandbox escape.Tests
Added
tests/util_msg_test.cc, wired intomake test. It uses local Unix socketpairs, without starting nsjail or creating namespaces. Eleven cases cover stream and sequenced-packet sockets, CLOEXEC, short payloads, truncated control data, extra descriptors, no descriptor output, and an oversized packet. Each case checks the process's FD count after cleanup.Against the original
util.cc, isolated checks fail for missing CLOEXEC, leaked descriptors after a short payload, acceptance of truncated control data, and acceptance of an oversized sequenced packet. Valid extra-descriptor and no-output controls pass. With the patch, all eleven cases pass.Validation run locally:
util_msg_test,nstun_buffer_budget_test,nstun_policy_test,nstun_ip_test,nstun_udp_peer_test.clang-format --dry-run --Werror util.cc tests/util_msg_test.ccandgit diff --checkpassed.make allpassed with the existing compatibility valueUSER_DEFINES=-DPR_SCHED_CORE_SCOPE_THREAD_GROUP=1. The local Ubuntu 22.04 headers lack that constant while definingPR_SCHED_CORE, so the existing fallback inmissing_defs.hdoes not supply it. No source workaround is included in this PR. Optional libnl support was not enabled in this local build.The privileged/network integration suite was not run.
AI tooling assisted this contribution. The code and tests were reviewed, and the listed commands were run locally.