From nobody Tue Apr 28 22:03:52 2026 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 64773C433EF for ; Fri, 27 May 2022 14:21:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351827AbiE0OVJ (ORCPT ); Fri, 27 May 2022 10:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbiE0OVI (ORCPT ); Fri, 27 May 2022 10:21:08 -0400 X-Greylist: delayed 341 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 27 May 2022 07:21:07 PDT Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0AC28106560; Fri, 27 May 2022 07:21:06 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id EACD52629; Fri, 27 May 2022 14:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1653661237; bh=XnC7aSAr5neGOTbasoTgRb0LT1HnKG7Qv+EzDQ/U96s=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=TJo2FR8XuGjp2J4EmDVyjwgKesMT1QCW38axW6Bg555bGml6FqTEzHGDpJU4Otbt7 f5iJ6T7UCq8+PqDA9gAyLh7tzVqXUw8IqAutKrMrZcTRdhFPvpbcAN5PogAz9zK0q8 mi/dK3fYOOOI/YNIejBMlQttPpQD/U06Ib6fNC/E= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 93361220E; Fri, 27 May 2022 14:21:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1653661264; bh=XnC7aSAr5neGOTbasoTgRb0LT1HnKG7Qv+EzDQ/U96s=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=XoYlcs8nM4kChSxxvHnaa/UCkpzr5vQ187tjOzeDwUdPbQZia6n1/keHbS5VOiz/N hkB6+5A9TlT5s7wkL3RN3zanV2X/sNeqzdGu/FtPJJkR9j5QSXepzjJurZvEQsZo/j 2e3sQHB1fR+V4nqIgxcKV8ub2JSYAHX1JFovNgHo= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 27 May 2022 17:21:04 +0300 Message-ID: <0f9648cc-66af-077c-88e6-8650fd78f44c@paragon-software.com> Date: Fri, 27 May 2022 17:21:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [PATCH 1/3] fs/ntfs3: Refactoring of indx_find function Content-Language: en-US From: Almaz Alexandrovich To: CC: , References: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> In-Reply-To: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.30.8.65] 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 Content-Type: text/plain; charset="utf-8"; format="flowed" This commit makes function a bit more readable Signed-off-by: Konstantin Komarov --- fs/ntfs3/index.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 6f81e3a49abf..511f872b6650 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1042,19 +1042,16 @@ int indx_find(struct ntfs_index *indx, struct ntfs_= inode *ni, { int err; struct NTFS_DE *e; - const struct INDEX_HDR *hdr; struct indx_node *node; =20 if (!root) root =3D indx_get_root(&ni->dir, ni, NULL, NULL); =20 if (!root) { - err =3D -EINVAL; - goto out; + /* Should not happed. */ + return -EINVAL; } =20 - hdr =3D &root->ihdr; - /* Check cache. */ e =3D fnd->level ? fnd->de[fnd->level - 1] : fnd->root_de; if (e && !de_is_last(e) && @@ -1068,39 +1065,34 @@ int indx_find(struct ntfs_index *indx, struct ntfs_= inode *ni, fnd_clear(fnd); =20 /* Lookup entry that is <=3D to the search value. */ - e =3D hdr_find_e(indx, hdr, key, key_len, ctx, diff); + e =3D hdr_find_e(indx, &root->ihdr, key, key_len, ctx, diff); if (!e) return -EINVAL; =20 fnd->root_de =3D e; - err =3D 0; =20 for (;;) { node =3D NULL; if (*diff >=3D 0 || !de_has_vcn_ex(e)) { *entry =3D e; - goto out; + return 0; } =20 /* Read next level. */ err =3D indx_read(indx, ni, de_get_vbn(e), &node); if (err) - goto out; + return err; =20 /* Lookup entry that is <=3D to the search value. */ e =3D hdr_find_e(indx, &node->index->ihdr, key, key_len, ctx, diff); if (!e) { - err =3D -EINVAL; put_indx_node(node); - goto out; + return -EINVAL; } =20 fnd_push(fnd, node, e); } - -out: - return err; } =20 int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni, --=20 2.36.1 From nobody Tue Apr 28 22:03:52 2026 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 5924FC433EF for ; Fri, 27 May 2022 14:22:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353069AbiE0OWI (ORCPT ); Fri, 27 May 2022 10:22:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350235AbiE0OWG (ORCPT ); Fri, 27 May 2022 10:22:06 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCCF234BAE; Fri, 27 May 2022 07:22:04 -0700 (PDT) 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 297FA2629; Fri, 27 May 2022 14:21:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1653661295; bh=gY524lf/gzPmcrcGqzOWu5zx71hGf3abpPOyo+Ffr80=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ED7kfG/vEm9bI9Gft1ivzFLUVj7DPujpoJSWZZ3ri7HXf/QnknuRrlbU5HZZFeLw2 7pjwBE5E3/+KwmjYBuVk/JhlgqYK5Gxkp6n4d0H/rE2JMjikDDyr8cT4incsbuhty9 Mk53R8mjisNgLESqwNw7IVtS+aPEPTZLbiYlbu9I= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 27 May 2022 17:22:02 +0300 Message-ID: Date: Fri, 27 May 2022 17:22:02 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [PATCH 2/3] fs/ntfs3: Fix double free on remount Content-Language: en-US From: Almaz Alexandrovich To: CC: , References: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> In-Reply-To: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.30.8.65] 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 Content-Type: text/plain; charset="utf-8"; format="flowed" Pointer to options was freed twice on remount Fixes xfstest generic/361 Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Signed-off-by: Konstantin Komarov --- fs/ntfs3/super.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index d41d76979e12..697a84ed395e 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -390,7 +391,7 @@ static int ntfs_fs_reconfigure(struct fs_context *fc) return -EINVAL; } =20 - memcpy(sbi->options, new_opts, sizeof(*new_opts)); + swap(sbi->options, fc->fs_private); =20 return 0; } @@ -897,6 +898,8 @@ static int ntfs_fill_super(struct super_block *sb, stru= ct fs_context *fc) ref.high =3D 0; =20 sbi->sb =3D sb; + sbi->options =3D fc->fs_private; + fc->fs_private =3D NULL; sb->s_flags |=3D SB_NODIRATIME; sb->s_magic =3D 0x7366746e; // "ntfs" sb->s_op =3D &ntfs_sops; @@ -1260,8 +1263,6 @@ static int ntfs_fill_super(struct super_block *sb, st= ruct fs_context *fc) goto put_inode_out; } =20 - fc->fs_private =3D NULL; - return 0; =20 put_inode_out: @@ -1414,7 +1415,6 @@ static int ntfs_init_fs_context(struct fs_context *fc) mutex_init(&sbi->compress.mtx_lzx); #endif =20 - sbi->options =3D opts; fc->s_fs_info =3D sbi; ok: fc->fs_private =3D opts; --=20 2.36.1 From nobody Tue Apr 28 22:03:52 2026 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 8F3A3C433EF for ; Fri, 27 May 2022 14:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353181AbiE0OW5 (ORCPT ); Fri, 27 May 2022 10:22:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353118AbiE0OWz (ORCPT ); Fri, 27 May 2022 10:22:55 -0400 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2B4F1207DD; Fri, 27 May 2022 07:22:53 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 0065C2629; Fri, 27 May 2022 14:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1653661344; bh=sICHCfo4uTR9mxXHyCTyqelqqIWYEf1R3oO5FRPMAf0=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=msCE6ahjekAsKMAmi68igLtf3/NyuBiUjfAW/r0yqeP4Z6GKaPq2a61ybqX7JpP2q BOFcVlbiA9ciz5FZ0/T5Hzb5zUdQfVLdY39HjHud1L9UHcVRBT0eL7TfHladY1zykt D0/YxHZVyuyiCFwsqQe5mRfcplYidnjcRRLSo/eM= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id A918A220E; Fri, 27 May 2022 14:22:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1653661371; bh=sICHCfo4uTR9mxXHyCTyqelqqIWYEf1R3oO5FRPMAf0=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Pl/r9H/gBYwCQ+ylmGeSeWFFgdyYCo8S3wxh3Cz+JlFNtO19gb6/d0WU/66AlAgHK b7qf2O7huWztDJ4TTi+FjHUvVkJpZU2sQRJD0m+SwoJyDHdQVZqkSCqwm3njCEQyX6 6rtJTVpZo6FXqQk5IjxDA7TLKcVmUP+4kqzvx53Q= Received: from [172.30.8.65] (172.30.8.65) 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; Fri, 27 May 2022 17:22:51 +0300 Message-ID: <5de359b4-e3d5-e585-10c4-65139cef6e14@paragon-software.com> Date: Fri, 27 May 2022 17:22:50 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: [PATCH 3/3] fs/ntfs3: Refactor ni_try_remove_attr_list function Content-Language: en-US From: Almaz Alexandrovich To: CC: , References: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> In-Reply-To: <75a1215a-eda2-d0dc-b962-0334356eef7c@paragon-software.com> Content-Transfer-Encoding: quoted-printable X-Originating-IP: [172.30.8.65] 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 Content-Type: text/plain; charset="utf-8"; format="flowed" Now we save a copy of primary record for restoration. Also now we remove all attributes from subrecords. Signed-off-by: Konstantin Komarov --- fs/ntfs3/frecord.c | 49 ++++++++++++++++++++++++++++++++++------------ fs/ntfs3/record.c | 5 ++--- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 18842998c8fa..3576268ee0a1 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -7,6 +7,7 @@ =20 #include #include +#include #include =20 #include "debug.h" @@ -649,6 +650,7 @@ static int ni_try_remove_attr_list(struct ntfs_inode *n= i) struct mft_inode *mi; u32 asize, free; struct MFT_REF ref; + struct MFT_REC *mrec; __le16 id; =20 if (!ni->attr_list.dirty) @@ -692,11 +694,17 @@ static int ni_try_remove_attr_list(struct ntfs_inode = *ni) free -=3D asize; } =20 + /* Make a copy of primary record to restore if error. */ + mrec =3D kmemdup(ni->mi.mrec, sbi->record_size, GFP_NOFS); + if (!mrec) + return 0; /* Not critical. */ + /* It seems that attribute list can be removed from primary record. */ mi_remove_attr(NULL, &ni->mi, attr_list); =20 /* - * Repeat the cycle above and move all attributes to primary record. + * Repeat the cycle above and copy all attributes to primary record. + * Do not remove original attributes from subrecords! * It should be success! */ le =3D NULL; @@ -707,14 +715,14 @@ static int ni_try_remove_attr_list(struct ntfs_inode = *ni) mi =3D ni_find_mi(ni, ino_get(&le->ref)); if (!mi) { /* Should never happened, 'cause already checked. */ - goto bad; + goto out; } =20 attr =3D mi_find_attr(mi, NULL, le->type, le_name(le), le->name_len, &le->id); if (!attr) { /* Should never happened, 'cause already checked. */ - goto bad; + goto out; } asize =3D le32_to_cpu(attr->size); =20 @@ -724,18 +732,33 @@ static int ni_try_remove_attr_list(struct ntfs_inode = *ni) le16_to_cpu(attr->name_off)); if (!attr_ins) { /* - * Internal error. - * Either no space in primary record (already checked). - * Either tried to insert another - * non indexed attribute (logic error). + * No space in primary record (already checked). */ - goto bad; + goto out; } =20 /* Copy all except id. */ id =3D attr_ins->id; memcpy(attr_ins, attr, asize); attr_ins->id =3D id; + } + + /* + * Repeat the cycle above and remove all attributes from subrecords. + */ + le =3D NULL; + while ((le =3D al_enumerate(ni, le))) { + if (!memcmp(&le->ref, &ref, sizeof(ref))) + continue; + + mi =3D ni_find_mi(ni, ino_get(&le->ref)); + if (!mi) + continue; + + attr =3D mi_find_attr(mi, NULL, le->type, le_name(le), + le->name_len, &le->id); + if (!attr) + continue; =20 /* Remove from original record. */ mi_remove_attr(NULL, mi, attr); @@ -748,11 +771,13 @@ static int ni_try_remove_attr_list(struct ntfs_inode = *ni) ni->attr_list.le =3D NULL; ni->attr_list.dirty =3D false; =20 + kfree(mrec); + return 0; +out: + /* Restore primary record. */ + swap(mrec, ni->mi.mrec); + kfree(mrec); return 0; -bad: - ntfs_inode_err(&ni->vfs_inode, "Internal error"); - make_bad_inode(&ni->vfs_inode); - return -EINVAL; } =20 /* diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index 861e35791506..8fe0a876400a 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -445,12 +445,11 @@ struct ATTRIB *mi_insert_attr(struct mft_inode *mi, e= num ATTR_TYPE type, attr =3D NULL; while ((attr =3D mi_enum_attr(mi, attr))) { diff =3D compare_attr(attr, type, name, name_len, upcase); - if (diff > 0) - break; + if (diff < 0) continue; =20 - if (!is_attr_indexed(attr)) + if (!diff && !is_attr_indexed(attr)) return NULL; break; } --=20 2.36.1