]> Git Repo - linux.git/commit - fs/file.c
fs: fix fd table size alignment properly
authorLinus Torvalds <[email protected]>
Wed, 30 Mar 2022 06:29:18 +0000 (23:29 -0700)
committerLinus Torvalds <[email protected]>
Wed, 30 Mar 2022 06:29:18 +0000 (23:29 -0700)
commitd888c83fcec75194a8a48ccd283953bdba7b2550
tree66c5fd5d83bb02fcfbb678191ae34edbe0c4904d
parent965181d7ef7e1a863477536dc328c23a7ebc8a1d
fs: fix fd table size alignment properly

Jason Donenfeld reports that my commit 1c24a186398f ("fs: fd tables have
to be multiples of BITS_PER_LONG") doesn't work, and the reason is an
embarrassing brown-paper-bag bug.

Yes, we want to align the number of fds to BITS_PER_LONG, and yes, the
reason they might not be aligned is because the incoming 'max_fd'
argument might not be aligned.

But aligining the argument - while simple - will cause a "infinitely
big" maxfd (eg NR_OPEN_MAX) to just overflow to zero.  Which most
definitely isn't what we want either.

The obvious fix was always just to do the alignment last, but I had
moved it earlier just to make the patch smaller and the code look
simpler.  Duh.  It certainly made _me_ look simple.

Fixes: 1c24a186398f ("fs: fd tables have to be multiples of BITS_PER_LONG")
Reported-and-tested-by: Jason A. Donenfeld <[email protected]>
Cc: Fedor Pchelkin <[email protected]>
Cc: Alexey Khoroshilov <[email protected]>
Cc: Christian Brauner <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/file.c
This page took 0.055024 seconds and 4 git commands to generate.