From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: Xue Boyang <fuchen.dust@gmail.com>
Cc: <ntfs3@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH ntfs] fs/ntfs3: fix slab-out-of-bounds write in index buffer replay
Date: Wed, 2 Dec 2026 11:42:17 +0100 [thread overview]
Message-ID: <4316f348-a202-4b79-874f-c1d7a8b1fb0c@paragon-software.com> (raw)
In-Reply-To: <20260929122500.362486-1-fuchen.dust@gmail.com>
On 9/29/26 14:25, Xue Boyang wrote:
> During $LogFile replay, the allocation-op preamble in do_action()
> computes the buffer size as:
>
> bytes = max(oe->bytes_per_index, lcns_follow << cluster_bits);
> bytes += roff;
> bytes = ALIGN(bytes, 512);
> buffer_le = kmalloc(bytes, GFP_NOFS);
>
> and then sets ib = buffer_le + roff, so the index buffer starts roff
> bytes into the allocation. However, all six allocation cases pass the
> FULL allocation size to check_index_buffer() and
> ntfs_fix_pre_write() instead of the space actually available behind ib
> (bytes - roff):
>
> check_index_buffer(ib, bytes) // validates entries up to ib+bytes
> ntfs_fix_pre_write(&ib->rhdr, bytes) // writes fixups up to ib+bytes-2
>
> This lets check_index_buffer() approve entries that extend roff bytes
> past the end of the kmalloc() allocation, and makes
> ntfs_fix_pre_write() write the last USA fixup at ib + bytes - 2, which
> is roff - 2 bytes past the allocation.
>
> Reproduced deterministically on rw mount of a crafted $LogFile with
> oe->bytes_per_index = 2560 and record_off = 1536 (bytes = 4096,
> ib = buffer_le + 1536, available = 2560). The USA fixup write at
> ib + 4094 = buffer_le + 5630 runs 1534 bytes past the 4096-byte
> allocation:
>
> BUG: KASAN: slab-out-of-bounds in ntfs_fix_pre_write+0xb4/0x100
> Read of size 2 at addr ffff8880044891fe by task mount/70
> ...
> ntfs_fix_pre_write+0xb4/0x100
> do_action+0x1c67/0x1e09
> log_replay (fs/ntfs3/fslog.c)
> ntfs_loadlog_and_replay+0x2cb/0x300
> ntfs_fill_super+0x1375/0x22d0
> ...
>
> Pass bytes - roff (the space behind ib) to both functions, matching
> the intended semantics when roff is nonzero. With roff = 0 the
> argument is unchanged.
>
> Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
> Assisted-by: GLM:zhipu-coding-plan/glm-5.3
> Signed-off-by: Xue Boyang <fuchen.dust@gmail.com>
> ---
> fs/ntfs3/fslog.c | 24 ++++++++++++------------
> 1 file changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
> index ba61767cab3f..4b83a21532a3 100644
> --- a/fs/ntfs3/fslog.c
> +++ b/fs/ntfs3/fslog.c
> @@ -3624,7 +3624,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> used = le32_to_cpu(hdr->used);
>
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff) ||
> Add2Ptr(e, esize) > Add2Ptr(lrh, rec_len) ||
> used + esize > le32_to_cpu(hdr->total)) {
> @@ -3639,7 +3639,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> a_dirty = true;
>
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> case DeleteIndexEntryAllocation:
> @@ -3653,7 +3653,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> if (!check_lsn(&ib->rhdr, rlsn))
> goto out;
>
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff)) {
> goto dirty_vol;
> }
> @@ -3682,7 +3682,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> a_dirty = true;
>
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> case WriteEndOfIndexBuffer:
> @@ -3694,7 +3694,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> goto dirty_vol;
> if (!check_lsn(&ib->rhdr, rlsn))
> goto out;
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff) ||
> aoff + dlen > offsetof(struct INDEX_BUFFER, ihdr) +
> le32_to_cpu(hdr->total)) {
> @@ -3705,7 +3705,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> memmove(e, data, dlen);
>
> a_dirty = true;
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> case SetIndexEntryVcnAllocation:
> @@ -3718,7 +3718,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> if (!check_lsn(&ib->rhdr, rlsn))
> goto out;
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff)) {
> goto dirty_vol;
> }
> @@ -3726,7 +3726,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> de_set_vbn_le(e, *(__le64 *)data);
>
> a_dirty = true;
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> case UpdateFileNameAllocation:
> @@ -3739,7 +3739,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> if (!check_lsn(&ib->rhdr, rlsn))
> goto out;
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff)) {
> goto dirty_vol;
> }
> @@ -3750,7 +3750,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> memmove(&fname->dup, data, sizeof(fname->dup));
>
> a_dirty = true;
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> case SetBitsInNonresidentBitMap:
> @@ -3789,7 +3789,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
>
> if (!check_lsn(&ib->rhdr, rlsn))
> goto out;
> - if (!check_index_buffer(ib, bytes) ||
> + if (!check_index_buffer(ib, bytes - roff) ||
> !check_if_alloc_index(hdr, aoff)) {
> goto dirty_vol;
> }
> @@ -3802,7 +3802,7 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
> memmove(Add2Ptr(e, le16_to_cpu(e->view.data_off)), data, dlen);
>
> a_dirty = true;
> - ntfs_fix_pre_write(&ib->rhdr, bytes);
> + ntfs_fix_pre_write(&ib->rhdr, bytes - roff);
> break;
>
> default:
> --
> 2.53.0
Hello,
The patch is applied, thank you.
Regards,
Konstantin
prev parent reply other threads:[~2026-12-02 10:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 12:25 Xue Boyang
2026-12-02 10:42 ` Konstantin Komarov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4316f348-a202-4b79-874f-c1d7a8b1fb0c@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=fuchen.dust@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®