* ntfs: deleting $Extend breaks subsequent mount
@ 2026-11-23 20:01 theBIT5 x3zk
2026-11-24 1:40 ` Namjae Jeon
0 siblings, 1 reply; 5+ messages in thread
From: theBIT5 x3zk @ 2026-11-23 20:01 UTC (permalink / raw)
To: linkinjeon; +Cc: linux-fsdevel, linux-kernel
Hi,
Was messing around with the new ntfs driver (fs/ntfs) on 7.4.0-rc3-1-mainline
and noticed you can just rm -rf '$Extend' even without show_sys_files.
After umount, the filesystem fails to mount again.
Steps:
# mount -t ntfs /root/ntfs.img /mnt -o loop
# cd /mnt
# ls '$Extend'
'$ObjId' '$Quota' '$Reparse'
# rm -rf '$Extend'
# cd /
# umount /mnt
# mount -t ntfs /root/ntfs.img /mnt -o loop
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error.
dmesg:
ntfs: volume version 3.1, dev loop0, cluster size 4096
ntfs: (device loop0): load_system_files(): Failed to load $Extend.
ntfs: (device loop0): ntfs_fill_super(): Failed to load system files (-22).
--
theBIT5
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: ntfs: deleting $Extend breaks subsequent mount 2026-11-23 20:01 ntfs: deleting $Extend breaks subsequent mount theBIT5 x3zk @ 2026-11-24 1:40 ` Namjae Jeon 2026-11-24 7:08 ` liubaolin 0 siblings, 1 reply; 5+ messages in thread From: Namjae Jeon @ 2026-11-24 1:40 UTC (permalink / raw) To: theBIT5 x3zk Cc: linux-fsdevel, linux-kernel, open list:NTFS FILESYSTEM, Hyunchul Lee, Baolin Liu, Baolin Liu [-- Attachment #1: Type: text/plain, Size: 938 bytes --] On Tue, Nov 24, 2026 at 5:01 AM theBIT5 x3zk <x3zk@outlook.com> wrote: > > Hi, Hi, > > Was messing around with the new ntfs driver (fs/ntfs) on 7.4.0-rc3-1-mainline > and noticed you can just rm -rf '$Extend' even without show_sys_files. > After umount, the filesystem fails to mount again. > > Steps: > > # mount -t ntfs /root/ntfs.img /mnt -o loop > # cd /mnt > # ls '$Extend' > '$ObjId' '$Quota' '$Reparse' > # rm -rf '$Extend' > # cd / > # umount /mnt > # mount -t ntfs /root/ntfs.img /mnt -o loop > mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0, > missing codepage or helper program, or other error. > > dmesg: > ntfs: volume version 3.1, dev loop0, cluster size 4096 > ntfs: (device loop0): load_system_files(): Failed to load $Extend. > ntfs: (device loop0): ntfs_fill_super(): Failed to load system files (-22). Please check the attached patch. Thanks for the report. [-- Attachment #2: 0001-ntfs-prevent-modification-of-Extend-system-metadata.patch --] [-- Type: text/x-patch, Size: 3562 bytes --] From 00d5fceb3b8076d937a64764ee663b40445b402d Mon Sep 17 00:00:00 2001 From: Namjae Jeon <linkinjeon@kernel.org> Date: Tue, 24 Nov 2026 10:23:42 +0900 Subject: [PATCH] ntfs: prevent modification of $Extend system metadata The $Extend directory contains system files such as $ObjId, $Quota, and $Reparse. show_sys_files only controls directory enumeration, so hidden system metadata remains reachable by explicit path. The forced immutability policy skips directories and does not protect $Extend entries, allowing rm -rf '$Extend' to remove them and make later mounts fail when load_system_files() opens FILE_Extend. Make FILE_Extend and system files recognized in $Extend immutable independently of sys_immutable. This prevents namespace changes beneath $Extend and direct VFS writes to its system-file inodes. Fixes: f72df3a4c33b ("ntfs: make system files immutable to prevent corruption") Reported-by: theBIT5 x3zk <x3zk@outlook.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org> --- fs/ntfs/file.c | 4 +++- fs/ntfs/inode.c | 11 +++++++---- fs/ntfs/inode.h | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 7d93a520566e..48d1b13b7e18 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -182,7 +182,9 @@ static bool ntfs_is_forced_immutable(struct inode *vi) { struct ntfs_inode *ni = NTFS_I(vi); - if (ni->mft_no < FILE_first_user && S_ISREG(vi->i_mode)) + if (NInoExtendSys(ni) || + ni->mft_no == FILE_Extend || + (ni->mft_no < FILE_first_user && S_ISREG(vi->i_mode))) return true; return NVolSysImmutable(ni->vol) && diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 4fbdcd459652..9df6dca10e17 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -1164,6 +1164,7 @@ static int ntfs_read_locked_inode(struct inode *vi) */ extend_sys = ntfs_is_extended_system_file(ctx); if (extend_sys > 0) { + NInoSetExtendSys(ni); if (m->flags & MFT_RECORD_IS_VIEW_INDEX) { if (extend_sys == 2) { name = reparse_index_name; @@ -1307,11 +1308,13 @@ static int ntfs_read_locked_inode(struct inode *vi) /* * System files such as $Bitmap and $MFT are maintained by the driver - * itself, and writing them from userspace corrupts the volume. - * Always make them immutable regardless of the sys_immutable option. - * Directories are skipped so the root and $Extend stay usable. + * itself. Always make them immutable regardless of the sys_immutable + * option. Protect $Extend and its system files too; modifying them + * through the VFS can corrupt NTFS metadata. */ - if (ni->mft_no < FILE_first_user && S_ISREG(vi->i_mode)) + if (NInoExtendSys(ni) || + ni->mft_no == FILE_Extend || + (ni->mft_no < FILE_first_user && S_ISREG(vi->i_mode))) vi->i_flags |= S_IMMUTABLE; /* diff --git a/fs/ntfs/inode.h b/fs/ntfs/inode.h index 7ea52c59c04b..8c1929bebe44 100644 --- a/fs/ntfs/inode.h +++ b/fs/ntfs/inode.h @@ -182,6 +182,7 @@ struct ntfs_inode { * NI_HasEA ntfs inode has EA attribute. * NI_RunlistDirty runlist need to be updated. * NI_StreamUnlinked Named stream is unlinked but still open. + * NI_ExtendSys Inode is a system file in $Extend. */ enum { NI_Dirty, @@ -204,6 +205,7 @@ enum { NI_HasEA, NI_RunlistDirty, NI_StreamUnlinked, + NI_ExtendSys, }; /* @@ -265,6 +267,7 @@ NINO_FNS(BeingDeleted) NINO_FNS(HasEA) NINO_FNS(RunlistDirty) NINO_FNS(StreamUnlinked) +NINO_FNS(ExtendSys) /* * The full structure containing a ntfs_inode and a vfs struct inode. Used for -- 2.34.1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ntfs: deleting $Extend breaks subsequent mount 2026-11-24 1:40 ` Namjae Jeon @ 2026-11-24 7:08 ` liubaolin 2026-11-24 17:20 ` theBIT5 x3zk 0 siblings, 1 reply; 5+ messages in thread From: liubaolin @ 2026-11-24 7:08 UTC (permalink / raw) To: Namjae Jeon, theBIT5 x3zk Cc: linux-fsdevel, linux-kernel, open list:NTFS FILESYSTEM, Hyunchul Lee, Baolin Liu 在 2026/11/24 09:40, Namjae Jeon 写道: > On Tue, Nov 24, 2026 at 5:01 AM theBIT5 x3zk <x3zk@outlook.com> wrote: >> >> Hi, > Hi, >> >> Was messing around with the new ntfs driver (fs/ntfs) on 7.4.0-rc3-1-mainline >> and noticed you can just rm -rf '$Extend' even without show_sys_files. >> After umount, the filesystem fails to mount again. >> >> Steps: >> >> # mount -t ntfs /root/ntfs.img /mnt -o loop >> # cd /mnt >> # ls '$Extend' >> '$ObjId' '$Quota' '$Reparse' >> # rm -rf '$Extend' >> # cd / >> # umount /mnt >> # mount -t ntfs /root/ntfs.img /mnt -o loop >> mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0, >> missing codepage or helper program, or other error. >> >> dmesg: >> ntfs: volume version 3.1, dev loop0, cluster size 4096 >> ntfs: (device loop0): load_system_files(): Failed to load $Extend. >> ntfs: (device loop0): ntfs_fill_super(): Failed to load system files (-22). > Please check the attached patch. > Thanks for the report. Hi Namjae, I noticed that NInoSetExtendSys() is only reached when looking up the unnamed $DATA attribute returns -ENOENT. A file directly under $Extend that has an unnamed $DATA attribute skips this path and never gets NI_ExtendSys set, leaving it mutable without sys_immutable. I reproduced this with your patch applied, using default mount options and a synthetic NTFS image containing a SYSTEM-marked file with unnamed $DATA directly under $Extend. After remounting, this write still succeeds: echo changed > '/mnt/$Extend/review-data' Could we move the direct-child classification into the common inode-loading path, so that setting NI_ExtendSys does not depend on whether the unnamed $DATA attribute exists? I tested the change below in QEMU. The write above is now rejected with EPERM, and normal file, hard-link, symlink and remount checks pass. Thanks, Baolin You may consider applying the following change on top of your attached patch: ************************************************************************** diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index e1c5a767e62b..c0e2535401bb 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -959,6 +959,15 @@ static int ntfs_read_locked_inode(struct inode *vi) goto unm_err_out; } + /* Classify $Extend children regardless of their data/index layout. */ + if (ni->mft_no >= FILE_first_user) { + err = ntfs_is_extended_system_file(ctx); + if (err < 0) + goto unm_err_out; + if (err > 0) + NInoSetExtendSys(ni); + } + if (ni->flags & FILE_ATTR_REPARSE_POINT) { unsigned int mode; @@ -1163,7 +1172,6 @@ static int ntfs_read_locked_inode(struct inode *vi) */ extend_sys = ntfs_is_extended_system_file(ctx); if (extend_sys > 0) { - NInoSetExtendSys(ni); if (m->flags & MFT_RECORD_IS_VIEW_INDEX) { if (extend_sys == 2) { name = reparse_index_name; ^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: ntfs: deleting $Extend breaks subsequent mount 2026-11-24 7:08 ` liubaolin @ 2026-11-24 17:20 ` theBIT5 x3zk 2026-11-25 3:18 ` liubaolin 0 siblings, 1 reply; 5+ messages in thread From: theBIT5 x3zk @ 2026-11-24 17:20 UTC (permalink / raw) To: liubaolin, Namjae Jeon Cc: linux-fsdevel, linux-kernel, open list:NTFS FILESYSTEM, Hyunchul Lee, Baolin Liu Hi, Built 7.4.0-rc4 with both patches applied and ran basic checks. Deleting '$Extend', creating files inside it, and writing to its system files now all fail with Operation not permitted, and remounting works: # mount -t ntfs /root/ntfs.img /mnt -o loop # cd /mnt # rm -fr '$Extend' rm: cannot remove '$Extend/$ObjId': Operation not permitted rm: cannot remove '$Extend/$Quota': Operation not permitted rm: cannot remove '$Extend/$Reparse': Operation not permitted # cd '$Extend' # touch file touch: cannot touch 'file': Operation not permitted # cat /dev/null > '$ObjId' warning: An error occurred while redirecting file '$ObjId' open: Operation not permitted # cat /dev/null > '$Quota' warning: An error occurred while redirecting file '$Quota' open: Operation not permitted # cat /dev/null > '$Reparse' warning: An error occurred while redirecting file '$Reparse' open: Operation not permitted Tested-by: theBIT5 x3zk <x3zk@outlook.com> ________________________________________ От: liubaolin <liubaolin12138@163.com> Отправлено: 24 ноября 2026 г. 10:08 Кому: Namjae Jeon; theBIT5 x3zk Копия: linux-fsdevel@vger.kernel.org; linux-kernel@vger.kernel.org; open list:NTFS FILESYSTEM; Hyunchul Lee; Baolin Liu Тема: Re: ntfs: deleting $Extend breaks subsequent mount 在 2026/11/24 09:40, Namjae Jeon 写道: > On Tue, Nov 24, 2026 at 5:01 AM theBIT5 x3zk <x3zk@outlook.com> wrote: >> >> Hi, > Hi, >> >> Was messing around with the new ntfs driver (fs/ntfs) on 7.4.0-rc3-1-mainline >> and noticed you can just rm -rf '$Extend' even without show_sys_files. >> After umount, the filesystem fails to mount again. >> >> Steps: >> >> # mount -t ntfs /root/ntfs.img /mnt -o loop >> # cd /mnt >> # ls '$Extend' >> '$ObjId' '$Quota' '$Reparse' >> # rm -rf '$Extend' >> # cd / >> # umount /mnt >> # mount -t ntfs /root/ntfs.img /mnt -o loop >> mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0, >> missing codepage or helper program, or other error. >> >> dmesg: >> ntfs: volume version 3.1, dev loop0, cluster size 4096 >> ntfs: (device loop0): load_system_files(): Failed to load $Extend. >> ntfs: (device loop0): ntfs_fill_super(): Failed to load system files (-22). > Please check the attached patch. > Thanks for the report. Hi Namjae, I noticed that NInoSetExtendSys() is only reached when looking up the unnamed $DATA attribute returns -ENOENT. A file directly under $Extend that has an unnamed $DATA attribute skips this path and never gets NI_ExtendSys set, leaving it mutable without sys_immutable. I reproduced this with your patch applied, using default mount options and a synthetic NTFS image containing a SYSTEM-marked file with unnamed $DATA directly under $Extend. After remounting, this write still succeeds: echo changed > '/mnt/$Extend/review-data' Could we move the direct-child classification into the common inode-loading path, so that setting NI_ExtendSys does not depend on whether the unnamed $DATA attribute exists? I tested the change below in QEMU. The write above is now rejected with EPERM, and normal file, hard-link, symlink and remount checks pass. Thanks, Baolin You may consider applying the following change on top of your attached patch: ************************************************************************** diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index e1c5a767e62b..c0e2535401bb 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -959,6 +959,15 @@ static int ntfs_read_locked_inode(struct inode *vi) goto unm_err_out; } + /* Classify $Extend children regardless of their data/index layout. */ + if (ni->mft_no >= FILE_first_user) { + err = ntfs_is_extended_system_file(ctx); + if (err < 0) + goto unm_err_out; + if (err > 0) + NInoSetExtendSys(ni); + } + if (ni->flags & FILE_ATTR_REPARSE_POINT) { unsigned int mode; @@ -1163,7 +1172,6 @@ static int ntfs_read_locked_inode(struct inode *vi) */ extend_sys = ntfs_is_extended_system_file(ctx); if (extend_sys > 0) { - NInoSetExtendSys(ni); if (m->flags & MFT_RECORD_IS_VIEW_INDEX) { if (extend_sys == 2) { name = reparse_index_name; ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: ntfs: deleting $Extend breaks subsequent mount 2026-11-24 17:20 ` theBIT5 x3zk @ 2026-11-25 3:18 ` liubaolin 0 siblings, 0 replies; 5+ messages in thread From: liubaolin @ 2026-11-25 3:18 UTC (permalink / raw) To: theBIT5 x3zk, Namjae Jeon Cc: linux-fsdevel, linux-kernel, open list:NTFS FILESYSTEM, Hyunchul Lee, Baolin Liu 在 2026/11/25 01:20, theBIT5 x3zk 写道: > Hi, > > Built 7.4.0-rc4 with both patches applied and ran basic checks. > Deleting '$Extend', creating files inside it, and writing to its system > files now all fail with Operation not permitted, and remounting works: > > # mount -t ntfs /root/ntfs.img /mnt -o loop > # cd /mnt > # rm -fr '$Extend' > rm: cannot remove '$Extend/$ObjId': Operation not permitted > rm: cannot remove '$Extend/$Quota': Operation not permitted > rm: cannot remove '$Extend/$Reparse': Operation not permitted > # cd '$Extend' > # touch file > touch: cannot touch 'file': Operation not permitted > # cat /dev/null > '$ObjId' > warning: An error occurred while redirecting file '$ObjId' > open: Operation not permitted > # cat /dev/null > '$Quota' > warning: An error occurred while redirecting file '$Quota' > open: Operation not permitted > # cat /dev/null > '$Reparse' > warning: An error occurred while redirecting file '$Reparse' > open: Operation not permitted > > Tested-by: theBIT5 x3zk <x3zk@outlook.com> Thanks for testing and confirming > > ________________________________________ > От: liubaolin <liubaolin12138@163.com> > Отправлено: 24 ноября 2026 г. 10:08 > Кому: Namjae Jeon; theBIT5 x3zk > Копия: linux-fsdevel@vger.kernel.org; linux-kernel@vger.kernel.org; open list:NTFS FILESYSTEM; Hyunchul Lee; Baolin Liu > Тема: Re: ntfs: deleting $Extend breaks subsequent mount > > > > 在 2026/11/24 09:40, Namjae Jeon 写道: >> On Tue, Nov 24, 2026 at 5:01 AM theBIT5 x3zk <x3zk@outlook.com> wrote: >>> >>> Hi, >> Hi, >>> >>> Was messing around with the new ntfs driver (fs/ntfs) on 7.4.0-rc3-1-mainline >>> and noticed you can just rm -rf '$Extend' even without show_sys_files. >>> After umount, the filesystem fails to mount again. >>> >>> Steps: >>> >>> # mount -t ntfs /root/ntfs.img /mnt -o loop >>> # cd /mnt >>> # ls '$Extend' >>> '$ObjId' '$Quota' '$Reparse' >>> # rm -rf '$Extend' >>> # cd / >>> # umount /mnt >>> # mount -t ntfs /root/ntfs.img /mnt -o loop >>> mount: /mnt: wrong fs type, bad option, bad superblock on /dev/loop0, >>> missing codepage or helper program, or other error. >>> >>> dmesg: >>> ntfs: volume version 3.1, dev loop0, cluster size 4096 >>> ntfs: (device loop0): load_system_files(): Failed to load $Extend. >>> ntfs: (device loop0): ntfs_fill_super(): Failed to load system files (-22). >> Please check the attached patch. >> Thanks for the report. > > Hi Namjae, > I noticed that NInoSetExtendSys() is only reached when looking up the > unnamed $DATA attribute returns -ENOENT. A file directly under $Extend > that has an unnamed $DATA attribute skips this path and never gets > NI_ExtendSys set, leaving it mutable without sys_immutable. > > I reproduced this with your patch applied, using default mount options > and a synthetic NTFS image containing a SYSTEM-marked file with unnamed > $DATA directly under $Extend. After remounting, this write still succeeds: > echo changed > '/mnt/$Extend/review-data' > > Could we move the direct-child classification into the common > inode-loading path, so that setting NI_ExtendSys does not depend on > whether the unnamed $DATA attribute exists? > I tested the change below in QEMU. The write above is now rejected > with EPERM, and normal file, hard-link, symlink and remount checks pass. > > Thanks, > Baolin > > You may consider applying the following change on top of your attached > patch: > ************************************************************************** > diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c > index e1c5a767e62b..c0e2535401bb 100644 > --- a/fs/ntfs/inode.c > +++ b/fs/ntfs/inode.c > @@ -959,6 +959,15 @@ static int ntfs_read_locked_inode(struct inode *vi) > goto unm_err_out; > } > > + /* Classify $Extend children regardless of their data/index > layout. */ > + if (ni->mft_no >= FILE_first_user) { > + err = ntfs_is_extended_system_file(ctx); > + if (err < 0) > + goto unm_err_out; > + if (err > 0) > + NInoSetExtendSys(ni); > + } > + > if (ni->flags & FILE_ATTR_REPARSE_POINT) { > unsigned int mode; > > @@ -1163,7 +1172,6 @@ static int ntfs_read_locked_inode(struct inode *vi) > */ > extend_sys = ntfs_is_extended_system_file(ctx); > if (extend_sys > 0) { > - NInoSetExtendSys(ni); > if (m->flags & MFT_RECORD_IS_VIEW_INDEX) { > if (extend_sys == 2) { > name = reparse_index_name; ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-25 3:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2026-11-23 20:01 ntfs: deleting $Extend breaks subsequent mount theBIT5 x3zk 2026-11-24 1:40 ` Namjae Jeon 2026-11-24 7:08 ` liubaolin 2026-11-24 17:20 ` theBIT5 x3zk 2026-11-25 3:18 ` liubaolin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®