Message ID | 20230801143204.2284343-3-shikemeng@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp2481663vqg; Mon, 31 Jul 2023 23:41:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/MVemIRUy1uAHLHq+aTZ2bCh9yyMdIEpvsm3toB6RVRz2xRHvO38FrStu8j1/OODdG4a4 X-Received: by 2002:a05:6a00:419a:b0:67d:308b:97ef with SMTP id ca26-20020a056a00419a00b0067d308b97efmr10827317pfb.2.1690872095065; Mon, 31 Jul 2023 23:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690872095; cv=none; d=google.com; s=arc-20160816; b=0SJiaC7CzXZ+64FxfOlf4YZsMDRjj6D1DEySuvFBPD6ERnmca3w67ZQnsYhuxx+yCb mbwZt9ljOnSrEvtdtZrsZaZBJ3RbRCD5vKjUqYK4RLubx9LoaqjRMhIpw1T/5zaxLybE xxHZWysxymj5jmoPU5MwdAFV+PYY/TVlXkFTHp8HhmoN7OM8zc9M7tBuGGGquUkhCHNi +Y56hY9/jrJfrkpOpfmHwezVCAzsyi1lrHchPxuvmkLoMYxzkF8cMk9d+rI9BArBZ74E 4yIAfzr75cGAaOv+EkP3iSEyIKgGN581xMw1lBUNyJAiSXpimniOVFU74oJ2qJLBRd8A JMmg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oS09VbzT0L5bZHtokM76Lw+dlqbeimHpMjisr68qnys=; fh=MlGqaUnvBjpXmiP990bdf+mzv9VjPrVaE5OVdv29XYE=; b=zve2MNh31RTsUjvXzL4Sw6G+Ok3smY49Fyq3dM2xeEasLfmZ/WFVKyQrPbsKStNOTe nYhNmY/mh407/ZYWko4j3ZgyiP/+NTNVNkB2l8C0IfFbZpAqNxfHy8aDU5kXKKkWw+JC GOwrNIDuGNmFtWJvw+HgV0SloB9hqUccD5q2BJWgi/9AC1A2vPWXnuucJeyvJjblzLIL UGoanjEjSvo5h4Y3LtnX0DKWgBFtT4nZG9pJPvMDsF0k1ni3hVZUXWe5PjLLjsdREs1Q DFa3VHMNptAeOKiwP2cVQHk1cPxnnSh0xEv96IaRGo0nG4UPq/KyvXABo/cWM9pzwR9Z L/uQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n4-20020a635904000000b00553e8d95742si7182500pgb.654.2023.07.31.23.41.21; Mon, 31 Jul 2023 23:41:35 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231478AbjHAGby (ORCPT <rfc822;cambridge8321@gmail.com> + 99 others); Tue, 1 Aug 2023 02:31:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbjHAGbx (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 1 Aug 2023 02:31:53 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24449E9; Mon, 31 Jul 2023 23:31:51 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4RFQHl5TnLz4f3l8B; Tue, 1 Aug 2023 14:31:47 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP2 (Coremail) with SMTP id Syh0CgDnjOrQpshkMcvqPA--.21719S4; Tue, 01 Aug 2023 14:31:48 +0800 (CST) From: Kemeng Shi <shikemeng@huaweicloud.com> To: tytso@mit.edu, adilger.kernel@dilger.ca, ritesh.list@gmail.com, ojaswin@linux.ibm.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Cc: shikemeng@huaweicloud.com Subject: [PATCH v3 02/10] ext4: avoid potential data overflow in next_linear_group Date: Tue, 1 Aug 2023 22:31:56 +0800 Message-Id: <20230801143204.2284343-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230801143204.2284343-1-shikemeng@huaweicloud.com> References: <20230801143204.2284343-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: Syh0CgDnjOrQpshkMcvqPA--.21719S4 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww1fAw1xWr45Gw17Ww48Zwb_yoW8JFy5pr srG3W8uryYgr1DGa9xGayvg3WrKw4Ig3WUJryfuw1jvF97Jr1kJFZrtr10vFyfGF4UAF15 Xa15AF1Uu3WfuaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPab4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M280x2IEY4vEnII2IxkI6r1a6r45M2 8IrcIa0xkI8VA2jI8067AKxVWUXwA2048vs2IY020Ec7CjxVAFwI0_Gr0_Xr1l8cAvFVAK 0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4 x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v2 6r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6I AqYI8I648v4I1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAq x4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r 1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF 7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxV WUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjTR mfOrUUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773007897776919921 X-GMAIL-MSGID: 1773007897776919921 |
Series |
A few fixes and cleanups to mballoc
|
|
Commit Message
Kemeng Shi
Aug. 1, 2023, 2:31 p.m. UTC
ngroups is ext4_group_t (unsigned int) while next_linear_group treat it in int. If ngroups is bigger than max number described by int, it will be treat as a negative number. Then "return group + 1 >= ngroups ? 0 : group + 1;" may keep returning 0. Switch int to ext4_group_t in next_linear_group to fix the overflow. Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning") Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com> Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> --- fs/ext4/mballoc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 556b7cd27f76..a6635cba291a 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1080,8 +1080,9 @@ static inline int should_optimize_scan(struct ext4_allocation_context *ac) * Return next linear group for allocation. If linear traversal should not be * performed, this function just returns the same group */ -static int -next_linear_group(struct ext4_allocation_context *ac, int group, int ngroups) +static ext4_group_t +next_linear_group(struct ext4_allocation_context *ac, ext4_group_t group, + ext4_group_t ngroups) { if (!should_optimize_scan(ac)) goto inc_and_return;