From: Qianqiang Liu <qianqiang.liu@163.com>
To: tytso@mit.edu
Cc: adilger.kernel@dilger.ca,
syzbot <syzbot+f792df426ff0f5ceb8d1@syzkaller.appspotmail.com>,
linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
syzkaller-bugs@googlegroups.com, qianqiang.liu@163.com
Subject: [PATCH] ext4: fix out-of-bounds issue in ext4_xattr_set_entry
Date: Sun, 22 Sep 2024 14:42:49 +0800 [thread overview]
Message-ID: <Zu+8aQBJgMn7xVws@thinkpad.lan> (raw)
In-Reply-To: <66efba95.050a0220.3195df.008c.GAE@google.com>
syzbot has found an out-of-bounds issue in ext4_xattr_set_entry:
==================================================================
BUG: KASAN: out-of-bounds in ext4_xattr_set_entry+0x8ce/0x1f60 fs/ext4/xattr.c:1781
Read of size 18446744073709551572 at addr ffff888036426850 by task syz-executor264/5095
CPU: 0 UID: 0 PID: 5095 Comm: syz-executor264 Not tainted 6.11.0-syzkaller-03917-ga940d9a43e62 #0
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:93 [inline]
dump_stack_lvl+0x241/0x360 lib/dump_stack.c:119
print_address_description mm/kasan/report.c:377 [inline]
print_report+0x169/0x550 mm/kasan/report.c:488
kasan_report+0x143/0x180 mm/kasan/report.c:601
kasan_check_range+0x282/0x290 mm/kasan/generic.c:189
__asan_memmove+0x29/0x70 mm/kasan/shadow.c:94
ext4_xattr_set_entry+0x8ce/0x1f60 fs/ext4/xattr.c:1781
[...]
==================================================================
This issue is caused by a negative size in memmove.
We need to check for this.
Fixes: dec214d00e0d ("ext4: xattr inode deduplication")
Reported-by: syzbot+f792df426ff0f5ceb8d1@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=f792df426ff0f5ceb8d1
Tested-by: syzbot+f792df426ff0f5ceb8d1@syzkaller.appspotmail.com
Signed-off-by: Qianqiang Liu <qianqiang.liu@163.com>
---
fs/ext4/xattr.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 46ce2f21fef9..336badb46246 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -1776,7 +1776,14 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
} else if (s->not_found) {
/* Insert new name. */
size_t size = EXT4_XATTR_LEN(name_len);
- size_t rest = (void *)last - (void *)here + sizeof(__u32);
+ size_t rest;
+
+ if (last < here) {
+ ret = -ENOSPC;
+ goto out;
+ } else {
+ rest = (void *)last - (void *)here + sizeof(__u32);
+ }
memmove((void *)here + size, here, rest);
memset(here, 0, size);
--
2.34.1
--
Best,
Qianqiang Liu
next prev parent reply other threads:[~2024-09-22 6:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-22 0:16 [syzbot] [ext4?] KASAN: out-of-bounds Read in ext4_xattr_set_entry syzbot
2024-09-22 5:46 ` Qianqiang Liu
2024-09-22 6:35 ` syzbot
2024-09-22 6:42 ` Qianqiang Liu [this message]
2024-10-01 9:41 ` [PATCH] ext4: fix out-of-bounds issue " Ojaswin Mujoo
2024-10-01 10:15 ` Qianqiang Liu
2024-10-02 6:27 ` Qianqiang Liu
2024-10-08 7:40 ` Baokun Li
2024-10-09 15:50 ` Jan Kara
2024-10-11 2:18 ` Baokun Li
2024-10-14 16:31 ` Jan Kara
2024-10-16 8:02 ` Baokun Li
2024-10-16 20:47 ` Theodore Ts'o
2024-10-17 12:42 ` Baokun Li
2024-10-17 14:47 ` Theodore Ts'o
2024-10-18 3:44 ` Baokun Li
2024-10-02 6:31 ` [syzbot] [ext4?] KASAN: out-of-bounds Read " Qianqiang Liu
2024-10-02 6:54 ` syzbot
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=Zu+8aQBJgMn7xVws@thinkpad.lan \
--to=qianqiang.liu@163.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=syzbot+f792df426ff0f5ceb8d1@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=tytso@mit.edu \
/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