fs/ntfs3: Fix out-of-bounds write in resident insert range
Subsystems (2)
PATCH 1/1 fs/ntfs3: Fix out-of-bounds write in resident insert range
From: Kyle Zeng <[email protected]>
attr_insert_range() grows a resident value before shifting data at and after the insertion offset. The current copy instead moves @bytes bytes from the start of the value, so both its source offset and length are wrong.
For example, inserting 2048 bytes at offset 512 in a 513-byte resident value copies 2048 bytes to data + 2048 even though the tail is only one byte long. The resulting destination can extend beyond the MFT record allocation.
Move the original tail from the insertion offset to its new location, then clear the inserted range.
--- fs/ntfs3/attrib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs3/attrib.c +3 -2
@@ -2610,8 +2610,9 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)char *data =Add2Ptr (attr_b,le16_to_cpu (attr_b->res.data_off)); -memmove (data + bytes, data, bytes); -memset (data,0 , bytes); +memmove (data + vbo + bytes, data + vbo, + data_size - vbo); +memset (data + vbo,0 , bytes); goto done; }
Signature · 1 line
2.53.0
Konstantin Komarov
maintainerQuoted 41 lines · Bruno Produit
From: Kyle Zeng <[email protected]>
attr_insert_range()grows a resident value before shifting data at and after the insertion offset. The current copy instead moves @bytes bytes from the start of the value, so both its source offset and length are wrong.For example, inserting 2048 bytes at offset 512 in a 513-byte resident value copies 2048 bytes to data + 2048 even though the tail is only one byte long. The resulting destination can extend beyond the MFT record allocation.
Move the original tail from the insertion offset to its new location, then clear the inserted range.
Fixes aa30eccb24e5 ("fs/ntfs3: Fallocate (FALLOC_FL_INSERT_RANGE) implementation")Assisted-by Codex:gpt-5.6-solSigned-off-by Kyle Zeng <[email protected]>Signed-off-by Bruno Produit <[email protected]>--- fs/ntfs3/attrib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/ntfs3/attrib.c +3
-3@@ -2610,8 +2610,9 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)char *data =Add2Ptr (attr_b,le16_to_cpu (attr_b->res.data_off)); -memmove (data + bytes, data, bytes); -memset (data,0 , bytes); +memmove (data + vbo + bytes, data + vbo, + data_size - vbo); +memset (data + vbo,0 , bytes); goto done; } --
Quoted 1 line
2.53.0
Hello,
Thanks for the patch. Alon Shakevsky previously submitted the same fix in "ntfs3: fix INSERT_RANGE for resident data".
Regards,
Konstantin