All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@zeniv.linux.org.uk>
To: Yuntao Wang <yuntao.wang@linux.dev>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Subject: Re: [PATCH] fs/file: fix the check in find_next_fd()
Date: Wed, 29 May 2024 20:03:28 +0100	[thread overview]
Message-ID: <20240529190328.GP2118490@ZenIV> (raw)
In-Reply-To: <20240529160656.209352-1-yuntao.wang@linux.dev>

On Thu, May 30, 2024 at 12:06:56AM +0800, Yuntao Wang wrote:
> The maximum possible return value of find_next_zero_bit(fdt->full_fds_bits,
> maxbit, bitbit) is maxbit. This return value, multiplied by BITS_PER_LONG,
> gives the value of bitbit, which can never be greater than maxfd, it can
> only be equal to maxfd at most, so the following check 'if (bitbit > maxfd)'
> will never be true.
> 
> Moreover, when bitbit equals maxfd, it indicates that there are no unused
> fds, and the function can directly return.
> 
> Fix this check.

Hmm...  The patch is correct, AFAICS.  I _think_ what happened is that
Linus decided to play it safe around the last word.  In the reality
->max_fds is always a multiple of BITS_PER_LONG, so there's no boundary
effects - a word can not cross the ->max_fds boundary, so "no zero
bits in full_fds_bits under max_fds/BITS_PER_LONG" does mean there's
no point checking in range starting at round_down(max_fds, BITS_PER_LONG).

Perhaps a comment along the lines of

        unsigned int maxfd = fdt->max_fds; // always a multiple of BITS_PER_LONG

would be useful in there...

  parent reply	other threads:[~2024-05-29 19:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-29 16:06 [PATCH] fs/file: fix the check in find_next_fd() Yuntao Wang
2024-05-29 16:22 ` Jan Kara
2024-05-29 19:03 ` Al Viro [this message]
2024-05-30  1:50   ` Yuntao Wang
2024-05-30  7:12 ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240529190328.GP2118490@ZenIV \
    --to=viro@zeniv.linux.org.uk \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yuntao.wang@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.