jfs: fix missing bounds check in __jfs_setxattr()
Subsystems (2)
PATCH 1/1 jfs: fix missing bounds check in __jfs_setxattr()
The loop in __jfs_setxattr() iterates over EA entries without validating that NEXT_EA(ea) stays within the ealist buffer. A crafted filesystem image with a manipulated EA valuelen field can cause NEXT_EA() to land inside the buffer but past the last valid entry, leading to out-of-bounds reads in the subsequent memcmp() call.
Fix this by adding the same bounds check already present in __jfs_getxattr() and jfs_listxattr().
--- fs/jfs/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/jfs/xattr.c +7 -1
@@ -688,8 +688,14 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, new_size =sizeof (struct jfs_ea_list );if (xattr_size) { -for (ea =FIRST_EA (ealist); ea <END_EALIST (ealist); +struct jfs_ea *ealist_end =END_EALIST (ealist); +for (ea =FIRST_EA (ealist); ea < ealist_end; ea =NEXT_EA (ea)) { +if (unlikely (ea +1 > ealist_end) || +unlikely (NEXT_EA (ea) > ealist_end)) { + rc = -EUCLEAN ; + goto release; + }if ((namelen == ea->namelen) && (memcmp (name, ea->name, namelen) ==0 )) { found =1 ;
Signature · 1 line
2.43.0
Quoted 38 lines · Sebastian Alba Vives
The loop in
__jfs_setxattr()iterates over EA entries without validating thatNEXT_EA(ea)stays within the ealist buffer. A crafted filesystem image with a manipulated EA valuelen field can causeNEXT_EA()to land inside the buffer but past the last valid entry, leading to out-of-bounds reads in the subsequentmemcmp()call.Fix this by adding the same bounds check already present in
__jfs_getxattr()andjfs_listxattr().Reported-by Sebastian Alba Vives <[email protected]>Signed-off-by Sebastian Alba Vives <[email protected]>--- fs/jfs/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/jfs/xattr.c +7
-1@@ -688,8 +688,14 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, new_size =sizeof (struct jfs_ea_list );if (xattr_size) { -for (ea =FIRST_EA (ealist); ea <END_EALIST (ealist); +struct jfs_ea *ealist_end =END_EALIST (ealist); +for (ea =FIRST_EA (ealist); ea < ealist_end; ea =NEXT_EA (ea)) { +if (unlikely (ea +1 > ealist_end) || +unlikely (NEXT_EA (ea) > ealist_end)) { + rc = -EUCLEAN ; + goto release; + }if ((namelen == ea->namelen) && (memcmp (name, ea->name, namelen) ==0 )) { found =1 ;Signature · 1 line
2.43.0
Does the userspace fsck program catch this first? That would prevent this check from having to always be here, slowing down this operation.
thanks,
greg k-h
Quoted 20 lines · Sebastian Alba Vives
The loop in
__jfs_setxattr()iterates over EA entries without validating thatNEXT_EA(ea)stays within the ealist buffer. A crafted filesystem image with a manipulated EA valuelen field can causeNEXT_EA()to land inside the buffer but past the last valid entry, leading to out-of-bounds reads in the subsequentmemcmp()call.Fix this by adding the same bounds check already present in
__jfs_getxattr()andjfs_listxattr().Reported-by Sebastian Alba Vives <[email protected]>Signed-off-by Sebastian Alba Vives <[email protected]>--- fs/jfs/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/jfs/xattr.c +0
-0
fs/jfs/xattr.c int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, · line 694
Quoted 8 lines
fs/jfs/xattr.c +3
-1@@ -688,8 +688,14 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, new_size =sizeof (struct jfs_ea_list );if (xattr_size) { -for (ea =FIRST_EA (ealist); ea <END_EALIST (ealist); +struct jfs_ea *ealist_end =END_EALIST (ealist); +for (ea =FIRST_EA (ealist); ea < ealist_end; ea =NEXT_EA (ea)) { + if (unlikely(ea + 1 > ealist_end) ||
What use is this check? How can ea + 1 > ealist_end immediately after ea < ealist_end?
Quoted 10 lines
fs/jfs/xattr.c +4
-0+ unlikely(NEXT_EA(ea) > ealist_end)) { + rc = -EUCLEAN ; + goto release; + }if ((namelen == ea->namelen) && (memcmp (name, ea->name, namelen) ==0 )) { found =1 ;Signature · 1 line
2.43.0
You should also know that jfs is not maintained, and there are MANY of these issues (see syzbot for instance). To my knowledge the community has decided to deprioritize these kinds of issues, and perhaps eventually move to FUSE based implementations for legacy filesystems.
Also, you should cc the general list [email protected] and the jfs maintainer Dave Kleikamp <[email protected]>. Use the get_maintainer script.
That being said these fixes are still accepted. Thanks for your (first?) contribution :)
Thanks,
Jori.
Quoted 13 lines
Op 16-04-2026 12:01 CEST schreef Jori Koolstra <[email protected]>:
Quoted 11 lines
--- fs/jfs/xattr.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)fs/jfs/xattr.c +0
-0@@ -688,8 +688,14 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, new_size =sizeof (struct jfs_ea_list );
Quoted 10 lines
fs/jfs/xattr.c int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name, · line 694
Quoted 6 lines
fs/jfs/xattr.c +3
-1if (xattr_size) { -for (ea =FIRST_EA (ealist); ea <END_EALIST (ealist); +struct jfs_ea *ealist_end =END_EALIST (ealist); +for (ea =FIRST_EA (ealist); ea < ealist_end; ea =NEXT_EA (ea)) { + if (unlikely(ea + 1 > ealist_end) ||What use is this check? How can ea + 1 >
ealist_endimmediately after ea <ealist_end?
Maybe I should rephrase this a bit more clearly: does the
unlikely(NEXT_EA(ea) > ealist_end))
already take care of that potential scenario?