From nobody Fri Sep 12 00:30:58 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5755DC636CC for ; Wed, 15 Feb 2023 13:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231186AbjBONh1 (ORCPT ); Wed, 15 Feb 2023 08:37:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjBONh0 (ORCPT ); Wed, 15 Feb 2023 08:37:26 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B980358D; Wed, 15 Feb 2023 05:37:25 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id D63352147; Wed, 15 Feb 2023 13:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467992; bh=s+jnBTb+FEAmnBEVyyEk7i0waZIXU0NPfdQERDIaNfE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ndKFZlp5o5+usKaaciH36JgPDyMsCNQzIeMorpXuUXxrHaeCrx5tuzcEccSGTQwZr 8N7sIMjEzZ0wshdQifn3gEbFbZRBqU+RiYSZZgTxpp5qBmEqS+GrRb/6y4p8ZUQJJr el3CtPeW4mvu41Zlz/1+woYx27WOLOdtnDxaaXsE= Received: from [192.168.211.36] (192.168.211.36) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 15 Feb 2023 16:37:22 +0300 Message-ID: <3f4de192-d3f3-f2b3-2b05-8c1c027d1d8c@paragon-software.com> Date: Wed, 15 Feb 2023 17:37:22 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 06/11] fs/ntfs3: Undo critial modificatins to keep directory consistency Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Affect xfstest 320. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/index.c | 30 ++++++++++++++++++++---------- =C2=A01 file changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 9fefeac5fe7e..5d1ec0124137 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1778,10 +1778,11 @@ indx_insert_into_buffer(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 struct indx_node *n1 =3D fnd->nodes[level]; =C2=A0=C2=A0=C2=A0=C2=A0 struct INDEX_HDR *hdr1 =3D &n1->index->ihdr; =C2=A0=C2=A0=C2=A0=C2=A0 struct INDEX_HDR *hdr2; -=C2=A0=C2=A0=C2=A0 u32 to_copy, used; +=C2=A0=C2=A0=C2=A0 u32 to_copy, used, used1; =C2=A0=C2=A0=C2=A0=C2=A0 CLST new_vbn; =C2=A0=C2=A0=C2=A0=C2=A0 __le64 t_vbn, *sub_vbn; =C2=A0=C2=A0=C2=A0=C2=A0 u16 sp_size; +=C2=A0=C2=A0=C2=A0 void *hdr1_saved =3D NULL; =C2=A0=C2=A0=C2=A0=C2=A0 /* Try the most easy case. */ =C2=A0=C2=A0=C2=A0=C2=A0 e =3D fnd->level - 1 =3D=3D level ? fnd->de[level= ] : NULL; @@ -1814,6 +1815,13 @@ indx_insert_into_buffer(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 return -ENOMEM; =C2=A0=C2=A0=C2=A0=C2=A0 memcpy(up_e, sp, sp_size); +=C2=A0=C2=A0=C2=A0 used1 =3D le32_to_cpu(hdr1->used); +=C2=A0=C2=A0=C2=A0 hdr1_saved =3D kmemdup(hdr1, used1, GFP_NOFS); +=C2=A0=C2=A0=C2=A0 if (!hdr1_saved) { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D -ENOMEM; +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 goto out; +=C2=A0=C2=A0=C2=A0 } + =C2=A0=C2=A0=C2=A0=C2=A0 if (!hdr1->flags) { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 up_e->flags |=3D NTFS_IE_HAS_S= UBNODES; =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 up_e->size =3D cpu_to_le16(sp_= size + sizeof(u64)); @@ -1846,7 +1854,7 @@ indx_insert_into_buffer(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 hdr_insert_head(hdr2, de_t, to_copy); =C2=A0=C2=A0=C2=A0=C2=A0 /* Remove all entries (sp including) from hdr1. */ -=C2=A0=C2=A0=C2=A0 used =3D le32_to_cpu(hdr1->used) - to_copy - sp_size; +=C2=A0=C2=A0=C2=A0 used =3D used1 - to_copy - sp_size; =C2=A0=C2=A0=C2=A0=C2=A0 memmove(de_t, Add2Ptr(sp, sp_size), used - le32_t= o_cpu(hdr1->de_off)); =C2=A0=C2=A0=C2=A0=C2=A0 hdr1->used =3D cpu_to_le32(used); @@ -1876,8 +1884,6 @@ indx_insert_into_buffer(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 if (!level) { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* Insert in root. */ =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D indx_insert_into_root(= indx, ni, up_e, NULL, ctx, fnd, 0); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (err) -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 goto out; =C2=A0=C2=A0=C2=A0=C2=A0 } else { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0* The target buffer's pa= rent is another index buffer. @@ -1885,12 +1891,20 @@ indx_insert_into_buffer(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*/ =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D indx_insert_into_buffe= r(indx, ni, root, up_e, ctx, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 level - 1, fnd); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (err) -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 goto out; +=C2=A0=C2=A0=C2=A0 } + +=C2=A0=C2=A0=C2=A0 if (err) { +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0* Undo critical operations. +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*/ +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 indx_mark_free(indx, ni, new_vbn >> = indx->idx2vbn_bits); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 memcpy(hdr1, hdr1_saved, used1); +=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 indx_write(indx, ni, n1, 0); =C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0out: =C2=A0=C2=A0=C2=A0=C2=A0 kfree(up_e); +=C2=A0=C2=A0=C2=A0 kfree(hdr1_saved); =C2=A0=C2=A0=C2=A0=C2=A0 return err; =C2=A0} @@ -1949,16 +1963,12 @@ int indx_insert_entry(struct ntfs_index *indx,=20 struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*/ =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D indx_insert_into_root(= indx, ni, new_de, fnd->root_de, ctx, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 fnd, undo); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (err) -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 goto out; =C2=A0=C2=A0=C2=A0=C2=A0 } else { =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 /* =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0* Found a leaf buffer, s= o we'll insert the new entry into it. =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*/ =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 err =3D indx_insert_into_buffe= r(indx, ni, root, new_de, ctx, =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2= =A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 fnd->level - 1,= fnd); -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 if (err) -=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 goto out; =C2=A0=C2=A0=C2=A0=C2=A0 } =C2=A0out: --=20 2.34.1