Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp663700pxb; Tue, 5 Apr 2022 17:51:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyj9/NBHSNeJPw9QQNElcZecZYpMNSIqiwiRshBS8irNiNSNxqZinnywWteFoVVmdenpC7 X-Received: by 2002:a17:902:d0d2:b0:156:caaa:6c16 with SMTP id n18-20020a170902d0d200b00156caaa6c16mr6122447pln.81.1649206290277; Tue, 05 Apr 2022 17:51:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206290; cv=none; d=google.com; s=arc-20160816; b=gakFIE4XNiDOkXZfxCgPEqsYNT4rQBV/Af4OkSXLiRlYzyemqJutMqnq7ey5Rjn+am Yll0v+Keu9jOq0eA5cdb4V6ozwwR43dhyndajOl7/Oc6lDK2w3MbmzikeD4FKMaumKE3 wEMO9wTyI9A8eq6z+UUqcOW93ko7dfEpeq2NHk0A8G5Z8HBxW1b1FdW49rn9UDDhI+Pw FYrKChUR6xHOYUZkz8cAtO0lhBhxiFBKCN6CLLPwTQ7X68PN5pDaQSyB1I2DUQJecCAR 2zw6wTvH6SfQV87lMz027eWq9xWkrQqgROyLBQo0tGHiyKvmafPiZKmKK7i6XsCvUVKs znXg== 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=SlCG3nbINMy2ycs7AccFLdvpBnai3RzafmBwy+TJHeXeZHW1S9/9I+pxx/WhLGJXEx 6Mn6FUHrh6KwdktgnY7I8sm4ueUtXkheUgCj6fyMQTxUvgX7EsqD55PfwsSXYGNEPsY7 +OiqIOtTpH7b8bVEP7cq9/FU97+9NrszFbKPExv0lixRoess8q24pkxnhlvSYWkh1fC/ neVBZvLh8oo5CI4xjGMXhbTrGIyGBUSCSWkX8e8oFV4JVmyxk1cjaCgj+ZKQNhePm3Ot l79TZG2eG7Er8ZgjOqFVNrOeFbVLFLZ8+FGGEGnIsT/0WSMmAjlBe1BNy8mlSp2pPj2t N8Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K30RS9or; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bd6-20020a170902830600b00153b2d1663dsi13320201plb.581.2022.04.05.17.51.15; Tue, 05 Apr 2022 17:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=K30RS9or; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229471AbiDEJnt (ORCPT + 99 others); Tue, 5 Apr 2022 05:43:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239600AbiDEIUP (ORCPT ); Tue, 5 Apr 2022 04:20:15 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27AEC83; Tue, 5 Apr 2022 01:17:12 -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 C9394B81BB2; Tue, 5 Apr 2022 08:17:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22650C385A1; Tue, 5 Apr 2022 08:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146629; bh=3KGFa6EC32xjqdgLhOOEcMv8VXMCN8d2FHi3RO5nQi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K30RS9orHTn9vFLpPPhw5nkiFmcumWemH7adAwikgpvgooT4380kxTgMYTdA85Bq1 qRHvkZC6xJVtjjAd68LYLxUNIyRca+F5JV6HHg/QdqAdMFV3r+QedADyasQnSPfIqB z+/nNHOyNTjAWpQ0gE7K/FP7twVqap5Ftv4Tolv4= 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.17 0832/1126] fs: fix fd table size alignment properly Date: Tue, 5 Apr 2022 09:26:19 +0200 Message-Id: <20220405070431.979689181@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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