Repository navigation
drivers/pipes: validate parameters and flags in pipe2 and file_pipe - #21938
Merged
xiaoxiang781216 merged 1 commit intoNov 17, 2026
Merged
Conversation
POSIX IEEE Std 1003.1 and Linux specifications (pipe2(2)) specify parameter and flags validation for pipe2: 1. Validate pipefd pointer in pipe2(): Linux pipe2(2) specifies that passing an invalid pipefd shall fail with EFAULT. Previously, pipe2() dereferenced fd[1] directly without checking fd != NULL, resulting in an immediate CWE-476 NULL pointer dereference kernel panic. 2. Validate flags against O_CLOEXEC and O_NONBLOCK: Linux pipe2(2) specifies that flags containing any bits other than O_CLOEXEC and O_NONBLOCK shall fail with EINVAL. Previously, NuttX did not validate flags, silently accepting invalid bits. 3. Avoid premature driver registration on invalid arguments: Previously, pipe2() called pipe_register() to register /dev/pipe/N and allocate pipe structures before validating input arguments. Validating fd and flags upfront avoids premature device registration and memory allocation on invalid parameters. 4. Defensively validate pointers and flags in file_pipe(): Validates filep != NULL && filep[0] != NULL && filep[1] != NULL and flags against ~(O_CLOEXEC | O_NONBLOCK), returning -EINVAL on invalid input. Assisted-by: Google DeepMind:antigravity Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
requested review from
jerpelea,
tmedicci and
xiaoxiang781216
as code owners
November 17, 2026 09:57
xiaoxiang781216
approved these changes
Nov 17, 2026
|
GUIDINGLI
approved these changes
Nov 17, 2026
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
POSIX IEEE Std 1003.1 and Linux specifications (
pipe2(2)) specify parameter and flags validation forpipe2():POSIX / Linux
pipefdValidation:Linux
pipe2(2)explicitly mandates:POSIX / Linux Flags Validation:
Linux
pipe2(2)explicitly mandates:Avoid Premature Driver Registration & Resource Allocation:
Previously,
pipe2()calledpipe_register(CONFIG_DEV_PIPE_SIZE, ...)to allocate minor numbers, allocate heap memory viapipecommon_allocdev(), and register/dev/pipe/Nin the VFS before checking parameters. Moving validation upfront ensures invalid system calls fail immediately without allocating heap memory or registering dangling/dev/pipe/Ndrivers.Defensive Pointer Validation in
file_pipe():Defensively validates
filep != NULL && filep[0] != NULL && filep[1] != NULLreturning-EINVALbefore dereferencing file pointers, and rejects invalid flag bits.Before vs. After Behavior
pipe(NULL)orpipe2(NULL, 0)fd[1]directly (Kernel Panic / Crash)ERROR,errno = EFAULTpipe2(fd, 0x1234)(invalid flags)ERROR,errno = EINVALpipe2(NULL, ...)or bad flags)/dev/pipe/Nbefore crashingfile_pipe(NULL, ...)or invalid flags-EINVALImpact
pipe(NULL)orpipe2(NULL, ...)is called.EFAULTon invalid pointers andEINVALon invalid flag bits per Linuxpipe2(2).pipe2()invocations from allocating heap device memory or leaking/dev/pipe/Ndriver entries in the VFS.0,O_CLOEXEC, orO_NONBLOCKcontinue to work without any changes.Testing
1. Build Verification
Cleanly built with
arm-none-eabi-gcc 10.3.1onsam4s-xplained-pro:nsh(CONFIG_PIPES=y,CONFIG_DEV_PIPE_SIZE > 0):2. Code Style Verification
Checked with
nxstyleinside Docker:3. What Was Not Tested