Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10627579rwp; Fri, 21 Jul 2023 02:13:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlHCk/0B30yVRDQGMfkwXJgpTqp4Hxwol+zSBWDINEPSMchuMupDvgmw+imq6an6Crwct91m X-Received: by 2002:a17:907:b0c:b0:999:9424:f5cc with SMTP id h12-20020a1709070b0c00b009999424f5ccmr1174406ejl.33.1689930791274; Fri, 21 Jul 2023 02:13:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689930791; cv=none; d=google.com; s=arc-20160816; b=Z7b1HkzA0NENFkisRARn4uZENqbTrt2jki+lEZlGQZ2+AOz4ZDVOkeN9I0Kxq3bhok 2HO/0GCKoQ+qg/4kHCu1EhuTcxjhTx4QzONPdZQZpmwwWe2GmZUoRpiX2vg+2iCws384 N9Pg9negf2KR7QgDk8EL781JGtYedynUx6snpdLT2CZ1dR4yHYGa8UuQqxJH0d/P7mca rHCzqFcEy+IjyYyZIe7gMgdiz7wAnR2kJ0DKB/j7hxKsgnkw095x2/Zr0dFSMrr1o33g tfw0fBIB01eXjmshYeCNXTGwwTOagsCYnbZ6E38LzPiXAkcwBdyZQI9gEen4FWmkV3oo 4+jA== 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=bGiRuQWoSZDYHPJWOIWT6ZPRZoiftczZk6Lj+KeE6Aw=; fh=MlGqaUnvBjpXmiP990bdf+mzv9VjPrVaE5OVdv29XYE=; b=Izn0knddjDTZe8E8UjWF8U+ubCMhfy55irgLkU4eOKWaKTJgUokfqOMxLU30K1Km/h YOIdlm9OHnuFVgtopKYsItIoPYc5GDWNP6reoFKiMO8gchc1lnygJrbMkjNzd7xjAZrW QfNClnOcveQFBL8jzqZHml2utd0Yl2WsXexnlNzEqY0Z0fGqdkFyXUEq9QMNDE8NDY4u SH/wmpwclL0N6QleADhc7Ec3Ry9x4oqKtD8dD9leJ6awzE9/pF9D3Zed6JH1Krn0Fk9P yP01h6onIeQmuWUQ9jNEvvj37a1KsI9uh+0fBqVwQFECOqltCbEbOp6m633sW7Kzobr5 A+kA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt8-20020a170906b14800b00987e40fd473si1940963ejb.1019.2023.07.21.02.12.47; Fri, 21 Jul 2023 02:13:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231432AbjGUJJn (ORCPT + 99 others); Fri, 21 Jul 2023 05:09:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjGUJJm (ORCPT ); Fri, 21 Jul 2023 05:09:42 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A92DD2D7E; Fri, 21 Jul 2023 02:09:40 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R6kJw2nk2z4f3nTL; Fri, 21 Jul 2023 17:09:36 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgAHvrFPS7pkqi7fOQ--.527S4; Fri, 21 Jul 2023 17:09:37 +0800 (CST) From: Kemeng Shi 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 02/10] ext4: avoid potential data overflow in next_linear_group Date: Sat, 22 Jul 2023 01:09:59 +0800 Message-Id: <20230721171007.2065423-3-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230721171007.2065423-1-shikemeng@huaweicloud.com> References: <20230721171007.2065423-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgAHvrFPS7pkqi7fOQ--.527S4 X-Coremail-Antispam: 1UD129KBjvdXoWruryDuFWruFy8Zry8GFyDZFb_yoWkCFc_Ga 10yr4fJF95Jw1S9a4I9wsYyrWvgFsYyr1UXFWftFsxZ3WUXw48u3WDJrsxZFW8uryfAFy5 urW7Cr1SyFWS9jkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbqAYFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l87I20VAvwVAaII0Ic2I_JFv_Gryl82 xGYIkIc2x26280x7IE14v26r15M28IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kI II0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7 xvwVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2 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, KHOP_HELO_FCRDNS,MAY_BE_FORGED,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: X-Mailing-List: linux-ext4@vger.kernel.org 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. Signed-off-by: Kemeng Shi --- 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 90ffabac100b..33ee3991f62c 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1081,8 +1081,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; -- 2.30.0