Received: by 2002:a05:7412:f584:b0:e2:908c:2ebd with SMTP id eh4csp2316067rdb; Wed, 6 Sep 2023 00:24:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGlfnUpKWUwXSZi9ymXSwnBNn7in+FIHZblzuVri57jfFjiHyRmXnNqTNUZy9GDaWHqH7/d X-Received: by 2002:a05:6402:8c3:b0:527:251e:1be8 with SMTP id d3-20020a05640208c300b00527251e1be8mr1465650edz.13.1693985078313; Wed, 06 Sep 2023 00:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693985078; cv=none; d=google.com; s=arc-20160816; b=wIX3kS9v2oVPga1gMiLolsm1TF13YrT4qEc/u1wib/p0T0wOyvofoUlwvNeBi6Y2Fw E7ifumbgz87wW7olvOvWS0jVwcGQU3XHG3TYx9+okHT/9UkKHmwCWS5IytHZOTDMjnAg t6jP1kiw02EEyxcMkZy8EQvbTQKjSOfTLRfUpCktMkmA3TvAaKkO+YFicJ6qD0arU3Jf fkAHtVnjH06n9fvdmCJrD1NO6yG9SE5rfyRfGq8+cqNYfpWRxHX0rc2L2z5YyOlNj9uX oYtGmnLYICudmOGzz+drWRq0klQXb4N/AubjswQ2f4XRZzDCzQsYcwHt/p3gjU8TzSXA b7iQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=GdKx2ca9c4FZOv75AxVV98y/R0uoJ+1SAmUNLUU17xM=; fh=J18NLo/oJ0GxNzA5m7jC+PdWU5QJQTO8VdqbdFX+3Bs=; b=pPKFRG2sSnBYtXlQVOPEozauGPNU0ixIu08aGytz4wmse9V5QPvKvdgseRzPmlV5xZ Sk/TqNOr0Xcq87dBQ/C4ufVewS4KmggPHBCPviXjBl4JrTNuK0lBVQ4RH2pHylp1m52k ZKSDHhBov2mt53ZqilomORMqyprSnuf1GgAwEdAuQ3hmXdbJdVLBfYkum38Ob28A4ZQs xpgt7R8MpJQ0316KgIJJwVlTUR74Pz5Ckp+rZlg5ctZpZYAHuoxU0h/EjOo5wSH9CL64 t8dYI3bSiAsW7KEuB3BWkmyZEtZnCATqNy8ib7N86HDwJ7s2bZpsXOkifATaaTrPFeq8 OMoA== 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 g14-20020a50ee0e000000b0052328243febsi9084863eds.153.2023.09.06.00.24.08; Wed, 06 Sep 2023 00:24:38 -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 S230226AbjIFBeR (ORCPT + 99 others); Tue, 5 Sep 2023 21:34:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229989AbjIFBeR (ORCPT ); Tue, 5 Sep 2023 21:34:17 -0400 Received: from smtpbg151.qq.com (smtpbg151.qq.com [18.169.211.239]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2194EBF; Tue, 5 Sep 2023 18:34:10 -0700 (PDT) X-QQ-mid: bizesmtp65t1693964025tuxkgbaa Received: from localhost.localdomain ( [113.200.76.118]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 06 Sep 2023 09:33:44 +0800 (CST) X-QQ-SSF: 01400000000000D0I000000A0000000 X-QQ-FEAT: ttAhR/+4RmkwQcBXx0/bYmPrTS4OCK09iM3T8Ufy+yqkvDtY8ELPLFanT9jfd 8SK2AVVa0XGH29e/aquu6Tx+/L2vaCYoQimoODap+VqDnznHrO9hx9IH4dcXc4u9lliF7wf l2Ugv8SsBpFgfvadxkzUkxFsIuiIsBXCAIfat8d/03dHc1Ld4/O0TPzNn82fj9SIMIL6/Sv fLxX5a04GpLuOPyp3ndvyvyioIYgfNCF3IEgTtKrgVaqAXIJgRsdC7dAyjV0s1XB193TVc4 4SmSmjac4hmYxntYgb17Uf2tkssJ3dc3DiPHEEG+RFMbBAOp6ERVvyrdBwx8TwDnlUlzvYG e0k4ejBYUBck0Mh96MdR7TJeWQHQ/wj9rcyd+uM6mDxx4LvZAFw6aWbJ3FoeYGLceaGYEHV X-QQ-GoodBg: 1 X-BIZMAIL-ID: 7777711094741804466 From: gouhao@uniontech.com To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org Cc: egouriou@google.com, linux-kernel@vger.kernel.org Subject: [PATCH] ext4: move 'ix' sanity check to corrent position Date: Wed, 6 Sep 2023 09:33:41 +0800 Message-Id: <20230906013341.7199-1-gouhao@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybglogicsvrgz:qybglogicsvrgz7a-0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 From: Gou Hao 'ix' check should be before using it. Fixes: 80e675f906db ("ext4: optimize memmmove lengths in extent/index insertions") Signed-off-by: Gou Hao --- fs/ext4/extents.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 202c76996b62..4d8496d1a8ac 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1010,6 +1010,11 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode, ix = curp->p_idx; } + if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) { + EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!"); + return -EFSCORRUPTED; + } + len = EXT_LAST_INDEX(curp->p_hdr) - ix + 1; BUG_ON(len < 0); if (len > 0) { @@ -1019,11 +1024,6 @@ static int ext4_ext_insert_index(handle_t *handle, struct inode *inode, memmove(ix + 1, ix, len * sizeof(struct ext4_extent_idx)); } - if (unlikely(ix > EXT_MAX_INDEX(curp->p_hdr))) { - EXT4_ERROR_INODE(inode, "ix > EXT_MAX_INDEX!"); - return -EFSCORRUPTED; - } - ix->ei_block = cpu_to_le32(logical); ext4_idx_store_pblock(ix, ptr); le16_add_cpu(&curp->p_hdr->eh_entries, 1); -- 2.20.1