Re: [PATCH 4/4] file: Fix file descriptor leak in copy_fd_bitmaps()

From: Christian Brauner
Date: Wed Mar 30 2022 - 03:47:25 EST


On Tue, Mar 29, 2022 at 03:23:10PM -0700, Linus Torvalds wrote:
> On Tue, Mar 29, 2022 at 3:18 PM Linus Torvalds
> <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > Ok, applied as commit 1c24a186398f ("fs: fd tables have to be
> > multiples of BITS_PER_LONG").
>
> Oh, forgot to mention...
>
> Christian - it strikes me that the whole "min(count, max_fds)" in
> sane_fdtable_size() is a bit stupid.
>
> A _smarter_ approach might be to pass in 'max_fds' to
> count_open_files(), and simply not count past that value.
>
> I didn't do that, because I wanted to keep the patch obvious. And it
> probably doesn't matter, but it's kind of silly to possibly count a
> lot of open files that we want to close anyway, when we already know
> the place we should stop counting.
>
> Whatever. I just wanted to mention it in case you decide you want to
> clean that part up. This is mostly your code anyway.

I put it on my TODO and will look at this soon!

Thank you!
Christian