Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp877768lqb; Wed, 29 May 2024 13:20:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWV3gt0f+mTixBQDu5TquXgs+7oMRDUwV3/Q4Zv5e6PAz2EuPXbAFyJAOg4KXJ2ESxEyhhC1R59V2pW/CT0jaxZ7ii1hTRUzIDTHGxxQQ== X-Google-Smtp-Source: AGHT+IEVq9r0Qk86PPCmDEUrYUJTQtLunlGn8SnzngHYOjwFh69r39ZR+DiuDdUlrBSfeOjwXflr X-Received: by 2002:a17:90b:1246:b0:2c1:a5d7:b15f with SMTP id 98e67ed59e1d1-2c1ab9f499bmr220542a91.18.1717014059265; Wed, 29 May 2024 13:20:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717014059; cv=pass; d=google.com; s=arc-20160816; b=bAVHstfPxVgZwwOkH9YVvj66izj+rodpXZFvofFHn1GJS3jyq07nMId7quIB1IRyZp Qqz56hZ0dTVqOBGMml7p1K469hDAqSe3CuS/6/W5nEPkHsKxy3irk0UhWCcsOnQTWWd/ OIJNNwffw09h10zWfTJ0N4bHomYRXibLb2n58NXQ2ukaL6ma1MEDC541sOi9FIMgSnqR xDAGGJyfC42wxR6h+65A1AJU5SrUp7Z96yEm18mATa9CxfYDFdfz+XCEb8W9kgzjbaSd ojfsOZ3UPPWd/fkGmk2cemz7XPE/AQo/A9k2kS92T9f8w7RtvPXwk6UyKjtp3nu+/vZL 9R+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:in-reply-to:content-disposition:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :message-id:subject:cc:to:from:date:dkim-signature; bh=cBJ2yfNPFC6AgKPZbvS91mCh/8Bwho3Soao0QI/qyeM=; fh=gX8P1uncQKNfeGslx4EIPVdAeDNDHR7OurMdoNGvKjw=; b=KhNxnM7QihyiPsLmyvt2iKepqNZLkCk3ak0HuhiPEYprY4VFej/LJNnUf5mnvGqOJL avq4Iuy45pknabX1CRosaDu/rd0bWTGp/Xpi/L4m22qUC0XMyQLuTaRuSaNgdZ2Wj6rc 7XqWeM/nFHcwxeSV4/QLmoMErZDddGEfKWftPfVq97Li0Db6XCckTTPXYV2evQ+lhmWb 5UKMaH2eI+kvzfKkOl9012RTn8AZC8N5oJ+HwHoIgY8GV6JmVLBo7jPW+6naVgyZmIaR wg23/AW4dgW9QBIXi3FRWo+37o5i8mPqD4Cvn84i0ossuf/xAWaVbPXo+GMkwrvVYtQG l2xw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=io8Jw4Ny; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-194601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2c1a7764abcsi256606a91.9.2024.05.29.13.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 13:20:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b=io8Jw4Ny; arc=pass (i=1 dkim=pass dkdomain=linux.org.uk dmarc=pass fromdomain=zeniv.linux.org.uk); spf=pass (google.com: domain of linux-kernel+bounces-194601-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194601-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D17E0287521 for ; Wed, 29 May 2024 19:03:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D95B1C0DEE; Wed, 29 May 2024 19:03:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b="io8Jw4Ny" Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [62.89.141.173]) (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 8F384335C7; Wed, 29 May 2024 19:03:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.89.141.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717009413; cv=none; b=gIoni7sKnOeJNxGTkwxC8EZtzGSjL0pn8x+CpQQXGF0xRj2FYw5IRIgN2QHe1i8V+4Z8AQhNRpZoG7A20N2+j5uOpb+KL+HhaYMxl/zpWufT8x777WzmEipu4gpj4OG9LkS+80D3zSiMpoSRTOdbgVkX0KZO2/b5iFYxZ4KU7wA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717009413; c=relaxed/simple; bh=Otfy8rES7rvdq+wnb3Wa8AaNEaYXerb7/pwMg3id6Gw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=d44xLp0sJMKYwHiSbjLPwIvn8Ze1O/eCe71r56bJDouelTPVnegYBNWa0hgPSqO/+TXQVahHYQV3+7SBxHrwaylizV++VK+c9h/JX1h5GGJ08RZOK5WeF61QJ2QSznxxZQYFBDiHPZN+Ok1oxlsS2t3LpGL3tqJNFQf5iFiyuaA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk; spf=none smtp.mailfrom=ftp.linux.org.uk; dkim=pass (2048-bit key) header.d=linux.org.uk header.i=@linux.org.uk header.b=io8Jw4Ny; arc=none smtp.client-ip=62.89.141.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zeniv.linux.org.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ftp.linux.org.uk DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=cBJ2yfNPFC6AgKPZbvS91mCh/8Bwho3Soao0QI/qyeM=; b=io8Jw4NyaEFkMQ4OAOUWJg0ZyE owa5pwXGFBnAdpTvTFEDDAab75ZSYKih19BbfS7OLZmvJKG8BYb32nBZnWCuPddTKEeE5OVZp1Yc3 Acai6StyYj0VIsd/fU6hTwKaC2SfoWV0tWLe5g3HZ1Y4ORQCRIoxMAd+0FBRrTp5cDWSoVbUMGMI9 N7UmU8ZZ6i7c75pt8A3TXmfBwDe2d4NkelwNsktROTgthw/LFu8ZssMSjsEDMsjsZAIAGux6tyLBp TnupI9bMmaPf9Zcnu1its8cxpmlNWA2jr/Wf6hoL76XnRQKYUgtco5bF8FPEPoFdJWvdImSIhFdnb T4I87nsg==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.96 #2 (Red Hat Linux)) id 1sCOa8-003Yze-0S; Wed, 29 May 2024 19:03:28 +0000 Date: Wed, 29 May 2024 20:03:28 +0100 From: Al Viro To: Yuntao Wang Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Christian Brauner , Jan Kara Subject: Re: [PATCH] fs/file: fix the check in find_next_fd() Message-ID: <20240529190328.GP2118490@ZenIV> References: <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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240529160656.209352-1-yuntao.wang@linux.dev> Sender: Al Viro 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...