]> git.baikalelectronics.ru Git - kernel.git/commit
fs: fix fd table size alignment properly
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 30 Mar 2022 06:29:18 +0000 (23:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 30 Mar 2022 06:29:18 +0000 (23:29 -0700)
commitba89561834263c824fb537a6bf9fdaaa2a2cc60f
tree66c5fd5d83bb02fcfbb678191ae34edbe0c4904d
parentc94dbf9daef5675b9c5c2c0c16eb5d1fc64b7a90
fs: fix fd table size alignment properly

Jason Donenfeld reports that my commit dce3bbef012e ("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: dce3bbef012e ("fs: fd tables have to be multiples of BITS_PER_LONG")
Reported-and-tested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Cc: Fedor Pchelkin <aissur0002@gmail.com>
Cc: Alexey Khoroshilov <khoroshilov@ispras.ru>
Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/file.c