This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new e4a7ebf8f09 fs/vfs: validate parameters and fix error handling in
signalfd
e4a7ebf8f09 is described below
commit e4a7ebf8f094b70bfb0cf309457cd0c95fa10e55
Author: Swatantra Yadav <[email protected]>
AuthorDate: Fri Nov 13 20:41:13 2026 +0530
fs/vfs: validate parameters and fix error handling in signalfd
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]>
---
fs/vfs/fs_signalfd.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/fs/vfs/fs_signalfd.c b/fs/vfs/fs_signalfd.c
index f86f0b7062b..30eda5db05e 100644
--- a/fs/vfs/fs_signalfd.c
+++ b/fs/vfs/fs_signalfd.c
@@ -26,6 +26,7 @@
#include <nuttx/config.h>
#include <stdio.h>
+#include <string.h>
#include <poll.h>
#include <assert.h>
#include <errno.h>
@@ -157,12 +158,18 @@ static ssize_t signalfd_file_read(FAR struct file *filep,
ssize_t ret;
int count;
- count = len / sizeof(struct signalfd_siginfo);
- if (buffer == NULL || count == 0)
+ if (buffer == NULL)
+ {
+ return -EFAULT;
+ }
+
+ if (len < sizeof(struct signalfd_siginfo))
{
return -EINVAL;
}
+ count = len / sizeof(struct signalfd_siginfo);
+
pendmask = nxsig_pendingset(NULL);
sigandset(&pendmask, &pendmask, &dev->sigmask);
if (sigisemptyset(&pendmask))
@@ -345,7 +352,7 @@ void signalfd_notify(FAR struct task_group_s *group, int
signo)
/* A group that never set up a signalfd poll has no waiter array. */
- if (group->tg_sigfds == NULL)
+ if (group == NULL || group->tg_sigfds == NULL)
{
return;
}
@@ -421,6 +428,12 @@ int signalfd(int fd, FAR const sigset_t *mask, int flags)
FAR struct file *filep = NULL;
int ret = EINVAL;
+ if (mask == NULL)
+ {
+ ret = EFAULT;
+ goto errout;
+ }
+
if (flags & ~(SFD_CLOEXEC | SFD_NONBLOCK))
{
goto errout;
@@ -455,7 +468,8 @@ int signalfd(int fd, FAR const sigset_t *mask, int flags)
goto errout;
}
- if (filep->f_inode->u.i_ops != &g_signalfd_fileops)
+ if (filep->f_inode == NULL ||
+ filep->f_inode->u.i_ops != &g_signalfd_fileops)
{
file_put(filep);
goto errout;