Repository navigation
fs/vfs: validate parameters in epoll_create, epoll_ctl, and epoll_wait - #21815
Merged
xiaoxiang781216 merged 1 commit intoNov 13, 2026
Merged
Conversation
POSIX and Linux man-pages explicitly specify parameter validation for the epoll family of system calls: For epoll_wait() and epoll_pwait(): - [EINVAL] maxevents is less than or equal to zero. - [EFAULT] The memory area pointed to by events is not accessible. Previously, if maxevents <= 0, epoll_teardown() returned 0, which caused epoll_wait() / epoll_pwait() to loop indefinitely on 'goto retry;', pegging the CPU at 100% and starving other tasks. Furthermore, if evs == NULL, epoll_teardown() dereferenced NULL (CWE-476). This change validates maxevents > 0 and evs != NULL upfront. For epoll_ctl(): - [EINVAL] epfd is the same as fd (circular dependency). - [EFAULT] The memory area pointed to by event is not accessible. Previously, epoll_ctl() did not reject epfd == fd and dereferenced ev->events without checking ev != NULL for EPOLL_CTL_ADD and EPOLL_CTL_MOD (CWE-476). This change enforces epfd != fd and validates ev != NULL for ADD/MOD operations. For epoll_create() and epoll_create1(): - [EINVAL] size is not positive. - [EINVAL] Invalid value specified in flags. Previously, epoll_create() silently accepted non-positive sizes, and large sizes could cause integer multiplication wraparound in sizeof(epoll_head_t) + sizeof(epoll_node_t) * size, resulting in a heap buffer overflow (CWE-190/CWE-122). epoll_create1() also accepted arbitrary invalid flags. This change validates size bounds and flags, while preserving normalization in epoll_do_create() for configurations where CONFIG_FS_NEPOLL_DESCRIPTORS is zero. Assisted-by: gemini-3.8-flash Signed-off-by: Swatantra Yadav <[email protected]>
acassis
approved these changes
Nov 12, 2026
|
xiaoxiang781216
approved these changes
Nov 13, 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 and Linux specifications (
epoll(7)) explicitly define parameter validation for theepollfamily of system calls:1.
epoll_wait()andepoll_pwait()[EINVAL]maxeventsis less than or equal to zero.[EFAULT]The memory area pointed to byeventsis not accessible.Previously:
maxevents <= 0,epoll_teardown()returned 0, causingepoll_wait()andepoll_pwait()to enter an infinite busy-wait loop (goto retry;), pegging the CPU at 100% and starving other tasks.maxevents > 0butevs == NULL,epoll_teardown()dereferenced NULL when storing results (CWE-476).Fix:
maxevents > 0upfront returningERRORwitherrno = EINVAL.evs != NULLupfront returningERRORwitherrno = EFAULT.2.
epoll_ctl()[EINVAL]fdis the same asepfd.[EFAULT]The memory area pointed to byeventis not accessible.Previously:
epoll_ctl()did not check forepfd == fd, allowing circular epoll self-monitoring dependencies.EPOLL_CTL_ADDandEPOLL_CTL_MOD,ev->eventsandev->datawere dereferenced without checkingev != NULL, causing kernel panics on NULL pointer dereference (CWE-476).Fix:
epfd == fdwithEINVAL.ev != NULLforEPOLL_CTL_ADDandEPOLL_CTL_MODreturningEFAULT.3.
epoll_create()andepoll_create1()[EINVAL]sizeis not positive.[EINVAL]Invalid value specified inflags.Previously:
epoll_create()silently accepted non-positive sizes (size <= 0 ? 1 : size).sizecould overflow 32-bit integer multiplication insizeof(epoll_head_t) + sizeof(epoll_node_t) * size, causing a small heap allocation followed by an out-of-bounds heap initialization loop (CWE-190/CWE-122).epoll_create1()accepted arbitrary invalid flags without checking againstEPOLL_CLOEXEC.Fix:
epoll_create(), rejectssize <= 0or oversized values exceeding(SIZE_MAX - sizeof(epoll_head_t)) / sizeof(epoll_node_t)withEINVAL.epoll_do_create(), preserves normalization for configurations whereCONFIG_FS_NEPOLL_DESCRIPTORS=0is used byepoll_create1().epoll_create1(), validates(flags & ~EPOLL_CLOEXEC) == 0.epoll_head_from_fd(), defensively guards against(*filep)->f_inode == NULL.Impact
epollsystem calls now validate parameter bounds per POSIX/Linux.EINVALorEFAULT) instead of hanging or crashing.Testing
Before vs After
epoll_wait(epfd, evs, 0, 100)goto retry;), 100% CPU hangERROR,errno = EINVALepoll_wait(epfd, NULL, 5, 0)ERROR,errno = EFAULTepoll_ctl(epfd, EPOLL_CTL_ADD, epfd, &ev)ERROR,errno = EINVALepoll_ctl(epfd, EPOLL_CTL_ADD, fd, NULL)ERROR,errno = EFAULTepoll_create(0)/epoll_create(-1)ERROR,errno = EINVALepoll_create(SIZE_MAX / 2)ERROR,errno = EINVALepoll_create1(0xdeadbeef)ERROR,errno = EINVALepoll_create1(0)withCONFIG_FS_NEPOLL_DESCRIPTORS=0Build & Verification Log
nuttx-builder)sim:nsh(x86_64)Tested:
sim:nsh(flat build, x86_64).Untested: kernel and protected builds, real hardware target boards.