Skip to content

fs/vfs: validate parameters and buffer alignment in signalfd - #21852

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/vfs-signalfd-posix-validation
Nov 17, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:fix/vfs-signalfd-posix-validation

Conversation

@Swatantra-66

@Swatantra-66 Swatantra-66 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR validates parameters and fixes error handling in fs/vfs/fs_signalfd.c:

  1. signalfd():

    • mask == NULL Validation: Added validation that mask != NULL, returning EFAULT (-1 with errno = EFAULT) per Linux signalfd(2) / POSIX specification. Previously, passing a NULL mask directly dereferenced *mask, causing a kernel panic (CWE-476 NULL pointer dereference).
    • Non-Inode Descriptor Safety: Validated that filep->f_inode != NULL before accessing filep->f_inode->u.i_ops. If signalfd(fd, ...) is called on a valid non-inode descriptor (such as a socket or pseudo-descriptor without an inode), dereferencing f_inode->u.i_ops caused a NULL pointer dereference kernel panic. It now returns EINVAL as specified by signalfd(2).
  2. signalfd_file_read():

    • POSIX Error Separation: Separated buffer == NULL and size check. buffer == NULL returns -EFAULT per POSIX read(2) ([EFAULT] buf is outside your accessible address space). A buffer size less than sizeof(struct signalfd_siginfo) returns -EINVAL per signalfd(2).
    • Stack-Efficient Direct Writes: Writes directly into (FAR struct signalfd_siginfo *)buffer to avoid allocating 128 bytes of temporary structure on the kernel stack and eliminate memcpy overhead.
  3. signalfd_notify():

    • Added group == NULL defensive check to prevent NULL pointer dereference if invoked during early teardown.

Comparison Table

Issue / System Call Prior Behavior Hardened POSIX Behavior Specification
signalfd(-1, NULL, 0) Kernel Panic (CWE-476 NULL dereference of *mask) Returns -1 with errno = EFAULT Linux signalfd(2)
signalfd(sock_fd, &mask, 0) Kernel Panic (dereference f_inode->u.i_ops when f_inode == NULL) Returns -1 with errno = EINVAL Linux signalfd(2)
read(sfd, NULL, len) Returns -1 with errno = EINVAL Returns -1 with errno = EFAULT POSIX read(2)
read(sfd, buf, < sizeof(siginfo)) Returns -1 with errno = EINVAL Returns -1 with errno = EINVAL Linux signalfd(2)

Impact

  • Is new feature added? No.
  • Impact on user: None. Corrects POSIX error codes and prevents kernel crashes on invalid inputs.
  • Impact on build: None.
  • Impact on hardware: None.
  • Impact on documentation: None.
  • Impact on security: Hardens against CWE-476 NULL pointer dereferences.

Testing

  • Host OS: Windows 11 (Docker container nuttx-builder Linux x86_64)
  • Target: sim:nsh with CONFIG_SIGNAL_FD=y
  • Compiler: GCC / Ubuntu clang

1. Code Style Check (nxstyle)

$ ./tools/nxstyle fs/vfs/fs_signalfd.c
# Exit code: 0 (0 errors, 0 warnings)

2. Build Verification

$ make -j$(nproc)
...
CC:  fs/vfs/fs_signalfd.c
AR:  staging/libfs.a fs_signalfd.o
LD:  nuttx
Pac SIM with dynamic libs..
SIM elf with dynamic libs archive in nuttx.tgz
# Exit code: 0

3. Binary Size

   text    data     bss     dec     hex filename
   2343      72       0    2415     96f /repos/nuttx/fs/fs_signalfd.o
 604233    5340   46752  656325   a03c5 /repos/nuttx/nuttx

4. Simulator Boot and Runtime Test

nsh> help
help usage:  help [-v] [<cmd>]

    .            break        exec         mkdir        rm           true         
    [            cat          exit         mkfifo       rmdir        truncate     
    ?            cd           expr         mkrd         rmmod        uname        
    addroute     cp           false        mount        set          umount       
    alias        cmp          help         mv           kill         unset        
    unalias      dirname      hexdump      nslookup     sleep        uptime       
    arp          date         insmod       poweroff     usleep       watch        
    base64dec    delroute     losetup      quit         source       xd           
    base64enc    dmesg        ls           printf       test         
    basename     echo         du           pwd          time         

Builtin Apps:
    dd      init    nsh     sh      
nsh> exit

@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

Comment thread fs/vfs/fs_signalfd.c Resolved
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

ci fixed by #21771.

@Swatantra-66
Swatantra-66 force-pushed the fix/vfs-signalfd-posix-validation branch 2 times, most recently from aa91969 to 7de77ef Compare November 15, 2026 07:41
@Swatantra-66
Swatantra-66 force-pushed the fix/vfs-signalfd-posix-validation branch from 7de77ef to 1f64c11 Compare November 15, 2026 11:46
1. signalfd():
   - Validate that mask != NULL; return -EFAULT if NULL, matching
     Linux signalfd(2) specification and preventing CWE-476 NULL
     pointer dereference.
   - Validate that filep->f_inode != NULL before inspecting ops,
     preventing kernel panic when invoked on non-inode descriptors.

2. signalfd_file_read():
   - Separate buffer validation: return -EFAULT if buffer == NULL,
     and -EINVAL if len < sizeof(struct signalfd_siginfo), strictly
     adhering to POSIX read(2) and signalfd(2).

3. signalfd_notify():
   - Guard against group == NULL to prevent NULL pointer dereference.

Assisted-by: Google DeepMind:antigravity
Signed-off-by: Swatantra Yadav <[email protected]>
@Swatantra-66
Swatantra-66 force-pushed the fix/vfs-signalfd-posix-validation branch from 1f64c11 to a57bbfc Compare November 16, 2026 07:30

@jerpelea jerpelea left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please split in 3 commits in same PR

@xiaoxiang781216
xiaoxiang781216 merged commit e4a7ebf into apache:master Nov 17, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants