From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F54EC433EF for ; Wed, 30 Mar 2022 06:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243244AbiC3GXL (ORCPT ); Wed, 30 Mar 2022 02:23:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238147AbiC3GXF (ORCPT ); Wed, 30 Mar 2022 02:23:05 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E3125046D; Tue, 29 Mar 2022 23:21:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E9D0AB81AD5; Wed, 30 Mar 2022 06:21:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A357AC340EC; Wed, 30 Mar 2022 06:21:17 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Ty2Q3C+n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1648621276; h=from:from:reply-to:subject:subject: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=2eRrPnqhTJjokXQOdORL7R4K689Hcih8p/XLm4p+Fvc=; b=Ty2Q3C+nxdjUQaGjzpqGcNWXhdezVxMLyN15NAoBzzwwlIQXJcfOnqRrOFLwMyyx2Xe2dy /7xX+lea48DGH7t3FxoPzw9ydT8Vlt1HH5VdQ1cqC/Rt2unU+agicblhqnyTLLjqmN57OJ WBaDiPIKKHn3Ig+J3hKmgdfa2vJo2eo= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 042fe011 (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Wed, 30 Mar 2022 06:21:15 +0000 (UTC) Date: Wed, 30 Mar 2022 02:21:14 -0400 From: "Jason A. Donenfeld" To: Linus Torvalds Cc: Fedor Pchelkin , Alexey Khoroshilov , Eric Biggers , Christian Brauner , Alexander Viro , linux-fsdevel , Linux Kernel Mailing List Subject: Re: [PATCH 4/4] file: Fix file descriptor leak in copy_fd_bitmaps() Message-ID: References: <20220326114009.1690-1-aissur0002@gmail.com> <2698031.BEx9A2HvPv@fedor-zhuzhzhalka67> <4705670.GXAFRqVoOG@fedor-zhuzhzhalka67> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Linus, On Tue, Mar 29, 2022 at 11:08:55PM -0700, Linus Torvalds wrote: > So does it help if you just remove that > > max_fds = ALIGN(max_fds, BITS_PER_LONG); > > and instead make the final return be > > return ALIGN(min(count, max_fds), BITS_PER_LONG); > > instead? Yep, that works: diff --git a/fs/file.c b/fs/file.c index c01c29417ae6..ee9317346702 100644 --- a/fs/file.c +++ b/fs/file.c @@ -303,10 +303,9 @@ static unsigned int sane_fdtable_size(struct fdtable *fdt, unsigned int max_fds) unsigned int count; count = count_open_files(fdt); - max_fds = ALIGN(max_fds, BITS_PER_LONG); if (max_fds < NR_OPEN_DEFAULT) max_fds = NR_OPEN_DEFAULT; - return min(count, max_fds); + return ALIGN(min(count, max_fds), BITS_PER_LONG); } /* Jason