fs/inode: bound fdlist_extend() against the requested row - #20000
Open
AlmAck wants to merge 1 commit into
Open
Conversation
fdlist_extend() grows a task group's descriptor table to 'row' rows of CONFIG_NFILE_DESCRIPTORS_PER_BLOCK entries each, and guards the growth against OPEN_MAX: if (CONFIG_NFILE_DESCRIPTORS_PER_BLOCK * (orig_rows + 1) > OPEN_MAX) The check sizes the table at orig_rows + 1, which assumes the caller only ever grows by a single block. The function then allocates 'row' rows, so the two agree only for growth by one. Callers do skip ahead. fdlist_dup3() asks for fd2 / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + 1, fdlist_dupfile() for the row holding minfd, and fdlist_copy() for the row holding a parent descriptor it is duplicating. Any of those can request a row well past orig_rows + 1. Such a request passes the check and the function then allocates and installs a table with more than OPEN_MAX descriptors. With the defaults (8 per block, OPEN_MAX 256) a process holding one row that calls dup2(fd, 400) ends up with 51 rows, or 408 descriptor slots, against a 256 limit. Check the row actually being requested. For single-block growth row == orig_rows + 1 and the comparison is unchanged. Signed-off-by: AlmAck <gluca86@gmail.com>
AlmAck
requested review from
Donny9,
pussuw and
xiaoxiang781216
as code owners
August 29, 2026 17:38
xiaoxiang781216
approved these changes
Aug 29, 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
fdlist_extend()grows a task group's descriptor table torowrows ofCONFIG_NFILE_DESCRIPTORS_PER_BLOCKentries each, and guards the growthagainst
OPEN_MAX:The check sizes the table at
orig_rows + 1, which assumes the calleronly ever grows by a single block. The function then allocates
rowrows, so the two agree only for growth by one.
Callers do skip ahead:
fdlist_dup3()asks forfd2 / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + 1fdlist_dupfile()asks for the row holdingminfdfdlist_copy()asks for the row holding a parent descriptor it isduplicating
Any of those can request a row well past
orig_rows + 1. Such a requestpasses the check, and the function then allocates and installs a table
with more than
OPEN_MAXdescriptors.Check the row actually being requested instead. For single-block growth
row == orig_rows + 1and the comparison is unchanged.Impact
Affects the paths that grow the descriptor table by more than one block:
dup2()/dup3()with a large target descriptor,fcntl(F_DUPFD)with alarge
minfd, andposix_spawn-style descriptor copying from a parentholding a high descriptor.
With the defaults (8 per block,
OPEN_MAX256) a process holding one rowthat calls
dup2(fd, 400)ends up with 51 rows — 408 descriptor slotsagainst a 256 limit — instead of receiving
-EMFILE.This is a limit-enforcement bug rather than memory corruption: the table
stays internally consistent, it is simply larger than the process is
entitled to, along with the memory for those rows.