Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp749279lqb; Wed, 29 May 2024 09:23:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/bvY8zR+D2waXkunBDPfzCQuMp8jek+MfSXC9mHD2UTmxJUTRmfd4hhcjcWPMFoV+lyO2WOXRoH30fjB9K5nfiwmCWKzuufcNJvgeuw== X-Google-Smtp-Source: AGHT+IFqAkaGPVHZ3XVznt0OvgopXr6nmcbtoKF44TiCNHvNJDnIS6O78vZa6GQQKnAAuh/BD0/B X-Received: by 2002:a17:906:d9c3:b0:a59:a83b:d437 with SMTP id a640c23a62f3a-a62642dce6bmr988134966b.32.1716999786523; Wed, 29 May 2024 09:23:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716999786; cv=pass; d=google.com; s=arc-20160816; b=s3Vj/8qfAWwYhc6oCu90Tp/yFrSF3cnDnIPocUX98cQuknHBl1tIgNH7YIRwr++EzM j2FuuGytM0d+qi/6N2xOLTfG541Q43CYvsmubkjhmRxEaGTe1rnvc3yzSHCWM3USBD7J v6Y+vwE0IgRGW2lkvAZGXjEC1XMRf53HaPzsRFPI0yNeyopynAlub0i9yUW7XpFHzPc2 9q4w0UsRILT4LbcipfT4Aitv1lj/v5ol8U1aPBGlrBvrp/ydHHzI1YgQ0SM0Oba6A2ks JbdRiRXBizJQyqRqtvVNT9186+R0l7AaKFC9RkBT43B7uScG39Qcktx+XWqm4c0B6BUA jU/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=aCZu6jdsDJqbFUOxgklErOVfk3nUsdlFfJQML2sSSgA=; fh=joZaMfgVHhslLWtJdtvbCRkkl10kg4T5ReVWVvgLLks=; b=AqcD7Ojqzryq5k0c9DUrUQ/Q+5Oc/Tj9vBO7WgO+oCr45pnFFwjRU2qTj2D0BpbOfe Ma5rE97eeenlE8dXE8paA/sDFZu7zkv3D6KZvuLsFc3r9eoBxtqxuyLJsQgA1zC2+8j/ W6rpHq8oVXWixj+GCkRUabkDPHwcycorR2ej5BpKMBraqwSNpoQwWetA/Jy5cxNvdXaF MFnyDJQlIeT9xw/lg4U64Ol/Uh9f6gOOyRJNCU7M5j0WOg/UCegKCQgjcPgdbEgyjBPw zoNDJKRFum8M/7FJRYtngtKcMLbtk/IwmthMbpIoltv9oyQxB2HUqAu6wlSxqJe1nFaj 8PtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="C+jo/LF8"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="C+jo/LF8"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-194432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194432-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a628b05961fsi579332266b.1053.2024.05.29.09.23.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 09:23:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="C+jo/LF8"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b="C+jo/LF8"; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-194432-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194432-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id A33431F25A9F for ; Wed, 29 May 2024 16:22:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A46AD1836FB; Wed, 29 May 2024 16:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="C+jo/LF8"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="fxPU1Bmg"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="C+jo/LF8"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="fxPU1Bmg" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33DAA1836E0; Wed, 29 May 2024 16:22:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716999760; cv=none; b=EA3ixII6998BKZwem/TUTGtNZ+CAol77Ww8LYD+C7DJgFIzlzd7uSaBsVJronYkBQwXHlcrI/Cx/Y6Hu+mjT/H1E3stdd8un5nvw/iKQoJMyBk4Bu4vKxYoO0rY2X5rq12hvKTJC4umFHgS/owERZydOnV8paAg7+drPpJ+pHLE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716999760; c=relaxed/simple; bh=0N8WwniUWLzXIUhUFVHN1Xwhqc4YYBcv14U5W5AqVOs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WKDuvtARsIUx0OyCF79kHgwSYF47xnUWBlA/lQyPLuzszjtsnuM0QTSCTj3M/OfYLgpzPG5oe+ENrNZoLeN2dkomLMLnNotVSb/zyc+ORdIiaPzZcdWTzeRXkzkDy5Cve9xg2Y8DBlV+QFJVTMzUYbM0YA6JG0pZJ10F0I0R1VQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=C+jo/LF8; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=fxPU1Bmg; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=C+jo/LF8; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=fxPU1Bmg; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 19D8E205B9; Wed, 29 May 2024 16:22:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1716999756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aCZu6jdsDJqbFUOxgklErOVfk3nUsdlFfJQML2sSSgA=; b=C+jo/LF8K39lhbdaZ1p2WiJgAHG3wgS6vuKBsAsAhgae7r30juMxBVDBZ/Yv0R+zYyIR9A ei4L9SF6ACtq8DghCUEOMyCEUsQv5RvaLisqeaZEM/bTvcBp+zJ2e770bvSK1TZnCmU5kd TdwuOhqs+gxG/Awylxe9CkCJggdDS8c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1716999756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aCZu6jdsDJqbFUOxgklErOVfk3nUsdlFfJQML2sSSgA=; b=fxPU1BmgKhi9azuUhIPM5e1vvALlG1xJsHEBOphIoINivX8k5AWjZZKoPQTv79aF195+r6 wzbRYW7fVSp9SzDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1716999756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aCZu6jdsDJqbFUOxgklErOVfk3nUsdlFfJQML2sSSgA=; b=C+jo/LF8K39lhbdaZ1p2WiJgAHG3wgS6vuKBsAsAhgae7r30juMxBVDBZ/Yv0R+zYyIR9A ei4L9SF6ACtq8DghCUEOMyCEUsQv5RvaLisqeaZEM/bTvcBp+zJ2e770bvSK1TZnCmU5kd TdwuOhqs+gxG/Awylxe9CkCJggdDS8c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1716999756; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aCZu6jdsDJqbFUOxgklErOVfk3nUsdlFfJQML2sSSgA=; b=fxPU1BmgKhi9azuUhIPM5e1vvALlG1xJsHEBOphIoINivX8k5AWjZZKoPQTv79aF195+r6 wzbRYW7fVSp9SzDQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0B55B1372E; Wed, 29 May 2024 16:22:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id RxQ+AkxWV2ZOBgAAD6G6ig (envelope-from ); Wed, 29 May 2024 16:22:36 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 9BA1AA082D; Wed, 29 May 2024 18:22:35 +0200 (CEST) Date: Wed, 29 May 2024 18:22:35 +0200 From: Jan Kara To: Yuntao Wang Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexander Viro , Christian Brauner , Jan Kara Subject: Re: [PATCH] fs/file: fix the check in find_next_fd() Message-ID: <20240529162235.b76ywqisawmcm22o@quack3> 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> X-Spam-Flag: NO X-Spam-Score: -3.72 X-Spam-Level: X-Spamd-Result: default: False [-3.72 / 50.00]; BAYES_HAM(-2.92)[99.67%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_RHS_NOT_FQDN(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; RCVD_COUNT_THREE(0.00)[3]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_LAST(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[linux.dev:email,suse.com:email,imap1.dmz-prg2.suse.org:helo,suse.cz:email] On Thu 30-05-24 00:06:56, 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. > > Signed-off-by: Yuntao Wang Good point. Feel free to add: Reviewed-by: Jan Kara Honza > --- > 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 > -- Jan Kara SUSE Labs, CR