On Tue, May 19, 2020 at 10:45:20PM +0100, Al Viro wrote: > The obvious fix would be to turn cpy and set into size_t - as in > ed fs/file.c <<'EOF' > /copy_fdtable/+2s/unsigned int/size_t/ > w > q > EOF > > On size_t overflow you would've failed allocation before getting to that > point - see sysctl_nr_open_max initializer. Overflow in alloc_fdtable() > (nr is unsigned int there) also can't happen, AFAICS - the worst you > can get is 1U<<31, which will fail sysctl_nr_open comparison. > > I really wonder about the missing couple of syscalls in your strace, though; > could you verify that they _are_ missing and see what the fix above does to > your testcase? Anyway, whether it's all there is to your reproducers or not, the bug is obvious; I've pushed the following into #fixes. commit 784233a6d4a56f1d0e6e4490fbf38d3cce5742ec Author: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Date: Tue May 19 17:48:52 2020 -0400 fix multiplication overflow in copy_fdtable() cpy and set really should be size_t; we won't get an overflow on that, since sysctl_nr_open can't be set above ~(size_t)0 / sizeof(void *), so nr that would've managed to overflow size_t on that multiplication won't get anywhere near copy_fdtable() - we'll fail with EMFILE before that. Cc: stable@xxxxxxxxxx # v2.6.25+ Fixes: 9cfe015aa424 (get rid of NR_OPEN and introduce a sysctl_nr_open) Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx> diff --git a/fs/file.c b/fs/file.c index c8a4e4c86e55..abb8b7081d7a 100644 --- a/fs/file.c +++ b/fs/file.c @@ -70,7 +70,7 @@ static void copy_fd_bitmaps(struct fdtable *nfdt, struct fdtable *ofdt, */ static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt) { - unsigned int cpy, set; + size_t cpy, set; BUG_ON(nfdt->max_fds < ofdt->max_fds);