From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0A6015821E; Tue, 23 Jul 2024 18:39:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721759947; cv=none; b=OOsMaKsuRg33k1VMaq+MNk8fosPsFu0xit8eiTL50xwitH21FU4BS12/m/Ax54uvK2D+7JdYKDThtz/HtxBG20QpvFDjBgvFSsU0z0+R3Z/JI99HPrd2GeFdmKncaC/i977a/++6Jl12ZUCSOMBurWUEmGi1+OOxtP7qfTnbOI8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721759947; c=relaxed/simple; bh=IpyWVZWUBT0nAce6zc9I1Xm9NA9eFqdP7xJeMbNRCWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e5VKwBArZuA3xvNBOBXGr3eSLQ3XiNRNIbJKTgRWXsUs5K7tXTL6nxgtc3wrfGBRYSjVNhfQ+puug/4fA7QXb8asN4QL67APTxvLi1Trz+xmqK38Y3v4opnmlLqv7fb5o7VfIV+EVk8qx4HCjywevHfJUl4/xHoKtQEsoEolBt0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=j7mF4XeY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="j7mF4XeY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CF5EC4AF09; Tue, 23 Jul 2024 18:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721759946; bh=IpyWVZWUBT0nAce6zc9I1Xm9NA9eFqdP7xJeMbNRCWU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j7mF4XeYpsZDSd8YPFw1Yz+3VSz68A6yhAqdv+1PbBpmJ2YR9Bp3Vo/P2m5Ai6ukJ RqmsvdUDr3jz6xvFocMYBaOBDoe3fhv8/qIxpt8/8joOxFgDqo9Kk9B5jZWUPowAGj I/9AaScdRFcagt2xWzAb5mOmqMuDk/iPkIt6+oaA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuntao Wang , Jan Kara , Christian Brauner , Sasha Levin Subject: [PATCH 6.9 052/163] fs/file: fix the check in find_next_fd() Date: Tue, 23 Jul 2024 20:23:01 +0200 Message-ID: <20240723180145.486096711@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240723180143.461739294@linuxfoundation.org> References: <20240723180143.461739294@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuntao Wang [ Upstream commit ed8c7fbdfe117abbef81f65428ba263118ef298a ] 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. Signed-off-by: Yuntao Wang Link: https://lore.kernel.org/r/20240529160656.209352-1-yuntao.wang@linux.dev Reviewed-by: Jan Kara Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/file.c b/fs/file.c index 3b683b9101d84..005841dd35977 100644 --- a/fs/file.c +++ b/fs/file.c @@ -481,12 +481,12 @@ struct files_struct init_files = { static unsigned int find_next_fd(struct fdtable *fdt, unsigned int start) { - unsigned int maxfd = fdt->max_fds; + unsigned int maxfd = fdt->max_fds; /* always multiple of BITS_PER_LONG */ unsigned int maxbit = maxfd / BITS_PER_LONG; unsigned int bitbit = start / BITS_PER_LONG; bitbit = find_next_zero_bit(fdt->full_fds_bits, maxbit, bitbit) * BITS_PER_LONG; - if (bitbit > maxfd) + if (bitbit >= maxfd) return maxfd; if (bitbit > start) start = bitbit; -- 2.43.0