[syzbot] [tomoyo?] WARNING in tomoyo_write_control

4 views
Skip to first unread message

syzbot

unread,
Dec 15, 2024, 4:48:26 PM12/15/24
to jmo...@namei.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, penguin...@i-love.sakura.ne.jp, se...@hallyn.com, syzkall...@googlegroups.com, take...@nttdata.co.jp, tomoyo...@lists.osdn.me
Hello,

syzbot found the following issue on:

HEAD commit: f932fb9b4074 Merge tag 'v6.13-rc2-ksmbd-server-fixes' of g..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=17855be8580000
kernel config: https://syzkaller.appspot.com/x/.config?x=99a5586995ec03b2
dashboard link: https://syzkaller.appspot.com/bug?extid=7536f77535e5210a5c76
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10a12d44580000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11fc4730580000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/f0d0c95f5364/disk-f932fb9b.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/201cf3c7a7b5/vmlinux-f932fb9b.xz
kernel image: https://storage.googleapis.com/syzbot-assets/fcb972084579/bzImage-f932fb9b.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+7536f7...@syzkaller.appspotmail.com

------------[ cut here ]------------
WARNING: CPU: 1 PID: 5829 at mm/page_alloc.c:4727 __alloc_pages_noprof+0xeff/0x25b0 mm/page_alloc.c:4727
Modules linked in:
CPU: 1 UID: 0 PID: 5829 Comm: syz-executor788 Not tainted 6.13.0-rc2-syzkaller-00159-gf932fb9b4074 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/25/2024
RIP: 0010:__alloc_pages_noprof+0xeff/0x25b0 mm/page_alloc.c:4727
Code: 24 2c 00 00 00 00 89 cd 0f 84 8b f9 ff ff 8b 34 24 48 89 da 8b 7c 24 08 e8 0e b3 fe ff e9 69 f9 ff ff c6 05 e1 44 16 0e 01 90 <0f> 0b 90 31 db e9 9f f3 ff ff 89 14 24 e8 9f a2 0c 00 8b 14 24 e9
RSP: 0018:ffffc90003e1f918 EFLAGS: 00010246
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
RDX: 0000000000000000 RSI: 000000000000000b RDI: 0000000000040d40
RBP: 0000000000000000 R08: 0000000000000006 R09: 00000000003fffff
R10: 00000000003fffff R11: 0000000000000003 R12: 000000000000000b
R13: 0000000000040d40 R14: 1ffff920007c3f37 R15: 00000000003fffff
FS: 0000555571ba8380(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000003ff000 CR3: 000000007b498000 CR4: 00000000003526f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
__alloc_pages_node_noprof include/linux/gfp.h:269 [inline]
alloc_pages_node_noprof include/linux/gfp.h:296 [inline]
___kmalloc_large_node+0x84/0x1b0 mm/slub.c:4228
__kmalloc_large_node_noprof+0x1c/0x70 mm/slub.c:4255
__do_kmalloc_node mm/slub.c:4271 [inline]
__kmalloc_noprof.cold+0xc/0x63 mm/slub.c:4295
kmalloc_noprof include/linux/slab.h:905 [inline]
kzalloc_noprof include/linux/slab.h:1037 [inline]
tomoyo_write_control+0x267/0x13d0 security/tomoyo/common.c:2668
vfs_write+0x24c/0x1150 fs/read_write.c:677
ksys_write+0x12b/0x250 fs/read_write.c:731
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f569c4ea2e9
Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffddff422d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007ffddff424b8 RCX: 00007f569c4ea2e9
RDX: 00000000fffffdef RSI: 0000000000000000 RDI: 0000000000000003
RBP: 00007f569c55d610 R08: 0000000000008000 R09: 0000000000008000
R10: 0000000000008000 R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffddff424a8 R14: 0000000000000001 R15: 0000000000000001
</TASK>


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

Leo Stone

unread,
Dec 15, 2024, 9:15:35 PM12/15/24
to syzbot+7536f7...@syzkaller.appspotmail.com, Leo Stone, jmo...@namei.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, penguin...@i-love.sakura.ne.jp, se...@hallyn.com, syzkall...@googlegroups.com, take...@nttdata.co.jp, tomoyo...@lists.osdn.me
syzbot creates an anonymous memory region, and then issues a
write syscall from the new memory region to a sysfs entry controlled by
tomoyo, specifying a buffer size of just under 2 GB (the actual size of
the buffer is ~32 MB). Because tomoyo_write_control will double the
size of head->write_buf every time it runs out of space for the current
line, and everything in the zero-initialized buffer is on the same line,
the function will eventually issue a kzalloc with a size that is too large,
triggering the warning.

Reject writes with excessively long lines.

Reported-by: syzbot+7536f7...@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=7536f77535e5210a5c76
Signed-off-by: Leo Stone <leoc...@gmail.com>
---
security/tomoyo/common.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 5c7b059a332a..0c75be949c9d 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -2665,6 +2665,10 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,

if (head->w.avail >= head->writebuf_size - 1) {
const int len = head->writebuf_size * 2;
+ if (len > KMALLOC_MAX_SIZE) {
+ error = -EINVAL;
+ break;
+ }
char *cp = kzalloc(len, GFP_NOFS);

if (!cp) {
--
2.43.0

Lizhi Xu

unread,
Dec 16, 2024, 2:19:12 AM12/16/24
to syzbot+7536f7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
User input a too large avail length 0xfffffdeful.

#syz test

diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 5c7b059a332a..d25752eb8790 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -2656,6 +2656,9 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
return -EINVAL;
if (mutex_lock_interruptible(&head->io_sem))
return -EINTR;
+ if (avail_len << PAGE_SHIFT > MAX_PAGE_ORDER)
+ return -EINVAL;
+
cp0 = head->write_buf;
head->read_user_buf_avail = 0;
idx = tomoyo_read_lock();

Lizhi Xu

unread,
Dec 16, 2024, 2:20:40 AM12/16/24
to syzbot+7536f7...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
User input a too large avail length 0xfffffdeful.

#syz test

diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 5c7b059a332a..65458b4059ab 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -2654,6 +2654,8 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,

if (!head->write)
return -EINVAL;
+ if (avail_len << PAGE_SHIFT > MAX_PAGE_ORDER)
+ return -EINVAL;
if (mutex_lock_interruptible(&head->io_sem))
return -EINTR;
cp0 = head->write_buf;

syzbot

unread,
Dec 16, 2024, 2:33:04 AM12/16/24
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING: lock held when returning to user space in tomoyo_write_control

================================================
WARNING: lock held when returning to user space!
6.13.0-rc3-syzkaller-g78d4f34e2115-dirty #0 Not tainted
------------------------------------------------
syz.0.16/6711 is leaving the kernel with locks still held!
1 lock held by syz.0.16/6711:
#0: ffff88802a08b080 (&head->io_sem){+.+.}-{4:4}, at: tomoyo_write_control+0x51/0x1b0 security/tomoyo/common.c:2657


Tested on:

commit: 78d4f34e Linux 6.13-rc3
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=12d7d4f8580000
kernel config: https://syzkaller.appspot.com/x/.config?x=9cac7e24ceea492
dashboard link: https://syzkaller.appspot.com/bug?extid=7536f77535e5210a5c76
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=12eb1730580000

syzbot

unread,
Dec 16, 2024, 2:53:07 AM12/16/24
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-by: syzbot+7536f7...@syzkaller.appspotmail.com
Tested-by: syzbot+7536f7...@syzkaller.appspotmail.com

Tested on:

commit: 78d4f34e Linux 6.13-rc3
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=14eafcdf980000
kernel config: https://syzkaller.appspot.com/x/.config?x=9cac7e24ceea492
dashboard link: https://syzkaller.appspot.com/bug?extid=7536f77535e5210a5c76
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=149947e8580000

Note: testing is done by a robot and is best-effort only.

Lizhi Xu

unread,
Dec 16, 2024, 3:20:00 AM12/16/24
to syzbot+7536f7...@syzkaller.appspotmail.com, jmo...@namei.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, penguin...@i-love.sakura.ne.jp, se...@hallyn.com, syzkall...@googlegroups.com, take...@nttdata.co.jp, tomoyo...@lists.osdn.me
User input a too large buffer size 0xfffffdeful, although it is truncated to
MAX_RW_COUNT in vfs_write, its value is still too large, causing warning when
allocating memory in tomoyo_write_control.

Add a check for it to avoid this case.
Tested-by: syzbot+7536f7...@syzkaller.appspotmail.com
Signed-off-by: Lizhi Xu <lizh...@windriver.com>
---
security/tomoyo/common.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 5c7b059a332a..f63388c2fffd 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -2654,6 +2654,8 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,

if (!head->write)
return -EINVAL;
+ if (avail_len > KMALLOC_MAX_SIZE)
+ return -EINVAL;
if (mutex_lock_interruptible(&head->io_sem))
return -EINTR;
cp0 = head->write_buf;
--
2.43.0

Tetsuo Handa

unread,
Dec 16, 2024, 5:06:29 AM12/16/24
to Lizhi Xu, syzbot+7536f7...@syzkaller.appspotmail.com, jmo...@namei.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, se...@hallyn.com, syzkall...@googlegroups.com, take...@nttdata.co.jp
On 2024/12/16 17:19, Lizhi Xu wrote:
> User input a too large buffer size 0xfffffdeful, although it is truncated to
> MAX_RW_COUNT in vfs_write, its value is still too large, causing warning when
> allocating memory in tomoyo_write_control.
>
> Add a check for it to avoid this case.

Thank you for a patch. But I don't think this fix is correct, for one can make
head->writebuf_size too large by writing chunks without new line for many times.

Tetsuo Handa

unread,
Dec 16, 2024, 5:45:17 AM12/16/24
to syzbot, jmo...@namei.org, linux-...@vger.kernel.org, linux-secu...@vger.kernel.org, pa...@paul-moore.com, se...@hallyn.com, syzkall...@googlegroups.com, take...@nttdata.co.jp, Leo Stone
syzbot is reporting too large allocation warning at tomoyo_write_control(),
for one can write a very very long line without new line character. To fix
this warning, I use __GFP_NOWARN rather than checking for KMALLOC_MAX_SIZE,
for practically a valid line should be always shorter than 32KB where the
"too small to fail" memory-allocation rule applies.

One might try to write a valid line that is longer than 32KB, but such
request will likely fail with -ENOMEM. Therefore, I feel that separately
returning -EINVAL when a line is longer than KMALLOC_MAX_SIZE is redundant.
There is no need to distinguish over-32KB and over-KMALLOC_MAX_SIZE.
Reported-by: Leo Stone <leoc...@gmail.com>
Closes: https://lkml.kernel.org/r/20241216021459.1...@gmail.com
Signed-off-by: Tetsuo Handa <penguin...@I-love.SAKURA.ne.jp>
---
security/tomoyo/common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 5c7b059a332a..972664962e8f 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -2665,7 +2665,7 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,

if (head->w.avail >= head->writebuf_size - 1) {
const int len = head->writebuf_size * 2;
- char *cp = kzalloc(len, GFP_NOFS);
+ char *cp = kzalloc(len, GFP_NOFS | __GFP_NOWARN);

if (!cp) {
error = -ENOMEM;
--
2.43.5


Reply all
Reply to author
Forward
0 new messages