diff options
| author | Wahid Khan <wahidzk0091@gmail.com> | 2026-11-14 13:04:51 +0530 |
|---|---|---|
| committer | Namjae Jeon <linkinjeon@kernel.org> | 2026-11-21 21:05:20 +0900 |
| commit | ea04295b4f1f4c40b955e85f432ddde72f659ee3 (patch) | |
| tree | dc7c2b19aef959f5616da531be737e1c32af8633 /tools/lib/python | |
| parent | 136760737a7659518e5aaa17b2630246ad0b7f33 (diff) | |
ntfs: convert a named $DATA stream safely when making room in a record
When an attribute has to grow and the mft record is full,
ntfs_resident_attr_resize() walks the other resident attributes and
converts them to non-resident ones. For $DATA it always opens the
unnamed data inode of the base inode, even if the attribute found is a
named stream:
tvi = ntfs_iget(sb, base_ni->mft_no);
ntfs_attr_make_non_resident(NTFS_I(tvi), value_len);
value_len is the length of the stream, so it does not match the
attribute that ntfs_attr_make_non_resident() looks up for the unnamed
inode, and the WARN_ON() on entry fires:
WARNING: fs/ntfs/attrib.c:2115 at ntfs_attr_make_non_resident
ntfs_resident_attr_resize
ntfs_attr_expand_locked
ntfs_expand_for_write
ntfs_file_write_iter
vfs_write
It does not need a damaged volume. A file with an alternate data stream
whose record has no room left is enough.
Open a named stream by name with ntfs_attr_iget(), as is done for the
other attribute types in this loop, and keep ntfs_iget() for the
unnamed one. The loop runs with the mft record lock held and takes no
lock of the stream inode, so converting a stream from here needs more
care than the plain lookup gives:
- A reader of the stream holds the folio lock and then takes the mft
record lock in ntfs_read_iomap_begin_resident(), the conversion takes
them the other way round and waits for folio 0. Take the folio with
FGP_NOWAIT in this loop and skip the attribute if it is busy. The loop
only tries to free space. The same inversion exists for the conversion
of the attribute being resized, which waited for folio 0 with the lock
held and hangs against an mmap fault or splice reader. Use FGP_NOWAIT
there too. The resize then fails with -EBUSY while such a reader is
stuck on the lock, instead of hanging.
Do not look for room in other attributes either: the reader keeps the
folio until the lock is dropped, so the attribute can neither be
converted nor written without waiting for it, and the loop would only
convert other attributes for nothing.
FGP_NOWAIT also fails when the folio can not be allocated, so on
failure look the folio up: only one that is there means a busy folio,
otherwise return -ENOMEM.
- A stream that is in the inode cache can be open, being written, being
removed or already unlinked. A write that passed its residency check
before the conversion carries on with a non-resident attribute, and
a stream in the middle of ntfs_stream_finish_remove() is converted
under its feet. Convert only a stream that is not cached.
- An attribute inode of a file that has no links left is evicted on the
last iput() with its dirty folio, so what was converted is lost and
an open file reads its extended attributes back as missing. Convert
nothing, of any type, in a file that is being deleted or has no links
left.
- The unnamed data is converted through the file's own inode, whose
i_rwsem only a resize of the unnamed data itself holds. When a stream
or an extended attribute is being resized, a writer of the file can
have passed its residency check and carry on with a non-resident
attribute (iomap_iter warnings, recursive mrec_lock). When the
unnamed data is the attribute being resized, its conversion was just
tried by the caller. Do not convert the unnamed data from this loop.
- Do not convert the attribute that is being resized either. Its
conversion was just tried and failed, for instance on a busy folio,
and a second try that succeeds leaves the resize to go on with the
resident layout of a record that is now non-resident.
- The lookup of a stream ignores case, so a stream whose name differs
only in case from an earlier one resolves to that one and the length
does not match again. Compare the names exactly.
Fixes: 495e90fa3348 ("ntfs: update attrib operations")
Cc: stable@vger.kernel.org # v7.1+
Signed-off-by: Wahid Khan <wahidzk0091@gmail.com>
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
