Patch "fs: fix fd table size alignment properly" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    fs: fix fd table size alignment properly

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     fs-fix-fd-table-size-alignment-properly.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6b92732dc9151c1eb5c29e6ffe6f68d396657864
Author: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Date:   Tue Mar 29 23:29:18 2022 -0700

    fs: fix fd table size alignment properly
    
    [ Upstream commit d888c83fcec75194a8a48ccd283953bdba7b2550 ]
    
    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 <Jason@xxxxxxxxx>
    Cc: Fedor Pchelkin <aissur0002@xxxxxxxxx>
    Cc: Alexey Khoroshilov <khoroshilov@xxxxxxxxx>
    Cc: Christian Brauner <brauner@xxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/file.c b/fs/file.c
index c01c29417ae6..ee9317346702 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -303,10 +303,9 @@ static unsigned int sane_fdtable_size(struct fdtable *fdt, unsigned int max_fds)
 	unsigned int count;
 
 	count = count_open_files(fdt);
-	max_fds = ALIGN(max_fds, BITS_PER_LONG);
 	if (max_fds < NR_OPEN_DEFAULT)
 		max_fds = NR_OPEN_DEFAULT;
-	return min(count, max_fds);
+	return ALIGN(min(count, max_fds), BITS_PER_LONG);
 }
 
 /*



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux