Skip to content

Commit eceafc3

Browse files
deepanshu406tytso
authored andcommitted
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. Fixes: 3478c83 ("ext4: improve xattr consistency checking and error reporting") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/20260224231429.31361-1-kartikey406@gmail.com/T/ [v1] Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com> Link: https://patch.msgid.link/20260328150038.349497-1-kartikey406@gmail.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 3f60efd commit eceafc3

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/ext4/xattr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ check_xattrs(struct inode *inode, struct buffer_head *bh,
226226
/* Find the end of the names list */
227227
while (!IS_LAST_ENTRY(e)) {
228228
struct ext4_xattr_entry *next = EXT4_XATTR_NEXT(e);
229-
if ((void *)next >= end) {
229+
if ((void *)next + sizeof(u32) > end) {
230230
err_str = "e_name out of bounds";
231231
goto errout;
232232
}

0 commit comments

Comments
 (0)