[syzbot] [arm-msm?] [net?] memory leak in radix_tree_insert (2)

49 views
Skip to first unread message

syzbot

unread,
Dec 7, 2023, 7:52:33 PM12/7/23
to da...@davemloft.net, edum...@google.com, ku...@kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, ma...@kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 33cc938e65a9 Linux 6.7-rc4
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=16ddf83ce80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=10276ebae80000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=128c50d2e80000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/bd6d7a5ff2af/disk-33cc938e.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/ce91b40ecddb/vmlinux-33cc938e.xz
kernel image: https://storage.googleapis.com/syzbot-assets/5507257fe99e/bzImage-33cc938e.xz

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

write to /proc/sys/kernel/hung_task_check_interval_secs failed: No such file or directory
write to /proc/sys/kernel/softlockup_all_cpu_backtrace failed: No such file or directory
BUG: memory leak
unreferenced object 0xffff88810bbf56d8 (size 576):
comm "syz-executor250", pid 5051, jiffies 4294951219 (age 12.920s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
f0 a9 2d 0c 81 88 ff ff f0 56 bf 0b 81 88 ff ff ..-......V......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae105d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae105d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae26f6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32d2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c32>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c32>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d7b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810bbf5920 (size 576):
comm "syz-executor250", pid 5051, jiffies 4294951219 (age 12.920s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 d8 56 bf 0b 81 88 ff ff 6........V......
f0 a9 2d 0c 81 88 ff ff 38 59 bf 0b 81 88 ff ff ..-.....8Y......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae105d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae105d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae26f6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32d2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c32>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c32>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d7b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c832000 (size 576):
comm "syz-executor250", pid 5051, jiffies 4294951219 (age 12.920s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 20 59 bf 0b 81 88 ff ff 0?...... Y......
f0 a9 2d 0c 81 88 ff ff 18 20 83 0c 81 88 ff ff ..-...... ......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae105d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae105d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae26f6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32d2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c32>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c32>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d7b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c832248 (size 576):
comm "syz-executor250", pid 5051, jiffies 4294951219 (age 12.920s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 00 20 83 0c 81 88 ff ff *?....... ......
f0 a9 2d 0c 81 88 ff ff 60 22 83 0c 81 88 ff ff ..-.....`"......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae105d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae105d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae26f6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32d2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c32>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c32>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d7b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

write to /proc/sys/kernel/hung_task_check_interval_secs failed: No such file or directory
write to /proc/sys/kernel/softlockup_all_cpu_backtrace failed: No such file or directory


---
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

Lizhi Xu

unread,
Dec 7, 2023, 11:13:15 PM12/7/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 976b9bd02a1b..5c2f9d8f2c3e 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -714,8 +714,10 @@ int radix_tree_insert(struct radix_tree_root *root, unsigned long index,
return error;

error = insert_entries(node, slot, item);
- if (error < 0)
+ if (error < 0) {
+ __radix_tree_delete(root, node, slot);
return error;
+ }

if (node) {
unsigned offset = get_slot_offset(node, slot);

syzbot

unread,
Dec 8, 2023, 12:17:04 AM12/8/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

lib/radix-tree.c:718:17: error: implicit declaration of function '__radix_tree_delete'; did you mean 'radix_tree_delete'? [-Werror=implicit-function-declaration]
lib/radix-tree.c:1366:13: error: conflicting types for '__radix_tree_delete'; have 'bool(struct xarray *, struct xa_node *, void **)' {aka '_Bool(struct xarray *, struct xa_node *, void **)'}


Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1472fe6ce80000

Lizhi Xu

unread,
Dec 8, 2023, 12:56:46 AM12/8/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
@@ -55,6 +55,8 @@ struct kmem_cache *radix_tree_node_cachep;
#define IDR_MAX_PATH (DIV_ROUND_UP(IDR_INDEX_BITS, \
RADIX_TREE_MAP_SHIFT))
#define IDR_PRELOAD_SIZE (IDR_MAX_PATH * 2 - 1)
+static bool __radix_tree_delete(struct radix_tree_root *root,
+ struct radix_tree_node *node, void __rcu **slot);

/*
* Per-cpu pool of preloaded nodes

syzbot

unread,
Dec 8, 2023, 1:15:06 AM12/8/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file lib/radix-tree.c
misordered hunks! output would be garbled
Hunk #2 FAILED at 57.
1 out of 2 hunks FAILED
patch: https://syzkaller.appspot.com/x/patch.diff?x=149841cae80000

Lizhi Xu

unread,
Dec 8, 2023, 1:59:50 AM12/8/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 976b9bd02a1b..5c2f9d8f2c3e 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -714,8 +714,10 @@ int radix_tree_insert(struct radix_tree_root *root, unsigned long index,
return error;

error = insert_entries(node, slot, item);
- if (error < 0)
+ if (error < 0) {
+ __radix_tree_delete(root, node, slot);
return error;
+ }

if (node) {
unsigned offset = get_slot_offset(node, slot);
@@ -581,6 +579,24 @@ static bool delete_node(struct radix_tree_root *root,
return deleted;
}

+static bool __radix_tree_delete(struct radix_tree_root *root,
+ struct radix_tree_node *node, void __rcu **slot)
+{
+ void *old = rcu_dereference_raw(*slot);
+ int values = xa_is_value(old) ? -1 : 0;
+ unsigned offset = get_slot_offset(node, slot);
+ int tag;
+
+ if (is_idr(root))
+ node_tag_set(root, node, IDR_FREE, offset);
+ else
+ for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++)
+ node_tag_clear(root, node, tag, offset);
+
+ replace_slot(slot, NULL, node, -1, values);
+ return node && delete_node(root, node);
+}
+
/**
* __radix_tree_create - create a slot in a radix tree
* @root: radix tree root
@@ -1365,24 +1381,6 @@ radix_tree_gang_lookup_tag_slot(const struct radix_tree_root *root,
}
EXPORT_SYMBOL(radix_tree_gang_lookup_tag_slot);

-static bool __radix_tree_delete(struct radix_tree_root *root,
- struct radix_tree_node *node, void __rcu **slot)
-{
- void *old = rcu_dereference_raw(*slot);
- int values = xa_is_value(old) ? -1 : 0;
- unsigned offset = get_slot_offset(node, slot);
- int tag;
-
- if (is_idr(root))
- node_tag_set(root, node, IDR_FREE, offset);
- else
- for (tag = 0; tag < RADIX_TREE_MAX_TAGS; tag++)
- node_tag_clear(root, node, tag, offset);
-
- replace_slot(slot, NULL, node, -1, values);
- return node && delete_node(root, node);
-}
-
/**
* radix_tree_iter_delete - delete the entry at this iterator position
* @root: radix tree root

syzbot

unread,
Dec 8, 2023, 2:16:04 AM12/8/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

failed to apply patch:
checking file lib/radix-tree.c
misordered hunks! output would be garbled
Hunk #2 FAILED at 581.
Hunk #3 succeeded at 1363 (offset -4 lines).
1 out of 3 hunks FAILED
patch: https://syzkaller.appspot.com/x/patch.diff?x=15fee232e80000

Lizhi Xu

unread,
Dec 8, 2023, 2:44:44 AM12/8/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 976b9bd02a1b..5c2f9d8f2c3e 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c

syzbot

unread,
Dec 8, 2023, 3:17:07 AM12/8/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

lib/radix-tree.c:591:17: error: implicit declaration of function 'node_tag_set'; did you mean 'root_tag_set'? [-Werror=implicit-function-declaration]
lib/radix-tree.c:594:25: error: implicit declaration of function 'node_tag_clear'; did you mean 'root_tag_clear'? [-Werror=implicit-function-declaration]
lib/radix-tree.c:596:9: error: implicit declaration of function 'replace_slot'; did you mean 'replace_fops'? [-Werror=implicit-function-declaration]
lib/radix-tree.c:843:13: error: static declaration of 'replace_slot' follows non-static declaration
lib/radix-tree.c:958:13: error: static declaration of 'node_tag_set' follows non-static declaration
lib/radix-tree.c:1015:13: error: static declaration of 'node_tag_clear' follows non-static declaration
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=178c2ed4e80000

Lizhi Xu

unread,
Dec 8, 2023, 4:45:45 AM12/8/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 976b9bd02a1b..b98e9f2c24ac 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -55,6 +55,8 @@ struct kmem_cache *radix_tree_node_cachep;
#define IDR_MAX_PATH (DIV_ROUND_UP(IDR_INDEX_BITS, \
RADIX_TREE_MAP_SHIFT))
#define IDR_PRELOAD_SIZE (IDR_MAX_PATH * 2 - 1)
+static bool __radix_tree_delete(struct radix_tree_root *root,
+ struct radix_tree_node *node, void __rcu **slot);

/*
* Per-cpu pool of preloaded nodes
@@ -714,8 +716,10 @@ int radix_tree_insert(struct radix_tree_root *root, unsigned long index,
return error;

error = insert_entries(node, slot, item);
- if (error < 0)
+ if (error < 0) {
+ __radix_tree_delete(root, node, slot);
return error;
+ }

if (node) {
unsigned offset = get_slot_offset(node, slot);
--
2.43.0

syzbot

unread,
Dec 8, 2023, 5:59:04 AM12/8/23
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:
memory leak in radix_tree_insert

2023/12/08 10:49:43 executed programs: 1
BUG: memory leak
unreferenced object 0xffff88810c5a6000 (size 576):
comm "syz-executor.0", pid 5491, jiffies 4294944531 (age 12.550s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
b0 ed 2e 1b 81 88 ff ff 18 60 5a 0c 81 88 ff ff .........`Z.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:278
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:626 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x370 lib/radix-tree.c:714
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae2716>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32f2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6dddf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6dddf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c5a6248 (size 576):
comm "syz-executor.0", pid 5491, jiffies 4294944531 (age 12.550s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 00 60 5a 0c 81 88 ff ff 6........`Z.....
b0 ed 2e 1b 81 88 ff ff 60 62 5a 0c 81 88 ff ff ........`bZ.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:278
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:626 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x370 lib/radix-tree.c:714
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae2716>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32f2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6dddf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6dddf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c5a6490 (size 576):
comm "syz-executor.0", pid 5491, jiffies 4294944531 (age 12.550s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 48 62 5a 0c 81 88 ff ff 0?......HbZ.....
b0 ed 2e 1b 81 88 ff ff a8 64 5a 0c 81 88 ff ff .........dZ.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:278
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:626 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x370 lib/radix-tree.c:714
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae2716>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32f2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6dddf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6dddf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c5a66d8 (size 576):
comm "syz-executor.0", pid 5491, jiffies 4294944531 (age 12.550s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 90 64 5a 0c 81 88 ff ff *?.......dZ.....
b0 ed 2e 1b 81 88 ff ff f0 66 5a 0c 81 88 ff ff .........fZ.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:278
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:626 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x370 lib/radix-tree.c:714
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae2716>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32f2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6dddf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6dddf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=102f9bcae80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1369870ee80000

Edward Adam Davis

unread,
Dec 8, 2023, 11:40:31 PM12/8/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..f08f7ba7d2b1 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -911,6 +911,9 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
u32 type;
int rc;

+ if (!msg->msg_iter.count)
+ return -EINVAL;
+
if (msg->msg_flags & ~(MSG_DONTWAIT))
return -EINVAL;


syzbot

unread,
Dec 9, 2023, 12:17:05 AM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-and-tested-by: syzbot+006987...@syzkaller.appspotmail.com

Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=14433bdae80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=14de5e6ce80000

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

Edward Adam Davis

unread,
Dec 9, 2023, 1:52:56 AM12/9/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..3d06156fe913 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -275,6 +275,8 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
if (flow) {
init_waitqueue_head(&flow->resume_tx);
if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ printk("f: %p\n", flow);
+ radix_tree_delete(&node->qrtr_tx_flow, key);
kfree(flow);
flow = NULL;
}
@@ -287,10 +289,14 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
return 1;

spin_lock_irq(&flow->resume_tx.lock);
+ printk("to wait, f: %p, pd: %d, ff: %d, ep: %p\n",
+ flow, flow->pending, flow->failed, node->ep);
ret = wait_event_interruptible_locked_irq(flow->resume_tx,
flow->pending < QRTR_TX_FLOW_HIGH ||
flow->tx_failed ||
!node->ep);
+ printk("r: %d, f: %p, pd: %d, ff: %d, ep: %p\n",
+ ret, flow, flow->pending, flow->failed, node->ep);
if (ret < 0) {
confirm_rx = ret;
} else if (!node->ep) {
@@ -911,6 +917,9 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)

Edward Adam Davis

unread,
Dec 9, 2023, 1:53:18 AM12/9/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com

syzbot

unread,
Dec 9, 2023, 2:05:05 AM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

net/qrtr/af_qrtr.c:293:44: error: 'struct qrtr_tx_flow' has no member named 'failed'; did you mean 'tx_failed'?
net/qrtr/af_qrtr.c:299:49: error: 'struct qrtr_tx_flow' has no member named 'failed'; did you mean 'tx_failed'?


Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1508339ce80000

syzbot

unread,
Dec 9, 2023, 2:10:06 AM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com

Edward Adam Davis

unread,
Dec 9, 2023, 8:04:27 PM12/9/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..3d06156fe913 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -275,6 +275,8 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
if (flow) {
init_waitqueue_head(&flow->resume_tx);
if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ printk("f: %p\n", flow);
+ radix_tree_delete(&node->qrtr_tx_flow, key);
kfree(flow);
flow = NULL;
}
@@ -287,10 +289,14 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
return 1;

spin_lock_irq(&flow->resume_tx.lock);
+ printk("to wait, f: %p, pd: %d, ff: %d, ep: %p\n",
+ flow, flow->pending, flow->tx_failed, node->ep);
ret = wait_event_interruptible_locked_irq(flow->resume_tx,
flow->pending < QRTR_TX_FLOW_HIGH ||
flow->tx_failed ||
!node->ep);
+ printk("r: %d, f: %p, pd: %d, ff: %d, ep: %p\n",
+ ret, flow, flow->pending, flow->tx_failed, node->ep);

syzbot

unread,
Dec 9, 2023, 8:19:07 PM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in radix_tree_insert

BUG: memory leak
unreferenced object 0xffff88810e5afda8 (size 576):
comm "syz-executor.0", pid 5489, jiffies 4294944355 (age 12.710s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
70 ee 73 1b 81 88 ff ff c0 fd 5a 0e 81 88 ff ff p.s.......Z.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae108c>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae108c>] qrtr_node_enqueue+0x58c/0x660 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2746>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3322>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e5ec248 (size 576):
comm "syz-executor.0", pid 5489, jiffies 4294944355 (age 12.710s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 a8 fd 5a 0e 81 88 ff ff 6.........Z.....
70 ee 73 1b 81 88 ff ff 60 c2 5e 0e 81 88 ff ff p.s.....`.^.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae108c>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae108c>] qrtr_node_enqueue+0x58c/0x660 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2746>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3322>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e635488 (size 576):
comm "syz-executor.0", pid 5489, jiffies 4294944355 (age 12.710s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 48 c2 5e 0e 81 88 ff ff 0?......H.^.....
70 ee 73 1b 81 88 ff ff a0 54 63 0e 81 88 ff ff p.s......Tc.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae108c>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae108c>] qrtr_node_enqueue+0x58c/0x660 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2746>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3322>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e4fa000 (size 576):
comm "syz-executor.0", pid 5489, jiffies 4294944355 (age 12.710s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 88 54 63 0e 81 88 ff ff *?.......Tc.....
70 ee 73 1b 81 88 ff ff 18 a0 4f 0e 81 88 ff ff p.s.......O.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae108c>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae108c>] qrtr_node_enqueue+0x58c/0x660 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2746>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3322>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=15858332e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=15b888b6e80000

Edward Adam Davis

unread,
Dec 9, 2023, 10:52:23 PM12/9/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..4946a14b819d 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -273,11 +273,17 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
if (!flow) {
flow = kzalloc(sizeof(*flow), GFP_KERNEL);
if (flow) {
+ if (radix_tree_preload(GFP_KERNEL)) {
+ mutex_unlock(&node->qrtr_tx_lock);
+ return -ENOMEM;
+ }
init_waitqueue_head(&flow->resume_tx);
- if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ if (ret = radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ printk("r: %d\n", ret);
kfree(flow);
flow = NULL;
}
+ radix_tree_preload_end();
}
}
mutex_unlock(&node->qrtr_tx_lock);

syzbot

unread,
Dec 9, 2023, 11:08:08 PM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in radix_tree_insert

2023/12/10 04:02:40 executed programs: 1
BUG: memory leak
unreferenced object 0xffff88810e4ac248 (size 576):
comm "syz-executor.0", pid 5510, jiffies 4294944556 (age 13.040s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
30 3c 8d 1a 81 88 ff ff 60 c2 4a 0e 81 88 ff ff 0<......`.J.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae1012>] qrtr_tx_wait net/qrtr/af_qrtr.c:281 [inline]
[<ffffffff84ae1012>] qrtr_node_enqueue+0x512/0x6d0 net/qrtr/af_qrtr.c:354
[<ffffffff84ae27b6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3392>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e4ac000 (size 576):
comm "syz-executor.0", pid 5510, jiffies 4294944556 (age 13.040s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 48 c2 4a 0e 81 88 ff ff 6.......H.J.....
30 3c 8d 1a 81 88 ff ff 18 c0 4a 0e 81 88 ff ff 0<........J.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae1012>] qrtr_tx_wait net/qrtr/af_qrtr.c:281 [inline]
[<ffffffff84ae1012>] qrtr_node_enqueue+0x512/0x6d0 net/qrtr/af_qrtr.c:354
[<ffffffff84ae27b6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3392>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e4adda8 (size 576):
comm "syz-executor.0", pid 5510, jiffies 4294944556 (age 13.040s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 00 c0 4a 0e 81 88 ff ff 0?........J.....
30 3c 8d 1a 81 88 ff ff c0 dd 4a 0e 81 88 ff ff 0<........J.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae1012>] qrtr_tx_wait net/qrtr/af_qrtr.c:281 [inline]
[<ffffffff84ae1012>] qrtr_node_enqueue+0x512/0x6d0 net/qrtr/af_qrtr.c:354
[<ffffffff84ae27b6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3392>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810e4da000 (size 576):
comm "syz-executor.0", pid 5510, jiffies 4294944556 (age 13.040s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 a8 dd 4a 0e 81 88 ff ff *?........J.....
30 3c 8d 1a 81 88 ff ff 18 a0 4d 0e 81 88 ff ff 0<........M.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae1012>] qrtr_tx_wait net/qrtr/af_qrtr.c:281 [inline]
[<ffffffff84ae1012>] qrtr_node_enqueue+0x512/0x6d0 net/qrtr/af_qrtr.c:354
[<ffffffff84ae27b6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3392>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=1485aebce80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=10dfa02ae80000

Edward Adam Davis

unread,
Dec 9, 2023, 11:30:46 PM12/9/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..41a210e1d8b3 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -274,7 +274,8 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
flow = kzalloc(sizeof(*flow), GFP_KERNEL);
if (flow) {
init_waitqueue_head(&flow->resume_tx);
- if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ if (ret = radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ printk("r: %d\n", ret);
kfree(flow);
flow = NULL;
}
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index b98e9f2c24ac..522277bff6e3 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -413,6 +413,7 @@ static int radix_tree_extend(struct radix_tree_root *root, gfp_t gfp,
void *entry;
unsigned int maxshift;
int tag;
+ int i = 0;

/* Figure out what the shift should be. */
maxshift = shift;
@@ -428,6 +429,8 @@ static int radix_tree_extend(struct radix_tree_root *root, gfp_t gfp,
root, shift, 0, 1, 0);
if (!node)
return -ENOMEM;
+ i++;
+ printk("i: %d, n: %p, idx: %d, s: %d, %s\n", i, node, index, shift, __func__);

if (is_idr(root)) {
all_tag_set(node, IDR_FREE);
@@ -611,6 +614,7 @@ static int __radix_tree_create(struct radix_tree_root *root,
shift = radix_tree_load_root(root, &child, &maxindex);

/* Make sure the tree is high enough. */
+ printk("im: %d, s: %d, m: %d, %s\n", index, shift, maxindex, __func__);
if (max > maxindex) {
int error = radix_tree_extend(root, gfp, max, shift);
if (error < 0)
@@ -625,6 +629,7 @@ static int __radix_tree_create(struct radix_tree_root *root,
/* Have to add a child node. */
child = radix_tree_node_alloc(gfp, node, root, shift,
offset, 0, 0);
+ printk("c: %p, %s\n", child, __func__);
if (!child)
return -ENOMEM;
rcu_assign_pointer(*slot, node_to_entry(child));

syzbot

unread,
Dec 9, 2023, 11:48:04 PM12/9/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in radix_tree_insert

BUG: memory leak
unreferenced object 0xffff88810bad6db0 (size 576):
comm "syz-executor.0", pid 5766, jiffies 4294945919 (age 13.560s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
f0 b3 c9 1b 81 88 ff ff c8 6d ad 0b 81 88 ff ff .........m......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b5252b>] __radix_tree_create lib/radix-tree.c:628 [inline]
[<ffffffff84b5252b>] radix_tree_insert+0x16b/0x3a0 lib/radix-tree.c:717
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x640 net/qrtr/af_qrtr.c:349
[<ffffffff84ae2726>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:892
[<ffffffff84ae3302>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:993
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de4f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de4f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c246000 (size 576):
comm "syz-executor.0", pid 5766, jiffies 4294945920 (age 13.550s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 b0 6d ad 0b 81 88 ff ff 6........m......
f0 b3 c9 1b 81 88 ff ff 18 60 24 0c 81 88 ff ff .........`$.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b5252b>] __radix_tree_create lib/radix-tree.c:628 [inline]
[<ffffffff84b5252b>] radix_tree_insert+0x16b/0x3a0 lib/radix-tree.c:717
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x640 net/qrtr/af_qrtr.c:349
[<ffffffff84ae2726>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:892
[<ffffffff84ae3302>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:993
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de4f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de4f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c246248 (size 576):
comm "syz-executor.0", pid 5766, jiffies 4294945921 (age 13.540s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 00 60 24 0c 81 88 ff ff 0?.......`$.....
f0 b3 c9 1b 81 88 ff ff 60 62 24 0c 81 88 ff ff ........`b$.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b5252b>] __radix_tree_create lib/radix-tree.c:628 [inline]
[<ffffffff84b5252b>] radix_tree_insert+0x16b/0x3a0 lib/radix-tree.c:717
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x640 net/qrtr/af_qrtr.c:349
[<ffffffff84ae2726>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:892
[<ffffffff84ae3302>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:993
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de4f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de4f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810c246490 (size 576):
comm "syz-executor.0", pid 5766, jiffies 4294945921 (age 13.540s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 48 62 24 0c 81 88 ff ff *?......Hb$.....
f0 b3 c9 1b 81 88 ff ff a8 64 24 0c 81 88 ff ff .........d$.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b5252b>] __radix_tree_create lib/radix-tree.c:628 [inline]
[<ffffffff84b5252b>] radix_tree_insert+0x16b/0x3a0 lib/radix-tree.c:717
[<ffffffff84ae107d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae107d>] qrtr_node_enqueue+0x57d/0x640 net/qrtr/af_qrtr.c:349
[<ffffffff84ae2726>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:892
[<ffffffff84ae3302>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:993
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de4f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de4f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=151b7d6ce80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1242ef32e80000

Edward Adam Davis

unread,
Dec 10, 2023, 12:14:34 AM12/10/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..3615a9f35bbb 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -267,6 +267,9 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
/* Never set confirm_rx on non-data packets */
if (type != QRTR_TYPE_DATA)
return 0;
+ printk("dn: %d, dp: %d, %s\n", dest_node, dest_port, type, __func__);
+ if (dest_node < 0)
+ return -EINVAL;

mutex_lock(&node->qrtr_tx_lock);
flow = radix_tree_lookup(&node->qrtr_tx_flow, key);

syzbot

unread,
Dec 10, 2023, 12:39:09 AM12/10/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

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

Reported-and-tested-by: syzbot+006987...@syzkaller.appspotmail.com

Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=113d92bce80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=11778c96e80000

Edward Adam Davis

unread,
Dec 10, 2023, 1:07:04 AM12/10/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
please test memory leak in radix_tree_insert

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/include/linux/radix-tree.h b/include/linux/radix-tree.h
index eae67015ce51..cc3e9fc7bae0 100644
--- a/include/linux/radix-tree.h
+++ b/include/linux/radix-tree.h
@@ -254,6 +254,7 @@ unsigned int radix_tree_gang_lookup_tag_slot(const struct radix_tree_root *,
void __rcu ***results, unsigned long first_index,
unsigned int max_items, unsigned int tag);
int radix_tree_tagged(const struct radix_tree_root *, unsigned int tag);
+unsigned long radix_tree_maxindex(const struct radix_tree_root *root);

static inline void radix_tree_preload_end(void)
{
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index b98e9f2c24ac..a89df8afa510 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -404,6 +404,18 @@ static unsigned radix_tree_load_root(const struct radix_tree_root *root,
return 0;
}

+unsigned long radix_tree_maxindex(const struct radix_tree_root *root)
+{
+ struct radix_tree_node *node = rcu_dereference_raw(root->xa_head);
+
+ if (likely(radix_tree_is_internal_node(node))) {
+ node = entry_to_node(node);
+ return node_maxindex(node);
+ }
+
+ return 0;
+}
+
/*
* Extend a radix tree so it can store key @index.
*/
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 41ece61eb57a..abdae567a370 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -344,6 +344,12 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
struct qrtr_hdr_v1 *hdr;
size_t len = skb->len;
int rc, confirm_rx;
+ unsigned long maxidx;
+
+ if (to->sq_node == QRTR_NODE_BCAST) {
+ maxidx = radix_tree_maxindex(&node->qrtr_tx_flow);
+ to->sq_node = maxidx + 1;
+ }

confirm_rx = qrtr_tx_wait(node, to->sq_node, to->sq_port, type);
if (confirm_rx < 0) {

syzbot

unread,
Dec 10, 2023, 1:30:05 AM12/10/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in radix_tree_insert

2023/12/10 06:24:31 executed programs: 3
BUG: memory leak
unreferenced object 0xffff88810dca76d0 (size 576):
comm "syz-executor.0", pid 5751, jiffies 4294945011 (age 13.020s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
30 76 57 0c 81 88 ff ff e8 76 ca 0d 81 88 ff ff 0vW......v......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10b8>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10b8>] qrtr_node_enqueue+0x5b8/0x670 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2756>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3332>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810dca66d8 (size 576):
comm "syz-executor.0", pid 5751, jiffies 4294945011 (age 13.020s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 d0 76 ca 0d 81 88 ff ff 6........v......
30 76 57 0c 81 88 ff ff f0 66 ca 0d 81 88 ff ff 0vW......f......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10b8>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10b8>] qrtr_node_enqueue+0x5b8/0x670 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2756>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3332>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810dd0f488 (size 576):
comm "syz-executor.0", pid 5751, jiffies 4294945011 (age 13.020s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 d8 66 ca 0d 81 88 ff ff 0?.......f......
30 76 57 0c 81 88 ff ff a0 f4 d0 0d 81 88 ff ff 0vW.............
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10b8>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10b8>] qrtr_node_enqueue+0x5b8/0x670 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2756>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3332>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff8881005e0000 (size 576):
comm "syz-executor.0", pid 5751, jiffies 4294945011 (age 13.020s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 88 f4 d0 0d 81 88 ff ff *?..............
30 76 57 0c 81 88 ff ff 18 00 5e 00 81 88 ff ff 0vW.......^.....
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10b8>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10b8>] qrtr_node_enqueue+0x5b8/0x670 net/qrtr/af_qrtr.c:354
[<ffffffff84ae2756>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:897
[<ffffffff84ae3332>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:998
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=17e587dae80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1626d7eee80000

Edward Adam Davis

unread,
Dec 10, 2023, 1:58:26 AM12/10/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
@@ -274,7 +274,8 @@ static int qrtr_tx_wait(struct qrtr_node *node, int dest_node, int dest_port,
flow = kzalloc(sizeof(*flow), GFP_KERNEL);
if (flow) {
init_waitqueue_head(&flow->resume_tx);
- if (radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ if (ret = radix_tree_insert(&node->qrtr_tx_flow, key, flow)) {
+ printk("r: %d, k: %llu, f: %p, %s\n", ret, key, flow, __func__);
kfree(flow);
flow = NULL;
}
@@ -344,6 +344,13 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
struct qrtr_hdr_v1 *hdr;
size_t len = skb->len;
int rc, confirm_rx;
+ unsigned long maxidx;
+
+ if (to->sq_node == QRTR_NODE_BCAST) {
+ maxidx = radix_tree_maxindex(&node->qrtr_tx_flow);
+ to->sq_node = maxidx + 1;
+ printk("mi: %llu, sn: %llu, %s\n", maxidx, to->sq_node, __func__);

syzbot

unread,
Dec 10, 2023, 3:13:06 AM12/10/23
to ead...@qq.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
memory leak in radix_tree_insert

2023/12/10 08:04:23 executed programs: 3
BUG: memory leak
unreferenced object 0xffff88810b920000 (size 576):
comm "syz-executor.0", pid 5753, jiffies 4294945520 (age 13.500s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
30 79 97 0c 81 88 ff ff 18 00 92 0b 81 88 ff ff 0y..............
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10d0>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10d0>] qrtr_node_enqueue+0x5d0/0x6a0 net/qrtr/af_qrtr.c:356
[<ffffffff84ae2786>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:899
[<ffffffff84ae3362>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:1000
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810b920248 (size 576):
comm "syz-executor.0", pid 5753, jiffies 4294945520 (age 13.500s)
hex dump (first 32 bytes):
36 0f 01 00 00 00 00 00 00 00 92 0b 81 88 ff ff 6...............
30 79 97 0c 81 88 ff ff 60 02 92 0b 81 88 ff ff 0y......`.......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10d0>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10d0>] qrtr_node_enqueue+0x5d0/0x6a0 net/qrtr/af_qrtr.c:356
[<ffffffff84ae2786>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:899
[<ffffffff84ae3362>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:1000
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810b920490 (size 576):
comm "syz-executor.0", pid 5753, jiffies 4294945520 (age 13.500s)
hex dump (first 32 bytes):
30 3f 01 00 00 00 00 00 48 02 92 0b 81 88 ff ff 0?......H.......
30 79 97 0c 81 88 ff ff a8 04 92 0b 81 88 ff ff 0y..............
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10d0>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10d0>] qrtr_node_enqueue+0x5d0/0x6a0 net/qrtr/af_qrtr.c:356
[<ffffffff84ae2786>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:899
[<ffffffff84ae3362>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:1000
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

BUG: memory leak
unreferenced object 0xffff88810b9206d8 (size 576):
comm "syz-executor.0", pid 5753, jiffies 4294945520 (age 13.500s)
hex dump (first 32 bytes):
2a 3f 00 00 00 00 00 00 90 04 92 0b 81 88 ff ff *?..............
30 79 97 0c 81 88 ff ff f0 06 92 0b 81 88 ff ff 0y..............
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:636 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:724
[<ffffffff84ae10d0>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae10d0>] qrtr_node_enqueue+0x5d0/0x6a0 net/qrtr/af_qrtr.c:356
[<ffffffff84ae2786>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:899
[<ffffffff84ae3362>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:1000
[<ffffffff83ec3c42>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c42>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d8b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6de2f>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6de2f>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b



Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=120e98b2e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=13605feee80000

Lizhi Xu

unread,
Dec 10, 2023, 11:24:49 PM12/10/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index a89df8afa510..0a2dfecdcd30 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -613,12 +613,13 @@ static int __radix_tree_create(struct radix_tree_root *root,
unsigned long index, struct radix_tree_node **nodep,
void __rcu ***slotp)
{
- struct radix_tree_node *node = NULL, *child;
+ struct radix_tree_node *node = NULL, *child, *orig;
void __rcu **slot = (void __rcu **)&root->xa_head;
unsigned long maxindex;
- unsigned int shift, offset = 0;
+ unsigned int shift, offset = 0, mmshift = 0;
unsigned long max = index;
gfp_t gfp = root_gfp_mask(root);
+ int ret;

shift = radix_tree_load_root(root, &child, &maxindex);

@@ -628,7 +629,9 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (error < 0)
return error;
shift = error;
+ mmshift = error;
child = rcu_dereference_raw(root->xa_head);
+ orig = child;
}

while (shift > 0) {
@@ -637,8 +640,11 @@ static int __radix_tree_create(struct radix_tree_root *root,
/* Have to add a child node. */
child = radix_tree_node_alloc(gfp, node, root, shift,
offset, 0, 0);
- if (!child)
- return -ENOMEM;
+ printk("nc: %p\n", child);
+ if (!child) {
+ ret = -ENOMEM;
+ goto freec;
+ }
rcu_assign_pointer(*slot, node_to_entry(child));
if (node)
node->count++;
@@ -656,6 +662,18 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (slotp)
*slotp = slot;
return 0;
+freec:
+ if (mmshift > 0) {
+ struct radix_tree_node *dn;
+ while (shift < mmshift) {
+ radix_tree_descend(orig, &dn, index);
+ printk("dc: %p\n", dn);
+ orig = orig->slots[0];
+ radix_tree_node_rcu_free(&dn->rcu_head);
+ shift += RADIX_TREE_MAP_SHIFT;
+ }
+ }
+ return ret;
}

/*

syzbot

unread,
Dec 10, 2023, 11:41:07 PM12/10/23
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:
BUG: unable to handle kernel NULL pointer dereference in radix_tree_insert

RBP: 00007fe1bdd63120 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002
R13: 000000000000000b R14: 00007fe1bd19bf80 R15: 00007ffff40ae278
</TASK>
nc: 0000000000000000
BUG: kernel NULL pointer dereference, address: 0000000000000000
#PF: supervisor read access in kernel mode
#PF: error_code(0x0000) - not-present page
PGD 11abdb067 P4D 11abdb067 PUD 11a311067 PMD 0
Oops: 0000 [#1] PREEMPT SMP
CPU: 0 PID: 5752 Comm: syz-executor.0 Not tainted 6.7.0-rc4-syzkaller-dirty #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/10/2023
RIP: 0010:radix_tree_descend lib/radix-tree.c:88 [inline]
RIP: 0010:__radix_tree_create lib/radix-tree.c:655 [inline]
RIP: 0010:radix_tree_insert+0x379/0x400 lib/radix-tree.c:730
Code: ba 89 fc 89 de 44 89 ef e8 54 b3 89 fc 41 39 dd 73 6e e8 ea ba 89 fc 4c 8b 7c 24 10 4c 89 f0 41 83 c5 06 48 c7 c7 b5 cf a7 85 <41> 0f b6 0f 48 d3 e8 83 e0 3f 48 83 c0 04 49 8b 5c c7 08 48 89 de
RSP: 0018:ffffc900049d3c18 EFLAGS: 00010202
RAX: fffffffffffffffe RBX: 0000000000000042 RCX: ffffffff84b526dc
RDX: ffff888106cc0000 RSI: ffffffff84b526e6 RDI: ffffffff85a7cfb5
RBP: 000000000000003f R08: 0000000000000004 R09: 0000000000000024
R10: 0000000000000042 R11: 205d323537355420 R12: ffff88810b7746d8
R13: 000000000000002a R14: fffffffffffffffe R15: 0000000000000000
FS: 00007fe1bdd636c0(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000011ae79000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
<TASK>
qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
sock_sendmsg_nosec net/socket.c:730 [inline]
__sock_sendmsg+0x52/0xa0 net/socket.c:745
sock_write_iter+0xfb/0x180 net/socket.c:1158
call_write_iter include/linux/fs.h:2020 [inline]
new_sync_write fs/read_write.c:491 [inline]
vfs_write+0x327/0x590 fs/read_write.c:584
ksys_write+0x13b/0x170 fs/read_write.c:637
do_syscall_x64 arch/x86/entry/common.c:51 [inline]
do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
entry_SYSCALL_64_after_hwframe+0x63/0x6b
RIP: 0033:0x7fe1bd07cae9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 00 00 90 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fe1bdd630c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007fe1bd19bf80 RCX: 00007fe1bd07cae9
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000004
RBP: 00007fe1bdd63120 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000002
R13: 000000000000000b R14: 00007fe1bd19bf80 R15: 00007ffff40ae278
</TASK>
Modules linked in:
CR2: 0000000000000000
---[ end trace 0000000000000000 ]---
RIP: 0010:radix_tree_descend lib/radix-tree.c:88 [inline]
RIP: 0010:__radix_tree_create lib/radix-tree.c:655 [inline]
RIP: 0010:radix_tree_insert+0x379/0x400 lib/radix-tree.c:730
Code: ba 89 fc 89 de 44 89 ef e8 54 b3 89 fc 41 39 dd 73 6e e8 ea ba 89 fc 4c 8b 7c 24 10 4c 89 f0 41 83 c5 06 48 c7 c7 b5 cf a7 85 <41> 0f b6 0f 48 d3 e8 83 e0 3f 48 83 c0 04 49 8b 5c c7 08 48 89 de
RSP: 0018:ffffc900049d3c18 EFLAGS: 00010202
RAX: fffffffffffffffe RBX: 0000000000000042 RCX: ffffffff84b526dc
RDX: ffff888106cc0000 RSI: ffffffff84b526e6 RDI: ffffffff85a7cfb5
RBP: 000000000000003f R08: 0000000000000004 R09: 0000000000000024
R10: 0000000000000042 R11: 205d323537355420 R12: ffff88810b7746d8
R13: 000000000000002a R14: fffffffffffffffe R15: 0000000000000000
FS: 00007fe1bdd636c0(0000) GS:ffff88813bc00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 000000011ae79000 CR4: 00000000003506f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
----------------
Code disassembly (best guess):
0: ba 89 fc 89 de mov $0xde89fc89,%edx
5: 44 89 ef mov %r13d,%edi
8: e8 54 b3 89 fc call 0xfc89b361
d: 41 39 dd cmp %ebx,%r13d
10: 73 6e jae 0x80
12: e8 ea ba 89 fc call 0xfc89bb01
17: 4c 8b 7c 24 10 mov 0x10(%rsp),%r15
1c: 4c 89 f0 mov %r14,%rax
1f: 41 83 c5 06 add $0x6,%r13d
23: 48 c7 c7 b5 cf a7 85 mov $0xffffffff85a7cfb5,%rdi
* 2a: 41 0f b6 0f movzbl (%r15),%ecx <-- trapping instruction
2e: 48 d3 e8 shr %cl,%rax
31: 83 e0 3f and $0x3f,%eax
34: 48 83 c0 04 add $0x4,%rax
38: 49 8b 5c c7 08 mov 0x8(%r15,%rax,8),%rbx
3d: 48 89 de mov %rbx,%rsi


Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=1263f02ae80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=14707d0ae80000

Lizhi Xu

unread,
Dec 11, 2023, 12:15:46 AM12/11/23
to syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 33cc938e65a9

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index a89df8afa510..301a8c01816a 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -613,12 +613,13 @@ static int __radix_tree_create(struct radix_tree_root *root,
unsigned long index, struct radix_tree_node **nodep,
void __rcu ***slotp)
{
- struct radix_tree_node *node = NULL, *child;
+ struct radix_tree_node *node = NULL, *child, *orig;
void __rcu **slot = (void __rcu **)&root->xa_head;
unsigned long maxindex;
- unsigned int shift, offset = 0;
+ unsigned int shift, offset = 0, mmshift = 0;
unsigned long max = index;
gfp_t gfp = root_gfp_mask(root);
+ int ret;

shift = radix_tree_load_root(root, &child, &maxindex);

@@ -628,6 +629,7 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (error < 0)
return error;
shift = error;
+ mmshift = error;
child = rcu_dereference_raw(root->xa_head);
}

@@ -637,8 +639,11 @@ static int __radix_tree_create(struct radix_tree_root *root,
/* Have to add a child node. */
child = radix_tree_node_alloc(gfp, node, root, shift,
offset, 0, 0);
- if (!child)
- return -ENOMEM;
+ printk("nc: %p\n", child);
+ if (!child) {
+ ret = -ENOMEM;
+ goto freec;
+ }
rcu_assign_pointer(*slot, node_to_entry(child));
if (node)
node->count++;
@@ -656,6 +661,18 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (slotp)
*slotp = slot;
return 0;
+freec:
+ if (mmshift > 0) {
+ struct radix_tree_node *pn;
+ while (shift < mmshift && node) {
+ printk("dc: %p\n", node);
+ pn = node->parent;
+ radix_tree_node_rcu_free(&node->rcu_head);
+ shift += RADIX_TREE_MAP_SHIFT;
+ node = pn;

syzbot

unread,
Dec 11, 2023, 12:52:05 AM12/11/23
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-and-tested-by: syzbot+006987...@syzkaller.appspotmail.com

Tested on:

commit: 33cc938e Linux 6.7-rc4
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=10325ab6e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=37d1b8bb20150e6
dashboard link: https://syzkaller.appspot.com/bug?extid=006987d1be3586e13555
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=1654f06ce80000

Lizhi Xu

unread,
Dec 11, 2023, 4:48:48 AM12/11/23
to syzbot+006987...@syzkaller.appspotmail.com, da...@davemloft.net, edum...@google.com, ku...@kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, ma...@kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com
[Syz report]
BUG: memory leak
unreferenced object 0xffff88810bbf56d8 (size 576):
comm "syz-executor250", pid 5051, jiffies 4294951219 (age 12.920s)
hex dump (first 32 bytes):
3c 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 <...............
f0 a9 2d 0c 81 88 ff ff f0 56 bf 0b 81 88 ff ff ..-......V......
backtrace:
[<ffffffff81631398>] kmemleak_alloc_recursive include/linux/kmemleak.h:42 [inline]
[<ffffffff81631398>] slab_post_alloc_hook mm/slab.h:766 [inline]
[<ffffffff81631398>] slab_alloc_node mm/slub.c:3478 [inline]
[<ffffffff81631398>] slab_alloc mm/slub.c:3486 [inline]
[<ffffffff81631398>] __kmem_cache_alloc_lru mm/slub.c:3493 [inline]
[<ffffffff81631398>] kmem_cache_alloc+0x298/0x430 mm/slub.c:3502
[<ffffffff84b5094c>] radix_tree_node_alloc.constprop.0+0x7c/0x1a0 lib/radix-tree.c:276
[<ffffffff84b524cf>] __radix_tree_create lib/radix-tree.c:624 [inline]
[<ffffffff84b524cf>] radix_tree_insert+0x14f/0x360 lib/radix-tree.c:712
[<ffffffff84ae105d>] qrtr_tx_wait net/qrtr/af_qrtr.c:277 [inline]
[<ffffffff84ae105d>] qrtr_node_enqueue+0x57d/0x630 net/qrtr/af_qrtr.c:348
[<ffffffff84ae26f6>] qrtr_bcast_enqueue+0x66/0xd0 net/qrtr/af_qrtr.c:891
[<ffffffff84ae32d2>] qrtr_sendmsg+0x232/0x450 net/qrtr/af_qrtr.c:992
[<ffffffff83ec3c32>] sock_sendmsg_nosec net/socket.c:730 [inline]
[<ffffffff83ec3c32>] __sock_sendmsg+0x52/0xa0 net/socket.c:745
[<ffffffff83ec3d7b>] sock_write_iter+0xfb/0x180 net/socket.c:1158
[<ffffffff816961a7>] call_write_iter include/linux/fs.h:2020 [inline]
[<ffffffff816961a7>] new_sync_write fs/read_write.c:491 [inline]
[<ffffffff816961a7>] vfs_write+0x327/0x590 fs/read_write.c:584
[<ffffffff816966fb>] ksys_write+0x13b/0x170 fs/read_write.c:637
[<ffffffff84b6ddcf>] do_syscall_x64 arch/x86/entry/common.c:51 [inline]
[<ffffffff84b6ddcf>] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82
[<ffffffff84c0008b>] entry_SYSCALL_64_after_hwframe+0x63/0x6b

[Analysis]
When creating child nodes, if not all child nodes used to store indexes are created,
so the child nodes created before the failure should be released.

Reported-and-tested-by: syzbot+006987...@syzkaller.appspotmail.com
Signed-off-by: Lizhi Xu <lizh...@windriver.com>
---
lib/radix-tree.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index a89df8afa510..c5caf5b7523a 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -616,9 +616,10 @@ static int __radix_tree_create(struct radix_tree_root *root,
struct radix_tree_node *node = NULL, *child;
void __rcu **slot = (void __rcu **)&root->xa_head;
unsigned long maxindex;
- unsigned int shift, offset = 0;
+ unsigned int shift, offset = 0, mmshift = 0;
unsigned long max = index;
gfp_t gfp = root_gfp_mask(root);
+ int ret;

shift = radix_tree_load_root(root, &child, &maxindex);

@@ -628,6 +629,7 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (error < 0)
return error;
shift = error;
+ mmshift = error;
child = rcu_dereference_raw(root->xa_head);
}

@@ -637,8 +639,10 @@ static int __radix_tree_create(struct radix_tree_root *root,
/* Have to add a child node. */
child = radix_tree_node_alloc(gfp, node, root, shift,
offset, 0, 0);
- if (!child)
- return -ENOMEM;
+ if (!child) {
+ ret = -ENOMEM;
+ goto freec;
+ }
rcu_assign_pointer(*slot, node_to_entry(child));
if (node)
node->count++;
@@ -656,6 +660,17 @@ static int __radix_tree_create(struct radix_tree_root *root,
if (slotp)
*slotp = slot;
return 0;
+freec:
+ if (mmshift > 0) {
+ struct radix_tree_node *pn;
+ while (shift < mmshift && node) {
+ pn = node->parent;
+ radix_tree_node_rcu_free(&node->rcu_head);
+ shift += RADIX_TREE_MAP_SHIFT;
+ node = pn;
+ }
+ }
+ return ret;
}

/*
--
2.43.0

kernel test robot

unread,
Dec 11, 2023, 6:17:17 PM12/11/23
to Lizhi Xu, syzbot+006987...@syzkaller.appspotmail.com, oe-kbu...@lists.linux.dev, da...@davemloft.net, edum...@google.com, ku...@kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, ma...@kernel.org, net...@vger.kernel.org, pab...@redhat.com, syzkall...@googlegroups.com
Hi Lizhi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on akpm-mm/mm-nonmm-unstable]
[also build test WARNING on linus/master v6.7-rc5 next-20231211]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Lizhi-Xu/radix-tree-fix-memory-leak-in-radix_tree_insert/20231211-174951
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-nonmm-unstable
patch link: https://lore.kernel.org/r/20231211094840.642118-1-lizhi.xu%40windriver.com
patch subject: [PATCH] radix-tree: fix memory leak in radix_tree_insert
config: i386-randconfig-061-20231212 (https://download.01.org/0day-ci/archive/20231212/202312120651...@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231212/202312120651...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <l...@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312120651...@intel.com/

sparse warnings: (new ones prefixed by >>)
lib/radix-tree.c:266:36: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *nodes @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:266:36: sparse: expected struct xa_node *nodes
lib/radix-tree.c:266:36: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:284:29: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node [noderef] __rcu *parent @@ got struct xa_node *parent @@
lib/radix-tree.c:284:29: sparse: expected struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:284:29: sparse: got struct xa_node *parent
lib/radix-tree.c:344:38: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node [noderef] __rcu *parent @@ got struct xa_node *nodes @@
lib/radix-tree.c:344:38: sparse: expected struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:344:38: sparse: got struct xa_node *nodes
lib/radix-tree.c:446:54: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node [noderef] __rcu *parent @@ got struct xa_node *node @@
lib/radix-tree.c:446:54: sparse: expected struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:446:54: sparse: got struct xa_node *node
lib/radix-tree.c:558:24: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *parent @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:558:24: sparse: expected struct xa_node *parent
lib/radix-tree.c:558:24: sparse: got struct xa_node [noderef] __rcu *parent
>> lib/radix-tree.c:653:28: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *pn @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:653:28: sparse: expected struct xa_node *pn
lib/radix-tree.c:653:28: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:687:31: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *[assigned] child @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:687:31: sparse: expected struct xa_node *[assigned] child
lib/radix-tree.c:687:31: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:962:22: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *node @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:962:22: sparse: expected struct xa_node *node
lib/radix-tree.c:962:22: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:1022:22: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *node @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:1022:22: sparse: expected struct xa_node *node
lib/radix-tree.c:1022:22: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:1542:38: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *[assigned] node @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:1542:38: sparse: expected struct xa_node *[assigned] node
lib/radix-tree.c:1542:38: sparse: got struct xa_node [noderef] __rcu *parent
lib/radix-tree.c:1602:28: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *nodes @@ got struct xa_node [noderef] __rcu *parent @@
lib/radix-tree.c:1602:28: sparse: expected struct xa_node *nodes
lib/radix-tree.c:1602:28: sparse: got struct xa_node [noderef] __rcu *parent

vim +653 lib/radix-tree.c

581
582 /**
583 * __radix_tree_create - create a slot in a radix tree
584 * @root: radix tree root
585 * @index: index key
586 * @nodep: returns node
587 * @slotp: returns slot
588 *
589 * Create, if necessary, and return the node and slot for an item
590 * at position @index in the radix tree @root.
591 *
592 * Until there is more than one item in the tree, no nodes are
593 * allocated and @root->xa_head is used as a direct slot instead of
594 * pointing to a node, in which case *@nodep will be NULL.
595 *
596 * Returns -ENOMEM, or 0 for success.
597 */
598 static int __radix_tree_create(struct radix_tree_root *root,
599 unsigned long index, struct radix_tree_node **nodep,
600 void __rcu ***slotp)
601 {
602 struct radix_tree_node *node = NULL, *child;
603 void __rcu **slot = (void __rcu **)&root->xa_head;
604 unsigned long maxindex;
605 unsigned int shift, offset = 0, mmshift = 0;
606 unsigned long max = index;
607 gfp_t gfp = root_gfp_mask(root);
608 int ret;
609
610 shift = radix_tree_load_root(root, &child, &maxindex);
611
612 /* Make sure the tree is high enough. */
613 if (max > maxindex) {
614 int error = radix_tree_extend(root, gfp, max, shift);
615 if (error < 0)
616 return error;
617 shift = error;
618 mmshift = error;
619 child = rcu_dereference_raw(root->xa_head);
620 }
621
622 while (shift > 0) {
623 shift -= RADIX_TREE_MAP_SHIFT;
624 if (child == NULL) {
625 /* Have to add a child node. */
626 child = radix_tree_node_alloc(gfp, node, root, shift,
627 offset, 0, 0);
628 if (!child) {
629 ret = -ENOMEM;
630 goto freec;
631 }
632 rcu_assign_pointer(*slot, node_to_entry(child));
633 if (node)
634 node->count++;
635 } else if (!radix_tree_is_internal_node(child))
636 break;
637
638 /* Go a level down */
639 node = entry_to_node(child);
640 offset = radix_tree_descend(node, &child, index);
641 slot = &node->slots[offset];
642 }
643
644 if (nodep)
645 *nodep = node;
646 if (slotp)
647 *slotp = slot;
648 return 0;
649 freec:
650 if (mmshift > 0) {
651 struct radix_tree_node *pn;
652 while (shift < mmshift && node) {
> 653 pn = node->parent;
654 radix_tree_node_rcu_free(&node->rcu_head);
655 shift += RADIX_TREE_MAP_SHIFT;
656 node = pn;
657 }
658 }
659 return ret;
660 }
661

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

Lizhi Xu

unread,
Dec 12, 2023, 10:25:14 PM12/12/23
to l...@intel.com, da...@davemloft.net, edum...@google.com, ku...@kernel.org, linux-...@vger.kernel.org, linux-...@vger.kernel.org, lizh...@windriver.com, ma...@kernel.org, net...@vger.kernel.org, oe-kbu...@lists.linux.dev, pab...@redhat.com, syzbot+006987...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
On Tue, 12 Dec 2023 07:16:50 +0800, kernel test robot <l...@intel.com> wrote:
> kernel test robot noticed the following build warnings:
> lib/radix-tree.c:558:24: sparse: got struct xa_node [noderef] __rcu *parent
> >> lib/radix-tree.c:653:28: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct xa_node *pn @@ got struct xa_node [noderef] __rcu *parent @@
> lib/radix-tree.c:653:28: sparse: expected struct xa_node *pn
> 651 struct radix_tree_node *pn;
> 652 while (shift < mmshift && node) {
> > 653 pn = node->parent;
It can be clarified here that node->parent is the type just alloced as
"struct radix_tree node *", so there is no need to use cast type conversion,
Please ignore this warning.

BR,
Lizhi

Reply all
Reply to author
Forward
0 new messages