From: ZhengYuan Huang <gality369@gmail.com>
To: agruenba@redhat.com
Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com,
ZhengYuan Huang <gality369@gmail.com>
Subject: [PATCH v2] gfs2: validate EA record lengths safely during xattr walks
Date: Wed, 6 May 2026 10:22:57 +0800 [thread overview]
Message-ID: <20260506022257.569389-1-gality369@gmail.com> (raw)
[BUG]
A fuzzed GFS2 image can crash in ea_split_ea() while servicing setxattr:
slab-out-of-bounds in ea_split_ea+0x1f3/0x230 fs/gfs2/xattr.c:835
Write of size 4 at addr ffff88801550a1c0 by task syz.0.379/950
Stack:
...
ea_split_ea+0x1f3/0x230 fs/gfs2/xattr.c:835
ea_set_simple_noalloc fs/gfs2/xattr.c:888 [inline]
ea_set_simple+0x66f/0x7c0 fs/gfs2/xattr.c:951
ea_foreach_i+0x2a1/0x560 fs/gfs2/xattr.c:112
ea_foreach+0x3cd/0x5d0 fs/gfs2/xattr.c:140
ea_set_i+0x176/0x3d0 fs/gfs2/xattr.c:1063
__gfs2_xattr_set+0x8de/0xc60 fs/gfs2/xattr.c:1215
gfs2_xattr_set+0x2ed/0x450 fs/gfs2/xattr.c:1258
__vfs_setxattr+0x14f/0x1c0 fs/xattr.c:200
__vfs_setxattr_noperm+0x10b/0x5c0 fs/xattr.c:234
__vfs_setxattr_locked+0x172/0x240 fs/xattr.c:295
vfs_setxattr+0x167/0x390 fs/xattr.c:321
do_setxattr+0x13c/0x180 fs/xattr.c:636
filename_setxattr+0x16b/0x1c0 fs/xattr.c:665
path_setxattrat+0x1d8/0x280 fs/xattr.c:713
__do_sys_setxattr fs/xattr.c:747 [inline]
__se_sys_setxattr fs/xattr.c:743 [inline]
__x64_sys_setxattr+0xcd/0x150 fs/xattr.c:743
...
Allocated by task 893:
kasan_save_stack+0x39/0x70 mm/kasan/common.c:56
kasan_save_track+0x14/0x40 mm/kasan/common.c:77
kasan_save_alloc_info+0x37/0x60 mm/kasan/generic.c:573
unpoison_slab_object mm/kasan/common.c:342 [inline]
__kasan_slab_alloc+0x9d/0xa0 mm/kasan/common.c:368
kasan_slab_alloc include/linux/kasan.h:252 [inline]
slab_post_alloc_hook mm/slub.c:4978 [inline]
slab_alloc_node mm/slub.c:5288 [inline]
kmem_cache_alloc_noprof+0x1f0/0x7d0 mm/slub.c:5295
__do_sys_getcwd+0xe0/0x730 fs/d_path.c:416
__se_sys_getcwd fs/d_path.c:412 [inline]
__x64_sys_getcwd+0x59/0x80 fs/d_path.c:412
x64_sys_call+0x15ac/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:80
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x76/0x7e
Freed by task 893:
kasan_save_stack+0x39/0x70 mm/kasan/common.c:56
kasan_save_track+0x14/0x40 mm/kasan/common.c:77
__kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:587
kasan_save_free_info mm/kasan/kasan.h:406 [inline]
poison_slab_object mm/kasan/common.c:252 [inline]
__kasan_slab_free+0x6f/0xa0 mm/kasan/common.c:284
kasan_slab_free include/linux/kasan.h:234 [inline]
slab_free_hook mm/slub.c:2543 [inline]
slab_free mm/slub.c:6642 [inline]
kmem_cache_free+0x384/0x7a0 mm/slub.c:6752
__do_sys_getcwd+0x3f8/0x730 fs/d_path.c:446
__se_sys_getcwd fs/d_path.c:412 [inline]
__x64_sys_getcwd+0x59/0x80 fs/d_path.c:412
x64_sys_call+0x15ac/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:80
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x76/0x7e
and also as:
use-after-free in ea_split_ea+0x1f3/0x230 fs/gfs2/xattr.c:835
Write of size 4 at addr ffff888023742118 by task syz.0.27/395
Stack:
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0xbe/0x130 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0xd1/0x650 mm/kasan/report.c:482
kasan_report+0xfb/0x140 mm/kasan/report.c:595
__asan_report_store4_noabort+0x17/0x30 mm/kasan/report_generic.c:385
ea_split_ea+0x1f3/0x230 fs/gfs2/xattr.c:835
ea_set_simple_noalloc fs/gfs2/xattr.c:888 [inline]
ea_set_simple+0x66f/0x7c0 fs/gfs2/xattr.c:951
ea_foreach_i+0x2a1/0x560 fs/gfs2/xattr.c:112
ea_foreach+0x334/0x5d0 fs/gfs2/xattr.c:162
ea_set_i+0x176/0x3d0 fs/gfs2/xattr.c:1063
__gfs2_xattr_set+0x8de/0xc60 fs/gfs2/xattr.c:1215
gfs2_xattr_set+0x2ed/0x450 fs/gfs2/xattr.c:1258
__vfs_setxattr+0x14f/0x1c0 fs/xattr.c:200
__vfs_setxattr_noperm+0x10b/0x5c0 fs/xattr.c:234
__vfs_setxattr_locked+0x172/0x240 fs/xattr.c:295
vfs_setxattr+0x167/0x390 fs/xattr.c:321
do_setxattr+0x13c/0x180 fs/xattr.c:636
filename_setxattr+0x16b/0x1c0 fs/xattr.c:665
path_setxattrat+0x1d8/0x280 fs/xattr.c:713
__do_sys_setxattr fs/xattr.c:747 [inline]
__se_sys_setxattr fs/xattr.c:743 [inline]
__x64_sys_setxattr+0xcd/0x150 fs/xattr.c:743
...
[CAUSE]
ea_foreach_i() validates that each EA record stays within the block and
has a valid type, but it does not verify that the recorded span covers
the layout encoded by ea_name_len, ea_data_len, and ea_num_ptrs.
Computing that layout from corrupt metadata must also be overflow-safe.
If a malformed record reaches ea_set_simple() with a recorded length
smaller than its computed layout, the unsigned subtraction in the split
test underflows and falsely claims there is enough free space.
ea_split_ea() then writes the new EA header outside the real record.
[FIX]
Add an overflow-safe ea_rec_len_valid() helper and call it from
ea_foreach_i(). The helper folds the zero-length check into the common
record-length validation, rejects records whose computed layout
overflows, and rejects records whose recorded span is smaller than the
aligned layout size.
Signed-off-by: ZhengYuan Huang <gality369@gmail.com>
---
v2:
- combine the zero-length and record-size validation in ea_rec_len_valid()
- make the EA layout size calculation overflow-safe
---
fs/gfs2/xattr.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/fs/gfs2/xattr.c b/fs/gfs2/xattr.c
index b9f48d6f10a9..38f49382c54b 100644
--- a/fs/gfs2/xattr.c
+++ b/fs/gfs2/xattr.c
@@ -8,6 +8,7 @@
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
+#include <linux/overflow.h>
#include <linux/xattr.h>
#include <linux/gfs2_ondisk.h>
#include <linux/posix_acl_xattr.h>
@@ -81,6 +82,31 @@ static bool gfs2_eatype_valid(struct gfs2_sbd *sdp, u8 type)
}
}
+static bool ea_rec_len_valid(const struct gfs2_ea_header *ea)
+{
+ size_t size;
+
+ if (!GFS2_EA_REC_LEN(ea))
+ return false;
+
+ size = sizeof(struct gfs2_ea_header) + ea->ea_name_len;
+ if (GFS2_EA_IS_STUFFED(ea)) {
+ if (check_add_overflow(size, (size_t)GFS2_EA_DATA_LEN(ea), &size))
+ return false;
+ } else {
+ size_t ptr_size;
+
+ if (check_mul_overflow(sizeof(__be64), (size_t)ea->ea_num_ptrs,
+ &ptr_size) ||
+ check_add_overflow(size, ptr_size, &size))
+ return false;
+ }
+ if (check_add_overflow(size, (size_t)7, &size))
+ return false;
+
+ return GFS2_EA_REC_LEN(ea) >= round_down(size, (size_t)8);
+}
+
typedef int (*ea_call_t) (struct gfs2_inode *ip, struct buffer_head *bh,
struct gfs2_ea_header *ea,
struct gfs2_ea_header *prev, void *private);
@@ -96,7 +122,7 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
return -EIO;
for (ea = GFS2_EA_BH2FIRST(bh);; prev = ea, ea = GFS2_EA2NEXT(ea)) {
- if (!GFS2_EA_REC_LEN(ea)) {
+ if (!ea_rec_len_valid(ea)) {
gfs2_consist_inode(ip);
return -EIO;
}
--
2.43.0
reply other threads:[~2026-05-06 2:45 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=20260506022257.569389-1-gality369@gmail.com \
--to=gality369@gmail.com \
--cc=agruenba@redhat.com \
--cc=baijiaju1990@gmail.com \
--cc=gfs2@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=r33s3n6@gmail.com \
--cc=zzzccc427@gmail.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