From nobody Sun Feb 8 06:22:24 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 21553C0015E for ; Mon, 3 Jul 2023 07:32:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjGCHcn (ORCPT ); Mon, 3 Jul 2023 03:32:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjGCHcl (ORCPT ); Mon, 3 Jul 2023 03:32:41 -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 E7603CC; Mon, 3 Jul 2023 00:32:40 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 6740A1D34; Mon, 3 Jul 2023 07:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368769; bh=Rx//LO9/7IMTU2TX9c0DIpKI/VjGm4z0Maj34lCnuA8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mu+4Zi+tLFsNMkcxYwGJASldvxkMTPZFVITANt9PQgmJTIhNILUfanN8HReP5EGc5 xOzSWVLVzvh1CrbVPqqkTlw4n773/xN7s9TfM/EgnivaCCaitQa9SfuU+V/0/3DBz2 dDW1mRxHVXGxntNaJNTgR3OOLHnLFHs2erVFyFrA= 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 D2AF71D1E; Mon, 3 Jul 2023 07:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369080; bh=Rx//LO9/7IMTU2TX9c0DIpKI/VjGm4z0Maj34lCnuA8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=mbEfFe+uruU4DDxz9aMUbl86vfw5tJv1u7XTjIXN0qGP4zWp5U6A3fp4GDW60Dn7J UGp9F/YD7nbSA6VuaVUG+ZYaiHAKVGP8dP0FW4Br07t8eQbXVIYmXOg5fktOTnf6Yf iHxMePOqIco19Sq1QD1Fk18NmNFsNhLx4EcS2G0k= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:24:40 +0300 Message-ID: <379d007b-63d1-ab12-57aa-0ceee3d539a0@paragon-software.com> Date: Mon, 3 Jul 2023 11:24:39 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 1/8] fs/ntfs3: Add ckeck in ni_update_parent() 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.138] 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 Check simple case when parent inode equals current inode. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/frecord.c | 6 ++++++ =C2=A01 file changed, 6 insertions(+) diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 16bd9faa2d28..8f34d6472ddb 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -3208,6 +3208,12 @@ static bool ni_update_parent(struct ntfs_inode=20 *ni, struct NTFS_DUP_INFO *dup, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!fname || !memcmp(&fname->= dup, dup, sizeof(fname->dup))) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0continue; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Check simple case when parent ino= de equals current inode. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (ino_get(&fname->home) =3D=3D ni-= >vfs_inode.i_ino) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_set_state(sb= i, NTFS_DIRTY_ERROR); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0continue; +=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/* ntfs_iget5 may sleep. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dir =3D ntfs_iget5(sb, &fname-= >home, NULL); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (IS_ERR(dir)) { --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 1E135C001B0 for ; Mon, 3 Jul 2023 07:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbjGCHZV (ORCPT ); Mon, 3 Jul 2023 03:25:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230394AbjGCHZQ (ORCPT ); Mon, 3 Jul 2023 03:25:16 -0400 X-Greylist: delayed 78 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 03 Jul 2023 00:25:11 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 A192DE44; Mon, 3 Jul 2023 00:25:11 -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 4FC781D74; Mon, 3 Jul 2023 07:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368798; bh=HNQF4HBbkbbtfs/+y+hwwE6jqL+QQ9MoDuKoaujlRVA=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=hOGcwcG1jbJ4se1vlTg/W5WaRKGWc44Bq9SzAw5Jb9TxByG1vGa3Mr+Iwd5Ly5i1B VbZuU0TYKlIOIwqTe6c9wx+0Em4Ug+UbOJQCEOesR9KWgDJo1zr/d3WKzDBMyFI6WV BSWaDR92yG1LPRDrgP2xQTjvWGpnMaU/ea6jfyk0= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:25:09 +0300 Message-ID: <55b51679-e500-353c-d670-74e2f7697155@paragon-software.com> Date: Mon, 3 Jul 2023 11:25:08 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 2/8] fs/ntfs3: Write immediately updated ntfs state 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.138] 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 Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/fsntfs.c | 13 +++---------- =C2=A01 file changed, 3 insertions(+), 10 deletions(-) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 33afee0f5559..edb51dc12f65 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -983,18 +983,11 @@ int ntfs_set_state(struct ntfs_sb_info *sbi, enum=20 NTFS_DIRTY_FLAGS dirty) =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return err; -=C2=A0=C2=A0 =C2=A0mark_inode_dirty(&ni->vfs_inode); +=C2=A0=C2=A0 =C2=A0mark_inode_dirty_sync(&ni->vfs_inode); =C2=A0=C2=A0=C2=A0 =C2=A0/* verify(!ntfs_update_mftmirr()); */ -=C2=A0=C2=A0 =C2=A0/* -=C2=A0=C2=A0 =C2=A0 * If we used wait=3D1, sync_inode_metadata waits for t= he io for the -=C2=A0=C2=A0 =C2=A0 * inode to finish. It hangs when media is removed. -=C2=A0=C2=A0 =C2=A0 * So wait=3D0 is sent down to sync_inode_metadata -=C2=A0=C2=A0 =C2=A0 * and filemap_fdatawrite is used for the data blocks. -=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0err =3D sync_inode_metadata(&ni->vfs_inode, 0); -=C2=A0=C2=A0 =C2=A0if (!err) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D filemap_fdatawrite(ni->vfs_i= node.i_mapping); +=C2=A0=C2=A0 =C2=A0/* write mft record on disk. */ +=C2=A0=C2=A0 =C2=A0err =3D _ni_write_inode(&ni->vfs_inode, 1); =C2=A0=C2=A0=C2=A0 =C2=A0return err; =C2=A0} --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 25FBAEB64DD for ; Mon, 3 Jul 2023 07:25:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbjGCHZ5 (ORCPT ); Mon, 3 Jul 2023 03:25:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbjGCHZs (ORCPT ); Mon, 3 Jul 2023 03:25:48 -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 A5FEAE6C; Mon, 3 Jul 2023 00:25:34 -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 1F2C31D74; Mon, 3 Jul 2023 07:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368821; bh=idQe/8I4/xtf47MoCwShCKiDMRqvp0LjVacaYr6AkWU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=jqwwrq8B8R664q9ffRJjmOoR2X8CkRNU4rlXglrlwAsRvgRunVJuYY9Nzd/Serb3x wZNXxN6TabamoZsxq4gvnA44ipNC5KLs/YzKRjXVD6bnZ+qF++zZ+TN646VFIW2Hp8 g+7ng2XewnogU8vU+K6qNydqFDKkhcl9brgaeiik= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:25:32 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:25:31 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 3/8] fs/ntfs3: Minor code refactoring and formatting 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.138] 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 Trim spaces and clang-format. Add comment for mi_enum_attr. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/namei.c=C2=A0 | 2 +- =C2=A0fs/ntfs3/ntfs.h=C2=A0=C2=A0 | 2 +- =C2=A0fs/ntfs3/record.c | 6 ++++++ =C2=A0fs/ntfs3/super.c=C2=A0 | 3 +-- =C2=A0fs/ntfs3/xattr.c=C2=A0 | 3 ++- =C2=A05 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 70f8c859e0ad..dd38dbf30add 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -376,7 +376,7 @@ static int ntfs_atomic_open(struct inode *dir,=20 struct dentry *dentry, =C2=A0#ifdef CONFIG_NTFS3_FS_POSIX_ACL =C2=A0=C2=A0=C2=A0 =C2=A0if (IS_POSIXACL(dir)) { -=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 * Load in cache current acl t= o avoid ni_lock(dir): =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * ntfs_create_inode -> ntfs_i= nit_acl -> posix_acl_create -> =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * ntfs_get_acl -> ntfs_get_ac= l_ex -> ni_lock diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 98b76d1b09e7..86aecbb01a92 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -847,7 +847,7 @@ struct OBJECT_ID { =C2=A0=C2=A0=C2=A0 =C2=A0// Birth Volume Id is the Object Id of the Volume= on. =C2=A0=C2=A0=C2=A0 =C2=A0// which the Object Id was allocated. It never ch= anges. =C2=A0=C2=A0=C2=A0 =C2=A0struct GUID BirthVolumeId; //0x10: - + =C2=A0=C2=A0=C2=A0 =C2=A0// Birth Object Id is the first Object Id that was =C2=A0=C2=A0=C2=A0 =C2=A0// ever assigned to this MFT Record. I.e. If the = Object Id =C2=A0=C2=A0=C2=A0 =C2=A0// is changed for some reason, this field will re= flect the diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index c12ebffc94da..cae939cb42cf 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -189,6 +189,12 @@ int mi_read(struct mft_inode *mi, bool is_mft) =C2=A0=C2=A0=C2=A0 =C2=A0return err; =C2=A0} +/* + * mi_enum_attr - start/continue attributes enumeration in record. + * + * NOTE: mi->mrec - memory of size sbi->record_size + * here we sure that mi->mrec->total =3D=3D sbi->record_size (see mi_read) + */ =C2=A0struct ATTRIB *mi_enum_attr(struct mft_inode *mi, struct ATTRIB *att= r) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0const struct MFT_REC *rec =3D mi->mrec; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 1a02072b6b0e..d24f2da36bb2 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -488,7 +488,6 @@ static ssize_t ntfs3_label_write(struct file *file,=20 const char __user *buffer, =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0int err; =C2=A0=C2=A0=C2=A0 =C2=A0struct super_block *sb =3D pde_data(file_inode(fi= le)); -=C2=A0=C2=A0 =C2=A0struct ntfs_sb_info *sbi =3D sb->s_fs_info; =C2=A0=C2=A0=C2=A0 =C2=A0ssize_t ret =3D count; =C2=A0=C2=A0=C2=A0 =C2=A0u8 *label =3D kmalloc(count, GFP_NOFS); @@ -502,7 +501,7 @@ static ssize_t ntfs3_label_write(struct file *file,=20 const char __user *buffer, =C2=A0=C2=A0=C2=A0 =C2=A0while (ret > 0 && label[ret - 1] =3D=3D '\n') =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ret -=3D 1; -=C2=A0=C2=A0 =C2=A0err =3D ntfs_set_label(sbi, label, ret); +=C2=A0=C2=A0 =C2=A0err =3D ntfs_set_label(sb->s_fs_info, label, ret); =C2=A0=C2=A0=C2=A0 =C2=A0if (err < 0) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_err(sb, "failed (%d) to w= rite label", err); diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 1a518550c317..c59d6f5a725a 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -211,7 +211,8 @@ static ssize_t ntfs_list_ea(struct ntfs_inode *ni,=20 char *buffer, =C2=A0=C2=A0=C2=A0 =C2=A0size =3D le32_to_cpu(info->size); =C2=A0=C2=A0=C2=A0 =C2=A0/* Enumerate all xattrs. */ -=C2=A0=C2=A0 =C2=A0for (ret =3D 0, off =3D 0; off + sizeof(struct EA_FULL)= < size; off +=3D=20 ea_size) { +=C2=A0=C2=A0 =C2=A0ret =3D 0; +=C2=A0=C2=A0 =C2=A0for (off =3D 0; off + sizeof(struct EA_FULL) < size; of= f +=3D ea_size) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ea =3D Add2Ptr(ea_all, off); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ea_size =3D unpacked_ea_size(e= a); --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 B8191C0015E for ; Mon, 3 Jul 2023 07:26:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjGCH0T (ORCPT ); Mon, 3 Jul 2023 03:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjGCH0Q (ORCPT ); Mon, 3 Jul 2023 03:26:16 -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 C5638E55; Mon, 3 Jul 2023 00:26:08 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 27D1D1D74; Mon, 3 Jul 2023 07:20:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368855; bh=+eBsKb2HTBRR8iMsfkWgMdZnxlIJ4gxnl7NXRmJUV8k=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=S0F7IwFq6c40h6gaEVdITZiroO+ZvZZ7+haTDwG7SUnO9xUWQul5u8vrjXJCUI2zF c49G0p4igW/1KdgwlwzRA0U6GP0EaxMmxiZ9YTB66g9k9NaCAfXn+0e3f4Ix0J/KH0 XJZlEw2GHdOfNcWFHxLLz3BxujT5lf8W2i2kU15k= 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 970F41D1E; Mon, 3 Jul 2023 07:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369166; bh=+eBsKb2HTBRR8iMsfkWgMdZnxlIJ4gxnl7NXRmJUV8k=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ZBp5rhznk1XyJ0MlCxs6qu+hl7QD7YL6ibfUhcXAbi0M2+qxtzaQou6K/7emjY8m7 o7dCJJpvZa699JIbR2dGdDTUsfbeieG5EPhehEcBTthpzsqZDK1hmx77LtbSxWdkgp GpkZ3aiTrUf+R/FzV1q4EliIHaVDa2BpEuapv4Hk= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:26:06 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:26:05 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 4/8] fs/ntfs3: Don't allow to change label if volume is read-only 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.138] 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 Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/super.c | 7 ++++++- =C2=A01 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index d24f2da36bb2..da739e509269 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -489,7 +489,12 @@ static ssize_t ntfs3_label_write(struct file *file,=20 const char __user *buffer, =C2=A0=C2=A0=C2=A0 =C2=A0int err; =C2=A0=C2=A0=C2=A0 =C2=A0struct super_block *sb =3D pde_data(file_inode(fi= le)); =C2=A0=C2=A0=C2=A0 =C2=A0ssize_t ret =3D count; -=C2=A0=C2=A0 =C2=A0u8 *label =3D kmalloc(count, GFP_NOFS); +=C2=A0=C2=A0 =C2=A0u8 *label; + +=C2=A0=C2=A0 =C2=A0if (sb_rdonly(sb)) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EROFS; + +=C2=A0=C2=A0 =C2=A0label =3D kmalloc(count, GFP_NOFS); =C2=A0=C2=A0=C2=A0 =C2=A0if (!label) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -ENOMEM; --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 A12D9EB64DD for ; Mon, 3 Jul 2023 07:26:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjGCH0z (ORCPT ); Mon, 3 Jul 2023 03:26:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjGCH0t (ORCPT ); Mon, 3 Jul 2023 03:26:49 -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 756C9E7A; Mon, 3 Jul 2023 00:26:39 -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 134861D74; Mon, 3 Jul 2023 07:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368886; bh=vlNC3aqT1PLyINaRjLgT5dt7keaunUkuSQDjNJ9mzS8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=qF1ERGbXVCfRF81fRmeXF7le5tiNB5aw8lYBUUKRh7sxSiHitGOZ5U92gH6LVSV5N 7vVl257xtBbRv6qSnyHU5ND//ac6PFjXjLL1R3aWqyRXR8tpBn2J7V6FymwnVeVryC jlSEGvv5l4ExEpdPCuQwNhGcX53Q3gsA9XFZX2eI= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:26:37 +0300 Message-ID: <890222ac-1bd2-6817-7873-390801c5a172@paragon-software.com> Date: Mon, 3 Jul 2023 11:26:36 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 5/8] fs/ntfs3: Use kvmalloc instead of kmalloc(... __GFP_NOWARN) 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.138] 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 Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/attrlist.c | 15 +++++++++++++-- =C2=A0fs/ntfs3/bitmap.c=C2=A0=C2=A0 |=C2=A0 3 ++- =C2=A0fs/ntfs3/super.c=C2=A0=C2=A0=C2=A0 |=C2=A0 2 +- =C2=A03 files changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/attrlist.c b/fs/ntfs3/attrlist.c index 42631b31adf1..7c01735d1219 100644 --- a/fs/ntfs3/attrlist.c +++ b/fs/ntfs3/attrlist.c @@ -52,7 +52,8 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct=20 ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr->non_res) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0lsize =3D le32_to_cpu(attr->re= s.data_size); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le =3D kmalloc(al_aligned(lsize), GF= P_NOFS | __GFP_NOWARN); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* attr is resident: lsize < record_= size (1K or 4K) */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le =3D kvmalloc(al_aligned(lsize), G= FP_KERNEL); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!le) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EN= OMEM; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; @@ -80,7 +81,17 @@ int ntfs_load_attr_list(struct ntfs_inode *ni, struct=20 ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err < 0) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le =3D kmalloc(al_aligned(lsize), GF= P_NOFS | __GFP_NOWARN); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* attr is nonresident. +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * The worst case: +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * 1T (2^40) extremely fragmented fi= le. +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * cluster =3D 4K (2^12) =3D> 2^28 f= ragments +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * 2^9 fragments per one record =3D>= 2^19 records +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * 2^5 bytes of ATTR_LIST_ENTRY per = one record =3D> 2^24 bytes. +=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 result is 16M bytes per attri= bute list. +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * Use kvmalloc to allocate in range= [several Kbytes - dozen=20 Mbytes] +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le =3D kvmalloc(al_aligned(lsize), G= FP_KERNEL); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!le) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EN= OMEM; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 107e808e06ea..d66055e30aff 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -659,7 +659,8 @@ int wnd_init(struct wnd_bitmap *wnd, struct=20 super_block *sb, size_t nbits) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0wnd->bits_last =3D wbits; =C2=A0=C2=A0=C2=A0 =C2=A0wnd->free_bits =3D -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0kcalloc(wnd->nwnd, sizeof(u16), GFP_= NOFS | __GFP_NOWARN); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0kvmalloc_array(wnd->nwnd, sizeof(u16= ), GFP_KERNEL | __GFP_ZERO); + =C2=A0=C2=A0=C2=A0 =C2=A0if (!wnd->free_bits) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -ENOMEM; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index da739e509269..0034952b9ccd 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1373,7 +1373,7 @@ static int ntfs_fill_super(struct super_block *sb,=20 struct fs_context *fc) =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0bytes =3D inode->i_size; -=C2=A0=C2=A0 =C2=A0sbi->def_table =3D t =3D kmalloc(bytes, GFP_NOFS | __GF= P_NOWARN); +=C2=A0=C2=A0 =C2=A0sbi->def_table =3D t =3D kvmalloc(bytes, GFP_KERNEL); =C2=A0=C2=A0=C2=A0 =C2=A0if (!t) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -ENOMEM; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto put_inode_out; --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 D8816C0015E for ; Mon, 3 Jul 2023 07:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230457AbjGCH1w (ORCPT ); Mon, 3 Jul 2023 03:27:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbjGCH1t (ORCPT ); Mon, 3 Jul 2023 03:27:49 -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 0FE02E73; Mon, 3 Jul 2023 00:27:24 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 701271D74; Mon, 3 Jul 2023 07:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368931; bh=D5iKNYHdfTlYuVyZq7hZxLedK3pQqQ8YbD1w2/CiIkM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=CI1shzojPy5vSQ43J+xYNHD1Gzp0EmNYBN5Mogs5S3EuABT2FjWh00R7QynsARaqy L7Nmq6ppKhjiM2BncRx78NR9lx2quEERAFxeRoJLHNXG0vHRzRFzpn1MxA6fpxxEmF Am2OoGIy/JyfpI/3JZUBFO6opPSLk7uzr8jti1/g= 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 D85EF1D1E; Mon, 3 Jul 2023 07:27:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369242; bh=D5iKNYHdfTlYuVyZq7hZxLedK3pQqQ8YbD1w2/CiIkM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=QLU2NYl/jPH9ptdm9LSZC8zXlU5D+m3dcAntTbIaWBkv4YUEl+TZvLtAyrmqWMP0X 0hjnpbirOKPB6D/3tyOtJXQ1+pbGGrisCNWVvD1n6B8kiABkXs1gxVlFPbqPIB2IZE fPlsir8M7+6++8uLNS8rbBZrXuMMDSSB6h1J6jto= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:27:22 +0300 Message-ID: <18640b25-5018-ebf2-38d9-e750404cb66f@paragon-software.com> Date: Mon, 3 Jul 2023 11:27:21 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 6/8] fs/ntfs3: Add more attributes checks in mi_enum_attr() 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.138] 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 Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/record.c | 68 ++++++++++++++++++++++++++++++++++++---------= -- =C2=A01 file changed, 52 insertions(+), 16 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index cae939cb42cf..53629b1f65e9 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -199,8 +199,9 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0const struct MFT_REC *rec =3D mi->mrec; =C2=A0=C2=A0=C2=A0 =C2=A0u32 used =3D le32_to_cpu(rec->used); -=C2=A0=C2=A0 =C2=A0u32 t32, off, asize; +=C2=A0=C2=A0 =C2=A0u32 t32, off, asize, prev_type; =C2=A0=C2=A0=C2=A0 =C2=A0u16 t16; +=C2=A0=C2=A0 =C2=A0u64 data_size, alloc_size, tot_size; =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u32 total =3D le32_to_cpu(rec-= >total); @@ -219,6 +220,7 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!is_rec_inuse(rec)) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0prev_type =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr =3D Add2Ptr(rec, off); =C2=A0=C2=A0=C2=A0 =C2=A0} else { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Check if input attr inside = record. */ @@ -232,11 +234,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; =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=A0if (off + asize < off) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Overflow check= . */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Overflow check. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (off + asize < off) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0prev_type =3D le32_to_cpu(attr->type= ); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr =3D Add2Ptr(attr, asize); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0off +=3D asize; =C2=A0=C2=A0=C2=A0 =C2=A0} @@ -256,7 +258,11 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0/* 0x100 is last known attribute for now. */ =C2=A0=C2=A0=C2=A0 =C2=A0t32 =3D le32_to_cpu(attr->type); -=C2=A0=C2=A0 =C2=A0if ((t32 & 0xf) || (t32 > 0x100)) +=C2=A0=C2=A0 =C2=A0if (!t32 || (t32 & 0xf) || (t32 > 0x100)) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0/* attributes in record must be ordered by type */ +=C2=A0=C2=A0 =C2=A0if (t32 < prev_type) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; =C2=A0=C2=A0=C2=A0 =C2=A0/* Check overflow and boundary. */ @@ -265,16 +271,15 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0/* Check size of attribute. */ =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr->non_res) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Check resident fields. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (asize < SIZEOF_RESIDENT) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t16 =3D le16_to_cpu(attr->res.= data_off); - =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (t16 > asize) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t32 =3D le32_to_cpu(attr->res.data_s= ize); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (t16 + t32 > asize) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (t16 + le32_to_cpu(attr->res.data= _size) > asize) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t32 =3D sizeof(short) * attr->= name_len; @@ -284,21 +289,52 @@ struct ATTRIB *mi_enum_attr(struct mft_inode *mi,=20 struct ATTRIB *attr) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return attr; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0/* Check some nonresident fields. */ -=C2=A0=C2=A0 =C2=A0if (attr->name_len && -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 le16_to_cpu(attr->name_off) + sizeof= (short) * attr->name_len > -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 le16_to_cpu(attr-= >nres.run_off)) { +=C2=A0=C2=A0 =C2=A0/* Check nonresident fields. */ +=C2=A0=C2=A0 =C2=A0if (attr->non_res !=3D 1) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0t16 =3D le16_to_cpu(attr->nres.run_off); +=C2=A0=C2=A0 =C2=A0if (t16 > asize) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0t32 =3D sizeof(short) * attr->name_len; +=C2=A0=C2=A0 =C2=A0if (t32 && le16_to_cpu(attr->name_off) + t32 > t16) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0/* Check start/end vcn. */ +=C2=A0=C2=A0 =C2=A0if (le64_to_cpu(attr->nres.svcn) > le64_to_cpu(attr->nr= es.evcn) + 1) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0data_size =3D le64_to_cpu(attr->nres.data_size); +=C2=A0=C2=A0 =C2=A0if (le64_to_cpu(attr->nres.valid_size) > data_size) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; -=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0if (attr->nres.svcn || !is_attr_ext(attr)) { +=C2=A0=C2=A0 =C2=A0alloc_size =3D le64_to_cpu(attr->nres.alloc_size); +=C2=A0=C2=A0 =C2=A0if (data_size > alloc_size) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0t32 =3D mi->sbi->cluster_mask; +=C2=A0=C2=A0 =C2=A0if (alloc_size & t32) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0if (!attr->nres.svcn && is_attr_ext(attr)) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* First segment of sparse/compresse= d attribute */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (asize + 8 < SIZEOF_NONRESIDENT_E= X) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0tot_size =3D le64_to_cpu(attr->nres.= total_size); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (tot_size & t32) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; + +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (tot_size > alloc_size) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; +=C2=A0=C2=A0 =C2=A0} else { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (asize + 8 < SIZEOF_NONRESI= DENT) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (attr->nres.c_unit) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; -=C2=A0=C2=A0 =C2=A0} else if (asize + 8 < SIZEOF_NONRESIDENT_EX) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return NULL; +=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0return attr; =C2=A0} --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 F3C66C0015E for ; Mon, 3 Jul 2023 07:28:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjGCH2C (ORCPT ); Mon, 3 Jul 2023 03:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbjGCH17 (ORCPT ); Mon, 3 Jul 2023 03:27:59 -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 D3A58E58; Mon, 3 Jul 2023 00:27:55 -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 3066D1D21; Mon, 3 Jul 2023 07:22:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368962; bh=q5eMVDMl8OohS/5+a1OTXjwPDE7CVMtEf2hDSqPpYdc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=RjkVAo7NwjKBmWEMvIlJsB79izFMwGHGw2m5t2MLac2t2fLRc9GuLr0ri2b88NDIf hH8hwrRf88DIOVYe57oacRxXKLbO4OITZPNsbEmre3dkirQEhKAP3ewdj6gXk1mvGs 1W4Yk/9Wnnl1BzrR4wVnCieGQvtG1qTiiZLXRwIg= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:27:53 +0300 Message-ID: <23596b4e-1a38-d944-3bba-de7d528c7bf6@paragon-software.com> Date: Mon, 3 Jul 2023 11:27:52 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 7/8] fs/ntfs3: fix deadlock in mark_as_free_ex 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.138] 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 Reported-by: syzbot+e94d98936a0ed08bde43@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/fsntfs.c | 6 +++++- =C2=A01 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index edb51dc12f65..fbfe21dbb425 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -2454,10 +2454,12 @@ void mark_as_free_ex(struct ntfs_sb_info *sbi,=20 CLST lcn, CLST len, bool trim) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0CLST end, i, zone_len, zlen; =C2=A0=C2=A0=C2=A0 =C2=A0struct wnd_bitmap *wnd =3D &sbi->used.bitmap; +=C2=A0=C2=A0 =C2=A0bool dirty =3D false; =C2=A0=C2=A0=C2=A0 =C2=A0down_write_nested(&wnd->rw_lock, BITMAP_MUTEX_CLU= STERS); =C2=A0=C2=A0=C2=A0 =C2=A0if (!wnd_is_used(wnd, lcn, len)) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_set_state(sbi, NTFS_DIRTY_ERROR= ); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* mark volume as dirty out of wnd->= rw_lock */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dirty =3D true; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0end =3D lcn + len; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0len =3D 0; @@ -2511,6 +2513,8 @@ void mark_as_free_ex(struct ntfs_sb_info *sbi,=20 CLST lcn, CLST len, bool trim) =C2=A0out: =C2=A0=C2=A0=C2=A0 =C2=A0up_write(&wnd->rw_lock); +=C2=A0=C2=A0 =C2=A0if (dirty) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_set_state(sbi, NTFS_DIRTY_ERROR= ); =C2=A0} =C2=A0/* --=20 2.34.1 From nobody Sun Feb 8 06:22:24 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 DB506C0015E for ; Mon, 3 Jul 2023 07:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbjGCH2f (ORCPT ); Mon, 3 Jul 2023 03:28:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjGCH2c (ORCPT ); Mon, 3 Jul 2023 03:28:32 -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 E2A74E55; Mon, 3 Jul 2023 00:28:28 -0700 (PDT) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 94B1C1D21; Mon, 3 Jul 2023 07:23:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688368995; bh=zSbz2rcKBXxPlxirBwRjMtqYwWRIZxW3itsjx+mpDUw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=DYoyooiNxquY396tRP4PveJSv97Iv0Ubc6k8OL0qQxFCA6XV8qkchtYOOoqDY9Ra+ t7yKwtRq3jIZDDqVANBULtAwLYwL/8uGar/18pHjMuBWJwDrWjiil/HB6HfJPIKS5G FLI/MYkMXFukxZXJvtk/m+4OJcOXuR370YsZz3Ag= 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 0DE091D1E; Mon, 3 Jul 2023 07:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1688369307; bh=zSbz2rcKBXxPlxirBwRjMtqYwWRIZxW3itsjx+mpDUw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Lv+C1XgnNu8FamEESwPA7jrLynFkxB2x/2GVVnBNxkQPd5KO6vOyXEnbwYKGvxWMy QEdp3btymMdQO3l0HSsf1HdeQ+5KGzxNAQpPfAtjTFD79NrSQK+I+Y//QUVuoFJ8Hw v5bT3YcVraRNSndWCb5HxWWSgnKku9tLZ6TUgG3o= Received: from [192.168.211.138] (192.168.211.138) 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; Mon, 3 Jul 2023 10:28:26 +0300 Message-ID: Date: Mon, 3 Jul 2023 11:28:25 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PATCH 8/8] fs/ntfs3: Fix shift-out-of-bounds in ntfs_fill_super 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.138] 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 Reported-by: syzbot+478c1bf0e6bf4a8f3a04@syzkaller.appspotmail.com Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/ntfs_fs.h |=C2=A0 2 ++ =C2=A0fs/ntfs3/super.c=C2=A0=C2=A0 | 26 ++++++++++++++++++++------ =C2=A02 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 629403ede6e5..788567d71d93 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -42,9 +42,11 @@ enum utf16_endian; =C2=A0#define MINUS_ONE_T=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0((size_t)(-1)) =C2=A0/* Biggest MFT / smallest cluster */ =C2=A0#define MAXIMUM_BYTES_PER_MFT=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A04= 096 +#define MAXIMUM_SHIFT_BYTES_PER_MFT=C2=A0=C2=A0 =C2=A012 =C2=A0#define NTFS_BLOCKS_PER_MFT_RECORD=C2=A0=C2=A0 =C2=A0(MAXIMUM_BYTES_= PER_MFT / 512) =C2=A0#define MAXIMUM_BYTES_PER_INDEX=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A04096 +#define MAXIMUM_SHIFT_BYTES_PER_INDEX=C2=A0=C2=A0 =C2=A012 =C2=A0#define NTFS_BLOCKS_PER_INODE=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0(= MAXIMUM_BYTES_PER_INDEX / 512) =C2=A0/* NTFS specific error code when fixup failed. */ diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 0034952b9ccd..34ebfaa8fbab 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -905,9 +905,17 @@ static int ntfs_init_from_boot(struct super_block=20 *sb, u32 sector_size, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0sbi->record_size =3D record_size =3D -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0boot->record_size < 0 ? 1 << (-boot-= >record_size) : -=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(u32)boot->record_size << cluster_bits; +=C2=A0=C2=A0 =C2=A0if (boot->record_size >=3D 0) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0record_size =3D (u32)boot->record_si= ze << cluster_bits; +=C2=A0=C2=A0 =C2=A0} else if (-boot->record_size <=3D MAXIMUM_SHIFT_BYTES_= PER_MFT) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0record_size =3D 1u << (-boot->record= _size); +=C2=A0=C2=A0 =C2=A0} else { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_err(sb, "%s: invalid record siz= e %d.", hint, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 boot->record_siz= e); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0} + +=C2=A0=C2=A0 =C2=A0sbi->record_size =3D record_size; =C2=A0=C2=A0=C2=A0 =C2=A0sbi->record_bits =3D blksize_bits(record_size); =C2=A0=C2=A0=C2=A0 =C2=A0sbi->attr_size_tr =3D (5 * record_size >> 4); // = ~320 bytes @@ -924,9 +932,15 @@ static int ntfs_init_from_boot(struct super_block=20 *sb, u32 sector_size, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0sbi->index_size =3D boot->index_size < 0 ? -=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 1u << (-boot->index_size) : -=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 (u32)boot->index_size << cluster_bits; +=C2=A0=C2=A0 =C2=A0if (boot->index_size >=3D 0) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0sbi->index_size =3D (u32)boot->index= _size << cluster_bits; +=C2=A0=C2=A0 =C2=A0} else if (-boot->index_size <=3D MAXIMUM_SHIFT_BYTES_P= ER_INDEX) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0sbi->index_size =3D 1u << (-boot->in= dex_size); +=C2=A0=C2=A0 =C2=A0} else { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_err(sb, "%s: invalid index size= %d.", hint, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 boot->index_size= ); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0/* Check index record size. */ =C2=A0=C2=A0=C2=A0 =C2=A0if (sbi->index_size < SECTOR_SIZE ||=20 !is_power_of_2(sbi->index_size)) { --=20 2.34.1