Skip to contentSkip to conversation

gfs2: reject undersized EA records during xattr walks

PATCH In review ZhengYuan Huang 2 participants 3 messages Apr 28 – May 6 GFS2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gfs2: reject undersized EA records during xattr walks

[BUG]
A fuzzed GFS2 image can crash in ea_split_ea() while servicing setxattr:

BUG: KASAN: 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

Call Trace:
 ...
 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:

BUG: KASAN: 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

Call Trace:
 __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 only that each EA record has a non-zero ea_rec_len, stays within the block, and has a valid type. It never checks that the record span actually covers the layout encoded by ea_name_len, ea_data_len, and ea_num_ptrs.

If a malformed record reaches ea_set_simple() with GFS2_EA_REC_LEN(ea) < GFS2_EA_SIZE(ea), 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]
Reject EA records whose reserved record length is smaller than their computed layout size in ea_foreach_i(), which is the common parse boundary for existing xattr metadata. This stops malformed records before any update path can split or otherwise trust the broken geometry.

---
fs/gfs2/xattr.c | 7 +++++++

1 file changed, 7 insertions(+)
fs/gfs2/xattr.c +7 -0
index b9f48d6f10a9..16cf31bde99a 100644
@@ -96,6 +96,8 @@ 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)) {
+		u32 ea_size;
+
 		if (!GFS2_EA_REC_LEN(ea)) {
 			gfs2_consist_inode(ip);
 			return -EIO;
@@ -109,6 +111,11 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
 			gfs2_consist_inode(ip);
 			return -EIO;
 		}
+		ea_size = GFS2_EA_SIZE(ea);
+		if (GFS2_EA_REC_LEN(ea) < ea_size) {
+			gfs2_consist_inode(ip);
+			return -EIO;
+		}
 		error = ea_call(ip, bh, ea, prev, data);
 		if (error)
 			return error;
Signature · 1 line
2.43.0
#1 lore raw

Hello ZhengYuan Huang,

Quoted 145 lines · ZhengYuan Huang

[BUG]
A fuzzed GFS2 image can crash in ea_split_ea() while servicing setxattr:

BUG: KASAN: 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

Call Trace:
 ...
 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:

BUG: KASAN: 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

Call Trace:
 __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 only that each EA record has a non-zero ea_rec_len, stays within the block, and has a valid type. It never checks that the record span actually covers the layout encoded by ea_name_len, ea_data_len, and ea_num_ptrs.

If a malformed record reaches ea_set_simple() with GFS2_EA_REC_LEN(ea) < GFS2_EA_SIZE(ea), 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]
Reject EA records whose reserved record length is smaller than their computed layout size in ea_foreach_i(), which is the common parse boundary for existing xattr metadata. This stops malformed records before any update path can split or otherwise trust the broken geometry.

---
fs/gfs2/xattr.c | 7 +++++++

1 file changed, 7 insertions(+)
fs/gfs2/xattr.c +7 -1
index b9f48d6f10a9..16cf31bde99a 100644
@@ -96,6 +96,8 @@ 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)) {
+               u32 ea_size;
+
                if (!GFS2_EA_REC_LEN(ea)) {
                        gfs2_consist_inode(ip);
                        return -EIO;
@@ -109,6 +111,11 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
                        gfs2_consist_inode(ip);
                        return -EIO;
                }
+               ea_size = GFS2_EA_SIZE(ea);
+               if (GFS2_EA_REC_LEN(ea) < ea_size) {
+                       gfs2_consist_inode(ip);
+                       return -EIO;
+               }
                error = ea_call(ip, bh, ea, prev, data);
                if (error)
                        return error;
--
Quoted 2 lines

2.43.0

the '!GFS2_EA_REC_LEN(ea)' and 'GFS2_EA_REC_LEN(ea) < ea_size' checks can be combined here. Also, nothing prevents GFS2_EA_SIZE() from overflowing.

Can you fix that?

Thanks,
Andreas

#2 lore raw
Quoted 156 lines · Andreas Gruenbacher

Hello ZhengYuan Huang,

Quoted 145 lines · ZhengYuan Huang

[BUG]
A fuzzed GFS2 image can crash in ea_split_ea() while servicing setxattr:

BUG: KASAN: 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

Call Trace:
 ...
 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:

BUG: KASAN: 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

Call Trace:
 __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 only that each EA record has a non-zero ea_rec_len, stays within the block, and has a valid type. It never checks that the record span actually covers the layout encoded by ea_name_len, ea_data_len, and ea_num_ptrs.

If a malformed record reaches ea_set_simple() with GFS2_EA_REC_LEN(ea) < GFS2_EA_SIZE(ea), 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]
Reject EA records whose reserved record length is smaller than their computed layout size in ea_foreach_i(), which is the common parse boundary for existing xattr metadata. This stops malformed records before any update path can split or otherwise trust the broken geometry.

---
fs/gfs2/xattr.c | 7 +++++++

1 file changed, 7 insertions(+)
fs/gfs2/xattr.c +7 -1
index b9f48d6f10a9..16cf31bde99a 100644
@@ -96,6 +96,8 @@ 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)) {
+               u32 ea_size;
+
                if (!GFS2_EA_REC_LEN(ea)) {
                        gfs2_consist_inode(ip);
                        return -EIO;
@@ -109,6 +111,11 @@ static int ea_foreach_i(struct gfs2_inode *ip, struct buffer_head *bh,
                        gfs2_consist_inode(ip);
                        return -EIO;
                }
+               ea_size = GFS2_EA_SIZE(ea);
+               if (GFS2_EA_REC_LEN(ea) < ea_size) {
+                       gfs2_consist_inode(ip);
+                       return -EIO;
+               }
                error = ea_call(ip, bh, ea, prev, data);
                if (error)
                        return error;
--
Quoted 2 lines

2.43.0

the '!GFS2_EA_REC_LEN(ea)' and 'GFS2_EA_REC_LEN(ea) < ea_size' checks can be combined here. Also, nothing prevents GFS2_EA_SIZE() from overflowing.

Quoted 5 lines

Can you fix that?

Thanks,
Andreas

Thanks for the suggestions. I have sent a v2 patch addressing the issues above.

Best regards,
ZhengYuan Huang