Repository navigation
fs/poll: Tear down a poll through the file of its setup. - #21490
Merged
Merged
Conversation
poll_teardown() looked up the file again by its descriptor. If another thread closed the descriptor during the poll, the lookup failed, so the driver was not told and the reference of the setup was not dropped. The file stayed open, and the driver kept a pointer to the struct pollfd_s, which is gone when poll() returns. The next event of that driver used this pointer. Keep the file of the setup in struct pollfd_s and use it in poll_teardown(). The file stays open until poll() ends, and then it closes. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
|
michallenc
approved these changes
Nov 5, 2026
xiaoxiang781216
approved these changes
Nov 5, 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
poll_teardown()looked up the file again by its descriptor. If another thread closes the descriptor duringpoll(), the lookup fails, so the driver is not told that the poll ended and the reference of the setup is not dropped. The file stays open, and the driver keeps a pointer to thestruct pollfd_s, which is gone whenpoll()returns. The next event of that driver uses this pointer.In a kernel build this panics the kernel from an ordinary program: a pipe, one thread in
poll()on the read end, and another thread that callsclose()on it. Then the close of the write end posts an event through the old pointer:This PR keeps the file of the setup in
struct pollfd_sand uses it inpoll_teardown(). The file stays open untilpoll()ends, and then it closes.epollalready keeps the file this way.Impact
All drivers and all build modes:
poll()andselect(). The poll method of a driver does not change.struct pollfd_sis kernel only; the userstruct pollfddoes not change. No ABI change. Not a breaking change.A descriptor that another thread closes during
poll()now closes whenpoll()ends. Before, it never closed.Size, image text from master 6e1126a, float and numbered arguments off: Cortex-M0
nucleo-f072rb:nsh0, Cortex-M3nucleo-f103rb:nsh0,rv-virt:nsh-10,qemu-armv8a:nsh-8. Data and bss do not change.RAM:
struct pollfd_sgrows by one pointer.poll()keeps 4 entries on its stack (+16 bytes on a 32-bit CPU, +32 on a 64-bit CPU), a Unix domain socket has 4 entries, and anepollentry has one. This comes from the types and was not measured.Documentation:
Documentation/os/filesystem/index.rstnames the new field, in this commit.Testing
Test:
poll_close_testin ostest, apache/nuttx-apps#3980, a draft that depends on this PR. Another thread closes the read end of a pipe duringpoll(). Whenpoll()ends, the write end must reportPOLLERR, because no reader is left.qemu-armv8a:knsh(kernel)POLLERR, then kernel panicqemu-armv8a:nsh(flat)POLLERR, ostest status 256rv-virt:knsh64(kernel)mps2-an500:knsh(protected)The tests ran before the rebase on bf029a2; the new commits touch no file of this PR. The commit is the same, apart from one line in the documentation.
tools/checkpatch.sh -c -u -m -gpasses.