Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1020102pxb; Wed, 6 Apr 2022 06:54:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxVoIN8xpgSbGhqnyMuWCjr3ihNDpIIssMIiXbc0l6SR9KS/bfd9R50gOwHbwClsxzshys X-Received: by 2002:a63:1014:0:b0:399:3710:f204 with SMTP id f20-20020a631014000000b003993710f204mr7265192pgl.424.1649253273736; Wed, 06 Apr 2022 06:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649253273; cv=none; d=google.com; s=arc-20160816; b=jo9igA54BPvRS7mN7NF6ja2ZlDmPS09MUiGDLJfc4GIuziTuWw1KCFIjEffJR7dA7K v9D8QVfktAVfxrti5ExFaptDyLOwPIQ2DVwGh6mbQ9lhmkaIMmJfSE3BCoFMhxn+66tw x1PRFUN1wLsG5S5X5kdjNBIgvl4UNMpyTli3daynQRAQ+sJA7ftNFxaxvQdllS7QRvZZ dEXlhshub05xElh7gTb9AckqYaOZSK6rG7w9AjNzJszlqWy2cwoaJbytg/fCOYhCNGRz 65QEFcRxIucYz/tEhgxAiUC0GfXnLoltsz2+wQFHhp0B+ZrZQ2nbgw3/AJr8MiCb1PO7 PfCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ob5QkvMTBVAcehqlsvpSo4iEfb92XOgNSKAAxjJkOws=; b=hmN02rM82NX8/vtqXDTe/zWsz/kt+T4Qz6tdbkMCgZ+tHVajLy8tS3LJicxI7I4uiw AG4I+3ONFopxPPHKkU4ZrwvECNn88zAwf45WkxYCgNdGccRlxrldPp3CubmgpnA6tpTI Es2JY0FKNH8gWCdKW8A4FJ2dWeWbxy4kDJh3wjNx7O5v3dtBBorS2Nwaa9X1j/85zKpd ys+5Y4wNSr91IelG8W5TPGIUerxvHWNidnX4+JsPlnx3RgJCmlK7a0+JUuuEkk9ojDg1 wCA9ZZAkCohnD9DwhuibnyLhprUPj3MovV5GXkEKAX7SHQwDD94KDJ5uyYy9zthk7Rig 4CFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLK2QYhw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r27-20020a63205b000000b0038609ba1522si16167730pgm.122.2022.04.06.06.54.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 06:54:33 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLK2QYhw; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 07E13241A21; Wed, 6 Apr 2022 04:48:27 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1392578AbiDEWKC (ORCPT + 99 others); Tue, 5 Apr 2022 18:10:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349798AbiDEJvd (ORCPT ); Tue, 5 Apr 2022 05:51:33 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15DC01D306; Tue, 5 Apr 2022 02:49:34 -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 AD6C7B81B76; Tue, 5 Apr 2022 09:49:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08891C385A2; Tue, 5 Apr 2022 09:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152172; bh=3KGFa6EC32xjqdgLhOOEcMv8VXMCN8d2FHi3RO5nQi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLK2QYhwwNEt83m+Nt59xZ8TjiqyMlohuS/D63dsr7nDUstm4iL4EAv/IMt2ebtRF h7LGTy6ztEa4cEdxwnlBppWQVn9ytuM/RBr3Fylmu1l/kBcZT1W6wVBn25LGsECxrU UOZD+k+Xxx8MKDXfuehL9ByNUIZnXf8pzn2XFm6Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fedor Pchelkin , Alexey Khoroshilov , Christian Brauner , Linus Torvalds , Sasha Levin , "Jason A . Donenfeld" Subject: [PATCH 5.15 681/913] fs: fix fd table size alignment properly Date: Tue, 5 Apr 2022 09:29:03 +0200 Message-Id: <20220405070400.247751851@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds [ Upstream commit d888c83fcec75194a8a48ccd283953bdba7b2550 ] Jason Donenfeld reports that my commit 1c24a186398f ("fs: fd tables have to be multiples of BITS_PER_LONG") doesn't work, and the reason is an embarrassing brown-paper-bag bug. Yes, we want to align the number of fds to BITS_PER_LONG, and yes, the reason they might not be aligned is because the incoming 'max_fd' argument might not be aligned. But aligining the argument - while simple - will cause a "infinitely big" maxfd (eg NR_OPEN_MAX) to just overflow to zero. Which most definitely isn't what we want either. The obvious fix was always just to do the alignment last, but I had moved it earlier just to make the patch smaller and the code look simpler. Duh. It certainly made _me_ look simple. Fixes: 1c24a186398f ("fs: fd tables have to be multiples of BITS_PER_LONG") Reported-and-tested-by: Jason A. Donenfeld Cc: Fedor Pchelkin Cc: Alexey Khoroshilov Cc: Christian Brauner Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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); } /* -- 2.34.1