From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=35.157.23.187 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208141; b=1JD6aedZF9jwJsQVSA/MhnTWPu8rs7uZ+LFEu2mk3cpvdmVNNwNzANJ5OO0a5unDE0c3 AgkXVHO7Dma0YDHDDXMLRE4zknb5PlMgXiWblJUnaSJOEfj27CuyjdULfiC5eFB7LKyjQ N9RRM/hTW/dc2zhhbLQvrEqkauvIL9KKJ0PIme3XqOAUmAva4UHQFoxmIEOxvQCFt+/ut nFYhS/x/ThpEwBIAym0zC39G/04wGU74+K3aC/E96WnAoStbO5uRtsFqs28nzx7WwKZo1 qIbU8pXDQO6fkHNDbFtZJdJcRdVhswF0LjIdAystpz2NdoOsZiMVgktA2fr0N2fc28w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208141; h=DMARC-Filter:Received:Received:DKIM-Signature:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:CC:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; bh=4mp4M2PVrJah+lMw/t1HfzWeHl5aamObx1OGAzh6MYE=; b=ARNUuAfid+UczZnRtzVM440F+htxNiOfut2GJKLfonGKz8fEdjowdheRXPAi5UMl6j+q 7oKttco5nNt+6IlZbVvNOJoNK+ReKaGEoLhCYEmuGauOmZj/iL+pCK/cnYxguWfn0BTba wn2Zm1obKNT4GmEbE95RBolDFw7wWaSnduQlt+6zwgyaor29o3DDyYPoWPDCUp9QbncYV oYuacLHIyzsbAjecwwfEOG9bRZnPfo+D7y3XWRhP1JvgIZ6UUpHdtFpzG3pv7XKxnbPCk VAlpOJHSBmOn9j3TPrQFS2T22x0EPEvr0KzLpbgclGSxLC/n/hdgqk4+BB1HdDlxwOw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass header.d=paragon-software.com header.i=@paragon-software.com header.a=rsa-sha256 header.s=mail header.b=GR6WP9WI; arc=none smtp.remote-ip=35.157.23.187 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4F660606A336 for ; Wed, 2 Dec 2026 10:42:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4F660606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.a=rsa-sha256 header.s=mail header.b=GR6WP9WI Received: from relayfre-01.paragon-software.com (relayfre-01.paragon-software.com [176.12.100.13]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 2ECF71D1C; Wed, 2 Dec 2026 10:42:59 +0000 (UTC) Authentication-Results: relayaws-01.paragon-software.com; dkim=pass (1024-bit key; unprotected) header.d=paragon-software.com header.i=@paragon-software.com header.b=GR6WP9WI; dkim-atps=neutral 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 8043A1FDF; Wed, 2 Dec 2026 10:42:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1796208138; bh=4mp4M2PVrJah+lMw/t1HfzWeHl5aamObx1OGAzh6MYE=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=GR6WP9WIfLhYq/CJcg9Fn47rp2lgieHJiCtF4MRBHMh6Z66ZTRlu7zSlAyIiV9qdd 5wYCaBXHMX/SqgAxJSGPmbghoLdB+y6oPf/kgV+uwcweEXr4IhFZ3rOhBKoYy2TPiL GbIPNYj26o6oy5+ipL1QxuwcI/Twv7nrNGqrUsNc= Received: from [192.168.95.128] (192.168.211.24) 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; Wed, 2 Dec 2026 13:42:18 +0300 Message-ID: <4316f348-a202-4b79-874f-c1d7a8b1fb0c@paragon-software.com> Date: Wed, 2 Dec 2026 11:42:17 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH ntfs] fs/ntfs3: fix slab-out-of-bounds write in index buffer replay To: Xue Boyang CC: , References: <20260929122500.362486-1-fuchen.dust@gmail.com> Content-Language: en-US From: Konstantin Komarov In-Reply-To: <20260929122500.362486-1-fuchen.dust@gmail.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) 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 > --- > 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