Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp739272lqb; Wed, 29 May 2024 09:08:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVI/YyUAXqrGY7fcJxqjvzjYKqgkdhdlFKpvFamM5G+tYuOV5jv03z4JSeTZ3TfCMmOg+149Woc0BNS5CGzil+cGfbS+D2uJ74jogcrQQ== X-Google-Smtp-Source: AGHT+IEti3vPQyfLZvOO+ZAT2UpS+O2gNnPRuR4JTIfb1dJSH6eAfonecpYk3qVoXANkGPMBICXN X-Received: by 2002:a05:6871:14b:b0:24c:a3f4:b45d with SMTP id 586e51a60fabf-24ca3f4b4e2mr21131626fac.38.1716998913332; Wed, 29 May 2024 09:08:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716998913; cv=pass; d=google.com; s=arc-20160816; b=qIKrJNeE5LmNx4eeGW4qBGMHy205IYMr9ueb2fIAh9SCcBuN8suFLj95CW1cWAvcCy 7anruXIdD3kCb8B0stq93VSkmV22X0AG1pKOiM3Jz063yDGf95E0Tx8mN6CWz6CHE8Ev A3WR4izozUBS3xpa7CGDaMwC+jwaGbk3Yqj2vXVY6+EnkVPbE7bKUAN1rQJJC8khCM1R 5yR3LRosaCBeb8J/dSdEpEoGyTO15WiYrSbwO+wukaXIwoqpYESCwCC2HXoi9yQ1FJZx ssFBj4KEw5ZGmXPQmnGyRkH5fsQyar8uI4oEEHToMF6TbJ0rwzBXmjvJxER+VosjSpp2 3N9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=KIXA4id9G2CaRpAXjkEzIwnBt0h+Tpbe5UdX8oSDWlk=; fh=pzkabqw/kvF7xGqr24IkRRCE8JUGU1H5M+z4M5adcRc=; b=NVlx8GU7RqyvhBN/jxitk8vOUfUMH6OyjGKRXpiFlcwGbl7c8QxmRbSuahlHcBfbCo pJkAAg3mQihauZQYyAYYmC8bR+zVI7AX2fo99NFxbA5gz/xDavM+KcpwAmrFMWSU+pE4 G8Kl7Rv7DyEjfm9AcNolkWJJshyiU3ZeJD4p406YiXyZEUJakAKm8cGjRXkv8qB70pJ4 LuOptyToEGaVK/Nv8eV7XBzi+YlEJZwCQdn5/aSrxR8NBm/FT4mGdAd+/sKMSbNt5+YJ 0DJq53+u3U+V6iO90IGo5yxBb8NAxbrehPOkWZkImer3nrV/GxcyOu7Q6X/V7ZLkdC1N qwHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xcMnwLhA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-194419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a1e0cc1a2514c-804cc08f699si2311609241.229.2024.05.29.09.08.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:08:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=xcMnwLhA; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-194419-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194419-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD6B81C24146 for ; Wed, 29 May 2024 16:08:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A77A184110; Wed, 29 May 2024 16:07:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xcMnwLhA" Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (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 BDA77181CF8 for ; Wed, 29 May 2024 16:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998872; cv=none; b=NZuxwWgFlP1GyAyhy9RwrsznYnmziCAkvp0KILzmBPXsKDgPcrXHnxk5ZqjyTEb6MrVm0aJJ120b4vn0NlLGfeKcoimYATTQjOSkhOHGcPfMN1mZ0Kk4Shc7+WksM+H43P+cIThX4EQgAUKMs6AnDRT1FuFTIyM2AzzntQRbTqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716998872; c=relaxed/simple; bh=E9DNaoOmfthVbSQNM5zSx1ewbDVsnzuDLD8hcnb2gp0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=nbhSrlEjKg+V4HN7eN5fMGscim0ujPiCBpjbSHGd8/G0zFzg31PEEb0mjZU19HOCR8ZmJFaBb4H96rSIO4N/sPepLwnBDj3+eU6GDVeEMcOx66UoJJm4Rvt8QwvB2KJdJZQNmWnZQ1Y/3DabY2jdJ7f2PtOqAjrXr3laUNHSAIM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xcMnwLhA; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1716998869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=KIXA4id9G2CaRpAXjkEzIwnBt0h+Tpbe5UdX8oSDWlk=; b=xcMnwLhAI1ZaHjJfQJolPSG3SR6XQd5C+R63Vp+xElxibh3Jp5gUTavEAijzqbJawBAxWZ ifKwmchh4xU5kIzkREMVlLbqTMhkifQjsjDRDBX88ANAGAU6hu7FXId4j+OW7tzq24zA6S R/SljvB3b5svAHQf2QSid15P3EHsTeo= X-Envelope-To: linux-fsdevel@vger.kernel.org X-Envelope-To: viro@zeniv.linux.org.uk X-Envelope-To: brauner@kernel.org X-Envelope-To: jack@suse.cz X-Envelope-To: yuntao.wang@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Yuntao Wang To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Alexander Viro , Christian Brauner , Jan Kara , Yuntao Wang Subject: [PATCH] fs/file: fix the check in find_next_fd() Date: Thu, 30 May 2024 00:06:56 +0800 Message-ID: <20240529160656.209352-1-yuntao.wang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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 --- fs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/file.c b/fs/file.c index 8076aef9c210..7058901a2154 100644 --- a/fs/file.c +++ b/fs/file.c @@ -491,7 +491,7 @@ static unsigned int find_next_fd(struct fdtable *fdt, unsigned int start) 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.45.1