ext4: fix bounds check in check_xattrs() to prevent out-of-bounds access
Subsystems (2)
PATCH v2 1/1 ext4: fix bounds check in check_xattrs() to prevent out-of-bounds access
The bounds check for the next xattr entry in check_xattrs() uses (void *)next >= end, which allows next to point within sizeof(u32) bytes of end. On the next loop iteration, IS_LAST_ENTRY() reads 4 bytes via *(__u32 *)(entry), which can overrun the valid xattr region.
For example, if next lands at end - 1, the check passes since next < end, but IS_LAST_ENTRY() reads 4 bytes starting at end - 1, accessing 3 bytes beyond the valid region.
Fix this by changing the check to (void *)next + sizeof(u32) > end, ensuring there is always enough space for the IS_LAST_ENTRY() read on the subsequent iteration.
---
v2: Move the fix to check_xattrs() as suggested by Ted Ts'o,
instead of adding a check in ext4_xattr_ibody_get().
--- fs/ext4/xattr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/xattr.c +1 -1
@@ -226,7 +226,7 @@ check_xattrs(struct inode *inode, struct buffer_head *bh,/* Find the end of the names list */ while (!IS_LAST_ENTRY (e)) {struct ext4_xattr_entry *next =EXT4_XATTR_NEXT (e); -if ((void *)next >= end) { +if ((void *)next +sizeof (u32) > end) { err_str ="e_name out of bounds" ; goto errout; }
Signature · 1 line
2.43.0
Quoted 10 lines · Deepanshu Kartikey
The bounds check for the next xattr entry in
check_xattrs()uses (void *)next >= end, which allows next to point within sizeof(u32) bytes of end. On the next loop iteration,IS_LAST_ENTRY()reads 4 bytes via *(__u32 *)(entry), which can overrun the valid xattr region.For example, if next lands at end - 1, the check passes since next < end, but
IS_LAST_ENTRY()reads 4 bytes starting at end - 1, accessing 3 bytes beyond the valid region.[...]
Applied, thanks!
[1/1] ext4: fix bounds check in check_xattrs() to prevent out-of-bounds access
commit: eceafc31ea7b42c984ece10d79d505c0bb6615d5
Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>