From: Roman Demidov <roman.demidov.nn@gmail.com>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: Roman Demidov <roman.demidov.nn@gmail.com>,
John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>,
Yangtao Li <frank.li@vivo.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] hfs: fix slab-out-of-bounds in __hfs_ext_write_extent
Date: Wed, 9 Sep 2026 12:59:25 +0300 [thread overview]
Message-ID: <20260909095930.19979-1-roman.demidov.nn@gmail.com> (raw)
The function __hfs_ext_write_extent() writes extent data to the B-tree
node using the length fd->entrylength obtained from the on-disk HFS
record without validation. This length can be larger than the actual
source buffer HFS_I(inode)->cached_extents (which is only 12 bytes,
the size of hfs_extent_rec). An attacker can craft a malicious HFS
image and mount it locally, then trigger a writeback by truncating
a file, causing the kernel to read beyond the cached_extents buffer
and leak up to 84 bytes of kernel memory into the image.
Although CVE-2025-38715 addressed similar out-of-bounds issues in the
read path and added bounds checks in hfs_bnode_write(), those checks
only verify that the write stays within the B-tree node boundaries.
A 96-byte write still fits within a typical node, so the overflow
persists in the write path.
Fix this by adding a validation in __hfs_ext_write_extent() that rejects
any write where fd->entrylength does not equal sizeof(hfs_extent_rec).
This is consistent with the existing check in the read path.
Fixes: a431930c9bac ("hfs: fix slab-out-of-bounds in hfs_bnode_read()")
Signed-off-by: Roman Demidov <roman.demidov.nn@gmail.com>
---
fs/hfs/extent.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/hfs/extent.c b/fs/hfs/extent.c
index 580c62981dbd..b588410f01c7 100644
--- a/fs/hfs/extent.c
+++ b/fs/hfs/extent.c
@@ -126,6 +126,8 @@ static int __hfs_ext_write_extent(struct inode *inode, struct hfs_find_data *fd)
} else {
if (res)
return res;
+ if (fd->entrylength != sizeof(hfs_extent_rec))
+ return -EIO;
hfs_bnode_write(fd->bnode, HFS_I(inode)->cached_extents, fd->entryoffset, fd->entrylength);
HFS_I(inode)->flags &= ~HFS_FLG_EXT_DIRTY;
}
--
2.53.0
reply other threads:[~2026-09-09 10:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260909095930.19979-1-roman.demidov.nn@gmail.com \
--to=roman.demidov.nn@gmail.com \
--cc=frank.li@vivo.com \
--cc=glaubitz@physik.fu-berlin.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=slava@dubeyko.com \
/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®