| 0/0 |
2026/01/28 22:41 |
flow |
patching |
29m
Results: map[KernelCommit:v6.19-rc7 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:net/netrom: Fix use-after-free in nr_dec_obs
A use-after-free occurs in nr_dec_obs() when a neighbor's reference
count is decremented and the object is freed before its 'count' and
'locked' fields are accessed.
The function nr_dec_obs() calls nr_neigh_put() before checking
nr_neigh->count and nr_neigh->locked. If nr_neigh_put() drops the
last reference, the object is freed, causing a UAF on the subsequent
access.
To fix this, move the nr_neigh_put() call after the field accesses.
However, simply moving the call reveals a potential issue in
nr_remove_neigh(). This function unconditionally calls nr_neigh_put()
under the assumption that it is removing the node from the list and
consuming the list's reference. If the node is not in the list (unhashed),
nr_remove_neigh() would incorrectly drop a reference it does not hold,
leading to a potential double-free when nr_neigh_put() is called again
in nr_dec_obs().
Modify __nr_remove_neigh() to check hlist_unhashed() and only remove the
node and drop the reference if it is actually hashed. This ensures
nr_remove_neigh() is safe to call on unhashed nodes and prevents
refcount underflows. PatchDiff:diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 9cc29ae85..496b328d1 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -295,6 +295,8 @@ static void nr_remove_node_locked(struct nr_node *nr_node)
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
+ if (hlist_unhashed(&nr_neigh->neigh_node))
+ return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
@@ -462,16 +464,17 @@ static int nr_dec_obs(void)
case 0: /* A locked entry */
break;
- case 1: /* From 1 -> 0 */
- nr_neigh = s->routes[i].neighbour;
+ case 1: /* From 1 -> 0 */
+ nr_neigh = s->routes[i].neighbour;
- nr_neigh->count--;
- nr_neigh_put(nr_neigh);
+ nr_neigh->count--;
+
+ if (nr_neigh->count == 0 && !nr_neigh->locked)
+ nr_remove_neigh(nr_neigh);
- if (nr_neigh->count == 0 && !nr_neigh->locked)
- nr_remove_neigh(nr_neigh);
+ nr_neigh_put(nr_neigh);
- s->count--;
+ s->count--;
switch (i) {
case 0:
Recipients:[map[Email:davem@davemloft.net Name:David S. Miller To:true] map[Email:edumazet@google.com Name:Eric Dumazet To:true] map[Email:horms@kernel.org Name:Simon Horman To:false] map[Email:kuba@kernel.org Name:Jakub Kicinski To:true] map[Email:linux-hams@vger.kernel.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:netdev@vger.kernel.org Name: To:true] map[Email:pabeni@redhat.com Name:Paolo Abeni To:true]]]
|
| 1/1 |
2026/01/28 22:41 |
action |
base-commit-picker |
0m
Results: map[KernelCommit:v6.19-rc7 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/01/28 22:41 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/src/5452af61ab2e1f5601403fe379188fc9d8a831af]
|
| 3/1 |
2026/01/28 22:41 |
action |
kernel-builder |
5m
Results: map[KernelObj:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/build/60b9d4796ca9a421a68f610e53e8e9b46ff002fd]
|
| 4/1 |
2026/01/28 22:47 |
action |
crash-reproducer |
1m
Results: map[BugTitle:KASAN: slab-use-after-free Read in nr_rt_ioctl CrashReport:==================================================================
BUG: KASAN: slab-use-after-free in nr_dec_obs net/netrom/nr_route.c:471 [inline]
BUG: KASAN: slab-use-after-free in nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
Read of size 2 at addr ffff888048ccf732 by task syz-executor102/6284
CPU: 1 UID: 0 PID: 6284 Comm: syz-executor102 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x10e/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x17e/0x810 mm/kasan/report.c:482
kasan_report+0x147/0x180 mm/kasan/report.c:595
nr_dec_obs net/netrom/nr_route.c:471 [inline]
nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb502ddcd39
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd784c5ad8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fb502ddcd39
RDX: 0000000000000000 RSI: 00000000000089e2 RDI: 0000000000000005
RBP: 0000000000000000 R08: 00007fb502e4123c R09: 00007fb502e4123c
R10: 00007fb502e4123c R11: 0000000000000246 R12: 00007ffd784c5afc
R13: 00007ffd784c5b30 R14: 00007ffd784c5b10 R15: 0000000000000012
</TASK>
Allocated by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x3e2/0x700 mm/slub.c:5780
kmalloc_noprof include/linux/slab.h:957 [inline]
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
nr_rt_ioctl+0xbfb/0xd20 net/netrom/nr_route.c:651
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x58/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2540 [inline]
slab_free mm/slub.c:6674 [inline]
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
nr_rt_ioctl+0x2e7/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888048ccf700
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 50 bytes inside of
freed 64-byte region [ffff888048ccf700, ffff888048ccf740)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48ccf
anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff88801a0418c0 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5509, tgid 5509 (dhcpcd-run-hook), ts 35445032815, free_ts 35417982511
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x234/0x290 mm/page_alloc.c:1884
prep_new_page mm/page_alloc.c:1892 [inline]
get_page_from_freelist+0x24d5/0x2570 mm/page_alloc.c:3945
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5240
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2486
alloc_slab_page mm/slub.c:3075 [inline]
allocate_slab+0x86/0x3b0 mm/slub.c:3248
new_slab mm/slub.c:3302 [inline]
___slab_alloc+0xe70/0x1860 mm/slub.c:4656
__slab_alloc+0x65/0x100 mm/slub.c:4779
__slab_alloc_node mm/slub.c:4855 [inline]
slab_alloc_node mm/slub.c:5251 [inline]
__do_kmalloc_node mm/slub.c:5656 [inline]
__kmalloc_noprof+0x47d/0x800 mm/slub.c:5669
kmalloc_noprof include/linux/slab.h:961 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x28a/0x550 security/tomoyo/realpath.c:80
tomoyo_realpath_from_path+0x58d/0x5d0 security/tomoyo/realpath.c:283
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x214/0x580 security/tomoyo/file.c:822
security_inode_getattr+0x12f/0x330 security/security.c:1869
vfs_getattr fs/stat.c:259 [inline]
vfs_fstat fs/stat.c:281 [inline]
vfs_fstatat+0xb1/0x170 fs/stat.c:373
__do_sys_newfstatat fs/stat.c:542 [inline]
__se_sys_newfstatat fs/stat.c:536 [inline]
__x64_sys_newfstatat+0x116/0x190 fs/stat.c:536
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 30 tgid 30 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0xbb8/0xd30 mm/page_alloc.c:2973
vfree+0x25a/0x400 mm/vmalloc.c:3466
delayed_vfree_work+0x55/0x80 mm/vmalloc.c:3385
process_one_work kernel/workqueue.c:3257 [inline]
process_scheduled_works+0xa45/0x1670 kernel/workqueue.c:3340
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3421
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x510/0xa50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
Memory state around the buggy address:
ffff888048ccf600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888048ccf680: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
>ffff888048ccf700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888048ccf780: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff888048ccf800: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
==================================================================
]
|
| 5/1 |
2026/01/28 22:49 |
action |
codesearch-prepare |
3m
Results: map[Index:codesearch-index]
|
| 6/1 |
2026/01/28 22:52 |
agent |
debugger |
3m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation.
Your final reply must contain only the explanation.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
==================================================================
BUG: KASAN: slab-use-after-free in nr_dec_obs net/netrom/nr_route.c:471 [inline]
BUG: KASAN: slab-use-after-free in nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
Read of size 2 at addr ffff888048ccf732 by task syz-executor102/6284
CPU: 1 UID: 0 PID: 6284 Comm: syz-executor102 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x10e/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x17e/0x810 mm/kasan/report.c:482
kasan_report+0x147/0x180 mm/kasan/report.c:595
nr_dec_obs net/netrom/nr_route.c:471 [inline]
nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb502ddcd39
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd784c5ad8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fb502ddcd39
RDX: 0000000000000000 RSI: 00000000000089e2 RDI: 0000000000000005
RBP: 0000000000000000 R08: 00007fb502e4123c R09: 00007fb502e4123c
R10: 00007fb502e4123c R11: 0000000000000246 R12: 00007ffd784c5afc
R13: 00007ffd784c5b30 R14: 00007ffd784c5b10 R15: 0000000000000012
</TASK>
Allocated by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x3e2/0x700 mm/slub.c:5780
kmalloc_noprof include/linux/slab.h:957 [inline]
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
nr_rt_ioctl+0xbfb/0xd20 net/netrom/nr_route.c:651
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x58/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2540 [inline]
slab_free mm/slub.c:6674 [inline]
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
nr_rt_ioctl+0x2e7/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888048ccf700
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 50 bytes inside of
freed 64-byte region [ffff888048ccf700, ffff888048ccf740)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48ccf
anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff88801a0418c0 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5509, tgid 5509 (dhcpcd-run-hook), ts 35445032815, free_ts 35417982511
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x234/0x290 mm/page_alloc.c:1884
prep_new_page mm/page_alloc.c:1892 [inline]
get_page_from_freelist+0x24d5/0x2570 mm/page_alloc.c:3945
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5240
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2486
alloc_slab_page mm/slub.c:3075 [inline]
allocate_slab+0x86/0x3b0 mm/slub.c:3248
new_slab mm/slub.c:3302 [inline]
___slab_alloc+0xe70/0x1860 mm/slub.c:4656
__slab_alloc+0x65/0x100 mm/slub.c:4779
__slab_alloc_node mm/slub.c:4855 [inline]
slab_alloc_node mm/slub.c:5251 [inline]
__do_kmalloc_node mm/slub.c:5656 [inline]
__kmalloc_noprof+0x47d/0x800 mm/slub.c:5669
kmalloc_noprof include/linux/slab.h:961 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x28a/0x550 security/tomoyo/realpath.c:80
tomoyo_realpath_from_path+0x58d/0x5d0 security/tomoyo/realpath.c:283
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x214/0x580 security/tomoyo/file.c:822
security_inode_getattr+0x12f/0x330 security/security.c:1869
vfs_getattr fs/stat.c:259 [inline]
vfs_fstat fs/stat.c:281 [inline]
vfs_fstatat+0xb1/0x170 fs/stat.c:373
__do_sys_newfstatat fs/stat.c:542 [inline]
__se_sys_newfstatat fs/stat.c:536 [inline]
__x64_sys_newfstatat+0x116/0x190 fs/stat.c:536
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 30 tgid 30 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0xbb8/0xd30 mm/page_alloc.c:2973
vfree+0x25a/0x400 mm/vmalloc.c:3466
delayed_vfree_work+0x55/0x80 mm/vmalloc.c:3385
process_one_work kernel/workqueue.c:3257 [inline]
process_scheduled_works+0xa45/0x1670 kernel/workqueue.c:3340
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3421
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x510/0xa50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
Memory state around the buggy address:
ffff888048ccf600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888048ccf680: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
>ffff888048ccf700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888048ccf780: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff888048ccf800: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
==================================================================
Reply: The crash is a **Use-After-Free (UAF)** in the function `nr_dec_obs` in `net/netrom/nr_route.c`.
### Root Cause Analysis
1. **The Bug**: The function `nr_dec_obs` decrements the reference count of a `nr_neigh` object and then accesses its members (`count` and `locked`) potentially after the object has been freed.
```c
// net/netrom/nr_route.c
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
nr_neigh_put(nr_neigh); // <--- Drops reference. If refcount hits 0, object is freed.
if (nr_neigh->count == 0 && !nr_neigh->locked) // <--- UAF! Accessing 'count' (offset 50) of freed object.
nr_remove_neigh(nr_neigh);
```
2. **Memory Layout Verification**:
The crash report states the read is at offset **50** inside the 64-byte object.
Structure layout of `struct nr_neigh`:
* 0: `struct hlist_node neigh_node` (16 bytes)
* 16: `ax25_address callsign` (7 bytes)
* 23: padding (1 byte)
* 24: `ax25_digi *digipeat` (8 bytes)
* 32: `ax25_cb *ax25` (8 bytes)
* 40: `struct net_device *dev` (8 bytes)
* 48: `unsigned char quality` (1 byte)
* 49: `unsigned char locked` (1 byte)
* **50**: `unsigned short count` (2 bytes) <-- **Exact match**
3. **Failure Scenario**:
Normally, a `nr_neigh` object referenced by a route has a reference count of at least 2 (one for the global `nr_neigh_list`, one for the route). However, in the crash scenario, the `nr_neigh` object has a reference count of **1** when entering the block (likely because it was removed from the global list but still referenced by a route due to a race or inconsistent state cleanup).
When `nr_neigh_put(nr_neigh)` is called, the reference count drops to 0, and the object is freed (`kfree`).
The subsequent check `if (nr_neigh->count == 0 ...)` attempts to read from the freed memory, triggering KASAN.
### Fix Proposal
To fix this, the code must not access `nr_neigh` after `nr_neigh_put`. The condition should be checked before dropping the reference, or the logic rearranged to ensure the object remains valid during access.
Example safe pattern:
```c
nr_neigh->count--;
bool remove = (nr_neigh->count == 0 && !nr_neigh->locked);
nr_neigh_put(nr_neigh);
if (remove)
nr_remove_neigh(nr_neigh);
```
*Note: Care must be taken ensuring `nr_remove_neigh` is safe to call if `nr_neigh_put` has already freed the object (which implies a double-free bug elsewhere if the object was already unlisted), or if `nr_remove_neigh` handles unhashed nodes safely.*
|
| 7/2 |
2026/01/28 22:52 |
llm |
debugger |
0m
Model:
Tokens:
input: 6224
output: 23
thoughts: 685
Thoughts: **Kernel Crash Analysis: A Deep Dive into a UAF in Net/Netrom**
Okay, so I've got a kernel crash, and it looks like a nasty one: a `KASAN: slab-use-after-free` in `nr_dec_obs` within the `net/netrom/nr_route.c` module. My immediate thought is, this is going to need some serious debugging.
Here's the breakdown of what I've got so far. The crash is a Use-After-Free. The access that's the problem is a read of size 2, happening within the inline function `nr_dec_obs`. This function is called from `nr_rt_ioctl`, and the error is on line 471 of `nr_route.c`. The allocation happens via `nr_add_node` which in turn is called from within `nr_rt_ioctl` (likely a `SIOCADDRT` ioctl command). The allocation is 64 bytes, and comes from `kmalloc-64` which is pretty standard.
Now, here's where it gets interesting and also where I have the initial thought that this is going to be a fun one to debug. The object is freed in `nr_dec_obs` itself, but the crash is also inside `nr_dec_obs`. The call stack confirms this, but that makes *no* sense. `nr_dec_obs` *should* be decrementing an obsolescence count, implying the object is being used and not freed at all! But the stack trace shows it calling `kfree` and also shows the crash. So, the stack traces look like the freeing and the use are happening within the *same* function. That's a classic UAF scenario: a double free, or a use after free. The stack trace of the "freed by task" shows that `kfree` is called from within `nr_dec_obs`!
So, to be absolutely clear: `nr_dec_obs` frees memory on line 469 and tries to use the same memory on line 471. That's a textbook definition of a use-after-free, and I'd bet my bottom dollar this is the root cause. This confirms the UAF.
Now, to solidify this, I need to verify all of this by looking directly at the code. I'll need to use `codesearch-definition-source` to jump to the definitions of `nr_dec_obs`, `nr_rt_ioctl`, and `nr_add_node`. Let's confirm the path with `ls`.
|
| 8/2 |
2026/01/28 22:53 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[af_netrom.c nr_dev.c nr_in.c nr_loopback.c nr_out.c nr_route.c nr_subr.c nr_timer.c sysctl_net_netrom.c] Subdirs:<nil>]
|
| 9/2 |
2026/01/28 22:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 7594
output: 25
thoughts: 85
Thoughts: Here's my thought process, as I delve into this code:
**Analyzing `nr_route.c` and Related Functions**
Alright, so `net/netrom/nr_route.c` is the file we're starting with, good. My immediate plan is to dissect the function `nr_dec_obs`. To gain a thorough understanding of its purpose within the Net/ROM routing scheme, I'll need to see how it interacts with the broader system. Therefore, I’ll also pull up the definitions for `nr_rt_ioctl` and `nr_add_node` to establish context. Specifically, I'm going to jump straight into `nr_dec_obs` around lines 469-471 to see what's happening there first. This will help me quickly grasp its core function within the overall routing logic.
|
| 10/2 |
2026/01/28 22:53 |
tool |
read-file |
0m
Args: map[File:net/netrom/nr_route.c]
Results: map[Contents:// SPDX-License-Identifier: GPL-2.0-or-later
/*
*
* Copyright Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
* Copyright Alan Cox GW4PTS (alan@lxorguk.ukuu.org.uk)
* Copyright Tomi Manninen OH2BNS (oh2bns@sral.fi)
*/
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/slab.h>
#include <net/ax25.h>
#include <linux/inet.h>
#include <linux/netdevice.h>
#include <net/arp.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <net/sock.h>
#include <linux/uaccess.h>
#include <linux/fcntl.h>
#include <linux/termios.h> /* For TIOCINQ/OUTQ */
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <net/netrom.h>
#include <linux/seq_file.h>
#include <linux/export.h>
static unsigned int nr_neigh_no = 1;
static HLIST_HEAD(nr_node_list);
static DEFINE_SPINLOCK(nr_node_list_lock);
static HLIST_HEAD(nr_neigh_list);
static DEFINE_SPINLOCK(nr_neigh_list_lock);
static struct nr_node *nr_node_get(ax25_address *callsign)
{
struct nr_node *found = NULL;
struct nr_node *nr_node;
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each(nr_node, &nr_node_list)
if (ax25cmp(callsign, &nr_node->callsign) == 0) {
nr_node_hold(nr_node);
found = nr_node;
break;
}
spin_unlock_bh(&nr_node_list_lock);
return found;
}
static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign,
struct net_device *dev)
{
struct nr_neigh *found = NULL;
struct nr_neigh *nr_neigh;
spin_lock_bh(&nr_neigh_list_lock);
nr_neigh_for_each(nr_neigh, &nr_neigh_list)
if (ax25cmp(callsign, &nr_neigh->callsign) == 0 &&
nr_neigh->dev == dev) {
nr_neigh_hold(nr_neigh);
found = nr_neigh;
break;
}
spin_unlock_bh(&nr_neigh_list_lock);
return found;
}
static void nr_remove_neigh(struct nr_neigh *);
/* re-sort the routes in quality order. */
static void re_sort_routes(struct nr_node *nr_node, int x, int y)
{
if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
if (nr_node->which == x)
nr_node->which = y;
else if (nr_node->which == y)
nr_node->which = x;
swap(nr_node->routes[x], nr_node->routes[y]);
}
}
/*
* Add a new route to a node, and in the process add the node and the
* neighbour if it is new.
*/
static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
ax25_address *ax25, ax25_digi *ax25_digi, struct net_device *dev,
int quality, int obs_count)
{
struct nr_node *nr_node;
struct nr_neigh *nr_neigh;
int i, found;
struct net_device *odev;
if ((odev=nr_dev_get(nr)) != NULL) { /* Can't add routes to ourself */
dev_put(odev);
return -EINVAL;
}
nr_node = nr_node_get(nr);
nr_neigh = nr_neigh_get_dev(ax25, dev);
/*
* The L2 link to a neighbour has failed in the past
* and now a frame comes from this neighbour. We assume
* it was a temporary trouble with the link and reset the
* routes now (and not wait for a node broadcast).
*/
if (nr_neigh != NULL && nr_neigh->failed != 0 && quality == 0) {
struct nr_node *nr_nodet;
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each(nr_nodet, &nr_node_list) {
nr_node_lock(nr_nodet);
for (i = 0; i < nr_nodet->count; i++)
if (nr_nodet->routes[i].neighbour == nr_neigh)
if (i < nr_nodet->which)
nr_nodet->which = i;
nr_node_unlock(nr_nodet);
}
spin_unlock_bh(&nr_node_list_lock);
}
if (nr_neigh != NULL)
nr_neigh->failed = 0;
if (quality == 0 && nr_neigh != NULL && nr_node != NULL) {
nr_neigh_put(nr_neigh);
nr_node_put(nr_node);
return 0;
}
if (nr_neigh == NULL) {
if ((nr_neigh = kmalloc(sizeof(*nr_neigh), GFP_ATOMIC)) == NULL) {
if (nr_node)
nr_node_put(nr_node);
return -ENOMEM;
}
nr_neigh->callsign = *ax25;
nr_neigh->digipeat = NULL;
nr_neigh->ax25 = NULL;
nr_neigh->dev = dev;
nr_neigh->quality = READ_ONCE(sysctl_netrom_default_path_quality);
nr_neigh->locked = 0;
nr_neigh->count = 0;
nr_neigh->number = nr_neigh_no++;
nr_neigh->failed = 0;
refcount_set(&nr_neigh->refcount, 1);
if (ax25_digi != NULL && ax25_digi->ndigi > 0) {
nr_neigh->digipeat = kmemdup(ax25_digi,
sizeof(*ax25_digi),
GFP_KERNEL);
if (nr_neigh->digipeat == NULL) {
kfree(nr_neigh);
if (nr_node)
nr_node_put(nr_node);
return -ENOMEM;
}
}
spin_lock_bh(&nr_neigh_list_lock);
hlist_add_head(&nr_neigh->neigh_node, &nr_neigh_list);
nr_neigh_hold(nr_neigh);
spin_unlock_bh(&nr_neigh_list_lock);
}
if (quality != 0 && ax25cmp(nr, ax25) == 0 && !nr_neigh->locked)
nr_neigh->quality = quality;
if (nr_node == NULL) {
if ((nr_node = kmalloc(sizeof(*nr_node), GFP_ATOMIC)) == NULL) {
if (nr_neigh)
nr_neigh_put(nr_neigh);
return -ENOMEM;
}
nr_node->callsign = *nr;
strscpy(nr_node->mnemonic, mnemonic);
nr_node->which = 0;
nr_node->count = 1;
refcount_set(&nr_node->refcount, 1);
spin_lock_init(&nr_node->node_lock);
nr_node->routes[0].quality = quality;
nr_node->routes[0].obs_count = obs_count;
nr_node->routes[0].neighbour = nr_neigh;
nr_neigh_hold(nr_neigh);
nr_neigh->count++;
spin_lock_bh(&nr_node_list_lock);
hlist_add_head(&nr_node->node_node, &nr_node_list);
/* refcount initialized at 1 */
spin_unlock_bh(&nr_node_list_lock);
nr_neigh_put(nr_neigh);
return 0;
}
nr_node_lock(nr_node);
if (quality != 0)
strscpy(nr_node->mnemonic, mnemonic);
for (found = 0, i = 0; i < nr_node->count; i++) {
if (nr_node->routes[i].neighbour == nr_neigh) {
nr_node->routes[i].quality = quality;
nr_node->routes[i].obs_count = obs_count;
found = 1;
break;
}
}
if (!found) {
/* We have space at the bottom, slot it in */
if (nr_node->count < 3) {
nr_node->routes[2] = nr_node->routes[1];
nr_node->routes[1] = nr_node->routes[0];
nr_node->routes[0].quality = quality;
nr_node->routes[0].obs_count = obs_count;
nr_node->routes[0].neighbour = nr_neigh;
nr_node->which++;
nr_node->count++;
nr_neigh_hold(nr_neigh);
nr_neigh->count++;
} else {
/* It must be better than the worst */
if (quality > nr_node->routes[2].quality) {
nr_node->routes[2].neighbour->count--;
nr_neigh_put(nr_node->routes[2].neighbour);
if (nr_node->routes[2].neighbour->count == 0 && !nr_node->routes[2].neighbour->locked)
nr_remove_neigh(nr_node->routes[2].neighbour);
nr_node->routes[2].quality = quality;
nr_node->routes[2].obs_count = obs_count;
nr_node->routes[2].neighbour = nr_neigh;
nr_neigh_hold(nr_neigh);
nr_neigh->count++;
}
}
}
/* Now re-sort the routes in quality order */
switch (nr_node->count) {
case 3:
re_sort_routes(nr_node, 0, 1);
re_sort_routes(nr_node, 1, 2);
fallthrough;
case 2:
re_sort_routes(nr_node, 0, 1);
break;
case 1:
break;
}
for (i = 0; i < nr_node->count; i++) {
if (nr_node->routes[i].neighbour == nr_neigh) {
if (i < nr_node->which)
nr_node->which = i;
break;
}
}
nr_neigh_put(nr_neigh);
nr_node_unlock(nr_node);
nr_node_put(nr_node);
return 0;
}
static void nr_remove_node_locked(struct nr_node *nr_node)
{
lockdep_assert_held(&nr_node_list_lock);
hlist_del_init(&nr_node->node_node);
nr_node_put(nr_node);
}
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
#define nr_remove_neigh_locked(__neigh) \
__nr_remove_neigh(__neigh)
static void nr_remove_neigh(struct nr_neigh *nr_neigh)
{
spin_lock_bh(&nr_neigh_list_lock);
__nr_remove_neigh(nr_neigh);
spin_unlock_bh(&nr_neigh_list_lock);
}
/*
* "Delete" a node. Strictly speaking remove a route to a node. The node
* is only deleted if no routes are left to it.
*/
static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct net_device *dev)
{
struct nr_node *nr_node;
struct nr_neigh *nr_neigh;
int i;
nr_node = nr_node_get(callsign);
if (nr_node == NULL)
return -EINVAL;
nr_neigh = nr_neigh_get_dev(neighbour, dev);
if (nr_neigh == NULL) {
nr_node_put(nr_node);
return -EINVAL;
}
spin_lock_bh(&nr_node_list_lock);
nr_node_lock(nr_node);
for (i = 0; i < nr_node->count; i++) {
if (nr_node->routes[i].neighbour == nr_neigh) {
nr_neigh->count--;
nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
nr_neigh_put(nr_neigh);
nr_node->count--;
if (nr_node->count == 0) {
nr_remove_node_locked(nr_node);
} else {
switch (i) {
case 0:
nr_node->routes[0] = nr_node->routes[1];
fallthrough;
case 1:
nr_node->routes[1] = nr_node->routes[2];
fallthrough;
case 2:
break;
}
nr_node_put(nr_node);
}
nr_node_unlock(nr_node);
spin_unlock_bh(&nr_node_list_lock);
return 0;
}
}
nr_neigh_put(nr_neigh);
nr_node_unlock(nr_node);
spin_unlock_bh(&nr_node_list_lock);
nr_node_put(nr_node);
return -EINVAL;
}
/*
* Lock a neighbour with a quality.
*/
static int __must_check nr_add_neigh(ax25_address *callsign,
ax25_digi *ax25_digi, struct net_device *dev, unsigned int quality)
{
struct nr_neigh *nr_neigh;
nr_neigh = nr_neigh_get_dev(callsign, dev);
if (nr_neigh) {
nr_neigh->quality = quality;
nr_neigh->locked = 1;
nr_neigh_put(nr_neigh);
return 0;
}
if ((nr_neigh = kmalloc(sizeof(*nr_neigh), GFP_ATOMIC)) == NULL)
return -ENOMEM;
nr_neigh->callsign = *callsign;
nr_neigh->digipeat = NULL;
nr_neigh->ax25 = NULL;
nr_neigh->dev = dev;
nr_neigh->quality = quality;
nr_neigh->locked = 1;
nr_neigh->count = 0;
nr_neigh->number = nr_neigh_no++;
nr_neigh->failed = 0;
refcount_set(&nr_neigh->refcount, 1);
if (ax25_digi != NULL && ax25_digi->ndigi > 0) {
nr_neigh->digipeat = kmemdup(ax25_digi, sizeof(*ax25_digi),
GFP_KERNEL);
if (nr_neigh->digipeat == NULL) {
kfree(nr_neigh);
return -ENOMEM;
}
}
spin_lock_bh(&nr_neigh_list_lock);
hlist_add_head(&nr_neigh->neigh_node, &nr_neigh_list);
/* refcount is initialized at 1 */
spin_unlock_bh(&nr_neigh_list_lock);
return 0;
}
/*
* "Delete" a neighbour. The neighbour is only removed if the number
* of nodes that may use it is zero.
*/
static int nr_del_neigh(ax25_address *callsign, struct net_device *dev, unsigned int quality)
{
struct nr_neigh *nr_neigh;
nr_neigh = nr_neigh_get_dev(callsign, dev);
if (nr_neigh == NULL) return -EINVAL;
nr_neigh->quality = quality;
nr_neigh->locked = 0;
if (nr_neigh->count == 0)
nr_remove_neigh(nr_neigh);
nr_neigh_put(nr_neigh);
return 0;
}
/*
* Decrement the obsolescence count by one. If a route is reduced to a
* count of zero, remove it. Also remove any unlocked neighbours with
* zero nodes routing via it.
*/
static int nr_dec_obs(void)
{
struct nr_neigh *nr_neigh;
struct nr_node *s;
struct hlist_node *nodet;
int i;
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each_safe(s, nodet, &nr_node_list) {
nr_node_lock(s);
for (i = 0; i < s->count; i++) {
switch (s->routes[i].obs_count) {
case 0: /* A locked entry */
break;
case 1: /* From 1 -> 0 */
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
s->count--;
switch (i) {
case 0:
s->routes[0] = s->routes[1];
fallthrough;
case 1:
s->routes[1] = s->routes[2];
break;
case 2:
break;
}
break;
default:
s->routes[i].obs_count--;
break;
}
}
if (s->count <= 0)
nr_remove_node_locked(s);
nr_node_unlock(s);
}
spin_unlock_bh(&nr_node_list_lock);
return 0;
}
/*
* A device has been removed. Remove its routes and neighbours.
*/
void nr_rt_device_down(struct net_device *dev)
{
struct nr_neigh *s;
struct hlist_node *nodet, *node2t;
struct nr_node *t;
int i;
spin_lock_bh(&nr_neigh_list_lock);
nr_neigh_for_each_safe(s, nodet, &nr_neigh_list) {
if (s->dev == dev) {
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each_safe(t, node2t, &nr_node_list) {
nr_node_lock(t);
for (i = 0; i < t->count; i++) {
if (t->routes[i].neighbour == s) {
t->count--;
switch (i) {
case 0:
t->routes[0] = t->routes[1];
fallthrough;
case 1:
t->routes[1] = t->routes[2];
break;
case 2:
break;
}
}
}
if (t->count <= 0)
nr_remove_node_locked(t);
nr_node_unlock(t);
}
spin_unlock_bh(&nr_node_list_lock);
nr_remove_neigh_locked(s);
}
}
spin_unlock_bh(&nr_neigh_list_lock);
}
/*
* Check that the device given is a valid AX.25 interface that is "up".
* Or a valid ethernet interface with an AX.25 callsign binding.
*/
static struct net_device *nr_ax25_dev_get(char *devname)
{
struct net_device *dev;
if ((dev = dev_get_by_name(&init_net, devname)) == NULL)
return NULL;
if ((dev->flags & IFF_UP) && dev->type == ARPHRD_AX25)
return dev;
dev_put(dev);
return NULL;
}
/*
* Find the first active NET/ROM device, usually "nr0".
*/
struct net_device *nr_dev_first(void)
{
struct net_device *dev, *first = NULL;
rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) {
if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM)
if (first == NULL || strncmp(dev->name, first->name, 3) < 0)
first = dev;
}
dev_hold(first);
rcu_read_unlock();
return first;
}
/*
* Find the NET/ROM device for the given callsign.
*/
struct net_device *nr_dev_get(ax25_address *addr)
{
struct net_device *dev;
rcu_read_lock();
for_each_netdev_rcu(&init_net, dev) {
if ((dev->flags & IFF_UP) && dev->type == ARPHRD_NETROM &&
ax25cmp(addr, (const ax25_address *)dev->dev_addr) == 0) {
dev_hold(dev);
goto out;
}
}
dev = NULL;
out:
rcu_read_unlock();
return dev;
}
static ax25_digi *nr_call_to_digi(ax25_digi *digi, int ndigis,
ax25_address *digipeaters)
{
int i;
if (ndigis == 0)
return NULL;
for (i = 0; i < ndigis; i++) {
digi->calls[i] = digipeaters[i];
digi->repeated[i] = 0;
}
digi->ndigi = ndigis;
digi->lastrepeat = -1;
return digi;
}
/*
* Handle the ioctls that control the routing functions.
*/
int nr_rt_ioctl(unsigned int cmd, void __user *arg)
{
struct nr_route_struct nr_route;
struct net_device *dev;
ax25_digi digi;
int ret;
switch (cmd) {
case SIOCADDRT:
if (copy_from_user(&nr_route, arg, sizeof(struct nr_route_struct)))
return -EFAULT;
if (nr_route.ndigis > AX25_MAX_DIGIS)
return -EINVAL;
if ((dev = nr_ax25_dev_get(nr_route.device)) == NULL)
return -EINVAL;
switch (nr_route.type) {
case NETROM_NODE:
if (strnlen(nr_route.mnemonic, 7) == 7) {
ret = -EINVAL;
break;
}
ret = nr_add_node(&nr_route.callsign,
nr_route.mnemonic,
&nr_route.neighbour,
nr_call_to_digi(&digi, nr_route.ndigis,
nr_route.digipeaters),
dev, nr_route.quality,
nr_route.obs_count);
break;
case NETROM_NEIGH:
ret = nr_add_neigh(&nr_route.callsign,
nr_call_to_digi(&digi, nr_route.ndigis,
nr_route.digipeaters),
dev, nr_route.quality);
break;
default:
ret = -EINVAL;
}
dev_put(dev);
return ret;
case SIOCDELRT:
if (copy_from_user(&nr_route, arg, sizeof(struct nr_route_struct)))
return -EFAULT;
if ((dev = nr_ax25_dev_get(nr_route.device)) == NULL)
return -EINVAL;
switch (nr_route.type) {
case NETROM_NODE:
ret = nr_del_node(&nr_route.callsign,
&nr_route.neighbour, dev);
break;
case NETROM_NEIGH:
ret = nr_del_neigh(&nr_route.callsign,
dev, nr_route.quality);
break;
default:
ret = -EINVAL;
}
dev_put(dev);
return ret;
case SIOCNRDECOBS:
return nr_dec_obs();
default:
return -EINVAL;
}
return 0;
}
/*
* A level 2 link has timed out, therefore it appears to be a poor link,
* then don't use that neighbour until it is reset.
*/
void nr_link_failed(ax25_cb *ax25, int reason)
{
struct nr_neigh *s, *nr_neigh = NULL;
struct nr_node *nr_node = NULL;
spin_lock_bh(&nr_neigh_list_lock);
nr_neigh_for_each(s, &nr_neigh_list) {
if (s->ax25 == ax25) {
nr_neigh_hold(s);
nr_neigh = s;
break;
}
}
spin_unlock_bh(&nr_neigh_list_lock);
if (nr_neigh == NULL)
return;
nr_neigh->ax25 = NULL;
ax25_cb_put(ax25);
if (++nr_neigh->failed < READ_ONCE(sysctl_netrom_link_fails_count)) {
nr_neigh_put(nr_neigh);
return;
}
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each(nr_node, &nr_node_list) {
nr_node_lock(nr_node);
if (nr_node->which < nr_node->count &&
nr_node->routes[nr_node->which].neighbour == nr_neigh)
nr_node->which++;
nr_node_unlock(nr_node);
}
spin_unlock_bh(&nr_node_list_lock);
nr_neigh_put(nr_neigh);
}
/*
* Route a frame to an appropriate AX.25 connection. A NULL ax25_cb
* indicates an internally generated frame.
*/
int nr_route_frame(struct sk_buff *skb, ax25_cb *ax25)
{
ax25_address *nr_src, *nr_dest;
struct nr_neigh *nr_neigh;
struct nr_node *nr_node;
struct net_device *dev;
unsigned char *dptr;
ax25_cb *ax25s;
int ret;
struct sk_buff *nskb, *oskb;
/*
* Reject malformed packets early. Check that it contains at least 2
* addresses and 1 byte more for Time-To-Live
*/
if (skb->len < 2 * sizeof(ax25_address) + 1)
return 0;
nr_src = (ax25_address *)(skb->data + 0);
nr_dest = (ax25_address *)(skb->data + 7);
if (ax25 != NULL) {
ret = nr_add_node(nr_src, "", &ax25->dest_addr, ax25->digipeat,
ax25->ax25_dev->dev, 0,
READ_ONCE(sysctl_netrom_obsolescence_count_initialiser));
if (ret)
return ret;
}
if ((dev = nr_dev_get(nr_dest)) != NULL) { /* Its for me */
if (ax25 == NULL) /* Its from me */
ret = nr_loopback_queue(skb);
else
ret = nr_rx_frame(skb, dev);
dev_put(dev);
return ret;
}
if (!READ_ONCE(sysctl_netrom_routing_control) && ax25 != NULL)
return 0;
/* Its Time-To-Live has expired */
if (skb->data[14] == 1) {
return 0;
}
nr_node = nr_node_get(nr_dest);
if (nr_node == NULL)
return 0;
nr_node_lock(nr_node);
if (nr_node->which >= nr_node->count) {
nr_node_unlock(nr_node);
nr_node_put(nr_node);
return 0;
}
nr_neigh = nr_node->routes[nr_node->which].neighbour;
if ((dev = nr_dev_first()) == NULL) {
nr_node_unlock(nr_node);
nr_node_put(nr_node);
return 0;
}
/* We are going to change the netrom headers so we should get our
own skb, we also did not know until now how much header space
we had to reserve... - RXQ */
nskb = skb_copy_expand(skb, dev->hard_header_len, 0, GFP_ATOMIC);
if (!nskb) {
nr_node_unlock(nr_node);
nr_node_put(nr_node);
dev_put(dev);
return 0;
}
oskb = skb;
skb = nskb;
skb->data[14]--;
dptr = skb_push(skb, 1);
*dptr = AX25_P_NETROM;
ax25s = nr_neigh->ax25;
nr_neigh->ax25 = ax25_send_frame(skb, 256,
(const ax25_address *)dev->dev_addr,
&nr_neigh->callsign,
nr_neigh->digipeat, nr_neigh->dev);
if (ax25s)
ax25_cb_put(ax25s);
dev_put(dev);
ret = (nr_neigh->ax25 != NULL);
nr_node_unlock(nr_node);
nr_node_put(nr_node);
if (ret)
kfree_skb(oskb);
return ret;
}
#ifdef CONFIG_PROC_FS
static void *nr_node_start(struct seq_file *seq, loff_t *pos)
__acquires(&nr_node_list_lock)
{
spin_lock_bh(&nr_node_list_lock);
return seq_hlist_start_head(&nr_node_list, *pos);
}
static void *nr_node_next(struct seq_file *seq, void *v, loff_t *pos)
{
return seq_hlist_next(v, &nr_node_list, pos);
}
static void nr_node_stop(struct seq_file *seq, void *v)
__releases(&nr_node_list_lock)
{
spin_unlock_bh(&nr_node_list_lock);
}
static int nr_node_show(struct seq_file *seq, void *v)
{
char buf[11];
int i;
if (v == SEQ_START_TOKEN)
seq_puts(seq,
"callsign mnemonic w n qual obs neigh qual obs neigh qual obs neigh\n");
else {
struct nr_node *nr_node = hlist_entry(v, struct nr_node,
node_node);
nr_node_lock(nr_node);
seq_printf(seq, "%-9s %-7s %d %d",
ax2asc(buf, &nr_node->callsign),
(nr_node->mnemonic[0] == '\0') ? "*" : nr_node->mnemonic,
nr_node->which + 1,
nr_node->count);
for (i = 0; i < nr_node->count; i++) {
seq_printf(seq, " %3d %d %05d",
nr_node->routes[i].quality,
nr_node->routes[i].obs_count,
nr_node->routes[i].neighbour->number);
}
nr_node_unlock(nr_node);
seq_puts(seq, "\n");
}
return 0;
}
const struct seq_operations nr_node_seqops = {
.start = nr_node_start,
.next = nr_node_next,
.stop = nr_node_stop,
.show = nr_node_show,
};
static void *nr_neigh_start(struct seq_file *seq, loff_t *pos)
__acquires(&nr_neigh_list_lock)
{
spin_lock_bh(&nr_neigh_list_lock);
return seq_hlist_start_head(&nr_neigh_list, *pos);
}
static void *nr_neigh_next(struct seq_file *seq, void *v, loff_t *pos)
{
return seq_hlist_next(v, &nr_neigh_list, pos);
}
static void nr_neigh_stop(struct seq_file *seq, void *v)
__releases(&nr_neigh_list_lock)
{
spin_unlock_bh(&nr_neigh_list_lock);
}
static int nr_neigh_show(struct seq_file *seq, void *v)
{
char buf[11];
int i;
if (v == SEQ_START_TOKEN)
seq_puts(seq, "addr callsign dev qual lock count failed digipeaters\n");
else {
struct nr_neigh *nr_neigh;
nr_neigh = hlist_entry(v, struct nr_neigh, neigh_node);
seq_printf(seq, "%05d %-9s %-4s %3d %d %3d %3d",
nr_neigh->number,
ax2asc(buf, &nr_neigh->callsign),
nr_neigh->dev ? nr_neigh->dev->name : "???",
nr_neigh->quality,
nr_neigh->locked,
nr_neigh->count,
nr_neigh->failed);
if (nr_neigh->digipeat != NULL) {
for (i = 0; i < nr_neigh->digipeat->ndigi; i++)
seq_printf(seq, " %s",
ax2asc(buf, &nr_neigh->digipeat->calls[i]));
}
seq_puts(seq, "\n");
}
return 0;
}
const struct seq_operations nr_neigh_seqops = {
.start = nr_neigh_start,
.next = nr_neigh_next,
.stop = nr_neigh_stop,
.show = nr_neigh_show,
};
#endif
/*
* Free all memory associated with the nodes and routes lists.
*/
void nr_rt_free(void)
{
struct nr_neigh *s = NULL;
struct nr_node *t = NULL;
struct hlist_node *nodet;
spin_lock_bh(&nr_neigh_list_lock);
spin_lock_bh(&nr_node_list_lock);
nr_node_for_each_safe(t, nodet, &nr_node_list) {
nr_node_lock(t);
nr_remove_node_locked(t);
nr_node_unlock(t);
}
nr_neigh_for_each_safe(s, nodet, &nr_neigh_list) {
while(s->count) {
s->count--;
nr_neigh_put(s);
}
nr_remove_neigh_locked(s);
}
spin_unlock_bh(&nr_node_list_lock);
spin_unlock_bh(&nr_neigh_list_lock);
}
]
|
| 11/2 |
2026/01/28 22:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 17289
output: 44
thoughts: 1218
Thoughts: **Analyzing `nr_dec_obs` for a Potential Use-After-Free**
Okay, let's break this down. I'm looking at the `nr_dec_obs` function, trying to understand a possible use-after-free scenario. The stack trace indicates that `kfree` is called from inside `nr_dec_obs` and, specifically, on line 469 of the function definition, which corresponds to the line: `case 1: /* From 1 -> 0 */`. Then, line 471, the line `nr_neigh = s->routes[i].neighbour;` reads from memory. The concern here is that a `nr_neigh` object, potentially freed on line 469 (through `nr_neigh_put` and eventually `kfree`), is then accessed on line 471.
My initial thoughts are that `nr_neigh` gets decremented, its reference count goes to zero, and if it's not locked, it's removed. The crucial path is where `nr_neigh->count` is decremented to zero *and* the object is not locked. `nr_remove_neigh` is called. That makes me wonder: does the `nr_remove_neigh` call, which in turn calls `nr_neigh_put` eventually, trigger a free? If it does, and if any subsequent access occurs before the memory is re-allocated for another purpose, that's a classic use-after-free.
I need to confirm that `nr_neigh_put` does, in fact, free the memory, and also that `nr_remove_neigh` acquires its own lock (or uses some other mechanism) to protect against concurrent access. I am pretty sure `nr_neigh_put` is just a wrapper for decrementing the reference count and calling `kfree` if the refcount hits zero.
So, I reviewed the code. Specifically, inside `nr_remove_neigh`, there's a call to `nr_neigh_put`, which is an inline decrement-and-free (via `kfree` indirectly in the typical refcount=0 case). The `nr_remove_neigh` function itself is protected by `nr_neigh_list_lock` so no concurrent access is possible during removal.
Now, I'm checking the disassembly (or a memory map would do too), but, line 471 reads memory from `nr_neigh` that was possibly freed on line 469. It looks like the scenario where a use-after-free could happen is when a `nr_neigh` object is removed *and* later accessed. So, I must investigate all code paths that might lead to a subsequent read of a freed `nr_neigh` object. This looks like a potentially exploitable vulnerability if there's any timing issue or race condition between the potential free and subsequent use.
I need to find the definition of `nr_remove_neigh`, and determine if it has any potential for re-entrancy, concurrent access and potential use-after-free condition. It seems there's the possibility of concurrent access to `nr_neigh` but `nr_neigh_list_lock` seems to protect against concurrent `nr_neigh` deletion.
The issue may be more subtle, as access to the `nr_neigh` structure happens within a loop and the read on line 471 might be stale data. This requires tracing all code paths using `nr_neigh` to guarantee memory safety. I will have to look at how these objects are used to see if a race can happen.
|
| 12/2 |
2026/01/28 22:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_dec_obs]
Results: map[SourceCode: 445: /*
446: * Decrement the obsolescence count by one. If a route is reduced to a
447: * count of zero, remove it. Also remove any unlocked neighbours with
448: * zero nodes routing via it.
449: */
450: static int nr_dec_obs(void)
451: {
452: struct nr_neigh *nr_neigh;
453: struct nr_node *s;
454: struct hlist_node *nodet;
455: int i;
456:
457: spin_lock_bh(&nr_node_list_lock);
458: nr_node_for_each_safe(s, nodet, &nr_node_list) {
459: nr_node_lock(s);
460: for (i = 0; i < s->count; i++) {
461: switch (s->routes[i].obs_count) {
462: case 0: /* A locked entry */
463: break;
464:
465: case 1: /* From 1 -> 0 */
466: nr_neigh = s->routes[i].neighbour;
467:
468: nr_neigh->count--;
469: nr_neigh_put(nr_neigh);
470:
471: if (nr_neigh->count == 0 && !nr_neigh->locked)
472: nr_remove_neigh(nr_neigh);
473:
474: s->count--;
475:
476: switch (i) {
477: case 0:
478: s->routes[0] = s->routes[1];
479: fallthrough;
480: case 1:
481: s->routes[1] = s->routes[2];
482: break;
483: case 2:
484: break;
485: }
486: break;
487:
488: default:
489: s->routes[i].obs_count--;
490: break;
491:
492: }
493: }
494:
495: if (s->count <= 0)
496: nr_remove_node_locked(s);
497: nr_node_unlock(s);
498: }
499: spin_unlock_bh(&nr_node_list_lock);
500:
501: return 0;
502: }
SourceFile:net/netrom/nr_route.c]
|
| 13/2 |
2026/01/28 22:53 |
llm |
debugger |
0m
Model:
Tokens:
input: 20113
output: 40
thoughts: 567
Thoughts: **Analyzing the Use-After-Free Bug**
Okay, I've got the code snippets and the crash report in front of me. The core issue is a classic Use-After-Free. The crash dump pinpoints the exact lines involved, which is incredibly helpful. Line 469, specifically `nr_neigh_put(nr_neigh);`, is where the memory for `nr_neigh` gets freed, according to the report. Then, immediately after, line 471 tries to read from the freed memory with `if (nr_neigh->count == 0 && !nr_neigh->locked)`. That's the problem.
Let's dissect the logic within `nr_dec_obs`. This function iterates through routes. It seems the goal is to clean up references to a neighbor (`nr_neigh`) when some sort of observation count (`obs_count`) drops to zero – let's assume `obs_count` is what decrements to zero. Now, line 468, `nr_neigh->count--`, decreases a counter on the `nr_neigh` object itself. Then, crucially, line 469 calls `nr_neigh_put(nr_neigh)`. This is where the potential free happens. The `nr_neigh_put` function presumably decrements a reference count, likely a `kref` or similar. If that reference count hits zero, the object is immediately freed.
So, the critical point is this: `nr_neigh_put` could free `nr_neigh`. However, the very next line – line 471 – attempts to access `nr_neigh->count`. That's the Use-After-Free. We're reading data from memory that may have just been deallocated.
The key question is, are `nr_neigh->count` and the object's reference count the same thing? It seems not. Based on a quick analysis, `nr_neigh` likely has a `refcount_t refcount;` (or similar for reference counting) and another field such as an `atomic_t count;` (or perhaps a `u16 count`) to track the number of routes using the neighbor. This is key. The `kref` (or `refcount_t`) governs the lifetime of the object, while `count` represents a logical use count.
My conclusion: The logic is fundamentally flawed because it accesses `nr_neigh` *after* a function (`nr_neigh_put`) that *might* free it. This is a classic concurrency bug, and we need to restructure the code to ensure that we don't access `nr_neigh` after a call that might release the last reference. I need to review the `nr_neigh_put` function and `struct nr_neigh` definition to confirm the reference counting mechanisms and other fields to confirm my current thoughts.
|
| 14/2 |
2026/01/28 22:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/net/netrom.h IncludeLines:false Name:nr_neigh]
Results: map[SourceCode:struct nr_neigh {
struct hlist_node neigh_node;
ax25_address callsign;
ax25_digi *digipeat;
ax25_cb *ax25;
struct net_device *dev;
unsigned char quality;
unsigned char locked;
unsigned short count;
unsigned int number;
unsigned char failed;
refcount_t refcount;
};
SourceFile:include/net/netrom.h]
|
| 15/2 |
2026/01/28 22:53 |
llm |
debugger |
2m
Model:
Tokens:
input: 21474
output: 778
thoughts: 16530
Thoughts: **Analysis of the UAF in `nr_dec_obs`**
Okay, so I've dug into this Use-After-Free (UAF) issue in the networking code. The core problem is accessing the `nr_neigh->count` field after the `nr_neigh_put` function has potentially freed the `nr_neigh` object. This happens in the `nr_dec_obs` function.
The code's intention is clear: we're decrementing a usage count (`nr_neigh->count`) for a neighbor (`nr_neigh`) within a route. We also need to release the route's reference to this neighbor (`nr_neigh_put`). Finally, if the usage count goes to zero *and* the neighbor isn't locked, we remove the neighbor from the global list (`nr_remove_neigh`).
Here's the problem: `nr_neigh_put` can free the `nr_neigh` object if its internal reference count (`refcount`) goes to zero. The crash happens when `refcount` *is* 1, and we call `nr_neigh_put`. The `nr_neigh` is freed and when we try to access `count` we crash.
In a normal scenario, the `nr_neigh` is on a global list, holding a reference, which normally means the `refcount` would be at least 2: one for the list, and one for the route using it. However, if the neighbor is *not* in the global list, but still referenced by a route, the `refcount` can be 1. That is the "anomalous state".
So, how can we end up with this anomalous state? The code for `nr_rt_device_down` is likely related. It removes all neighbors from a given device. The logic is complex, involving iterators, nested loops and the removal of routes and neighbors. I think `nr_rt_device_down` can leave a `nr_neigh` out of the list and dangling in a route if there's a race, or due to a subtle off-by-one error.
The fix I'm sure of is to avoid accessing the memory after releasing it. In this case, we need to cache the state (or, effectively, compute it earlier), and then, *only* if the conditions are met (count is zero *and* it's not locked), should we then attempt to remove the neighbor and *after* we call `nr_neigh_put`.
The current code:
1. `nr_neigh->count--`.
2. `nr_neigh_put(nr_neigh)`.
3. `if (nr_neigh->count == 0 && !nr_neigh->locked)`
The correct order:
1. `nr_neigh->count--`.
2. `drop_list = (nr_neigh->count == 0 && !nr_neigh->locked)`
3. `nr_neigh_put(nr_neigh)`.
4. `if (drop_list) nr_remove_neigh(nr_neigh)`
By doing this, even if `nr_neigh_put` frees the object (because the list reference is missing), we won't access its fields. We can check it and if it's the right state we call `nr_remove_neigh`, otherwise we don't. The primary bug is the read access after `put`, this proposed reordering addresses this issue.
|
| 16/1 |
2026/01/28 22:56 |
action |
kernel-scratch-checkouter |
0m
Results: map[KernelScratchSrc:/usr/local/google/home/dvyukov/syzkaller/agent/workdir/cache/tmp/tmp2691922866]
|
| 17/1 |
2026/01/28 22:56 |
loop |
|
12m
|
| 18/2 |
2026/01/28 22:56 |
iteration |
0 |
12m
|
| 19/3 |
2026/01/28 22:56 |
agent |
patch-generator |
3m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
Use the codeedit tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Your final reply should contain explanation of what you did in the patch and why.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
==================================================================
BUG: KASAN: slab-use-after-free in nr_dec_obs net/netrom/nr_route.c:471 [inline]
BUG: KASAN: slab-use-after-free in nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
Read of size 2 at addr ffff888048ccf732 by task syz-executor102/6284
CPU: 1 UID: 0 PID: 6284 Comm: syz-executor102 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x10e/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x17e/0x810 mm/kasan/report.c:482
kasan_report+0x147/0x180 mm/kasan/report.c:595
nr_dec_obs net/netrom/nr_route.c:471 [inline]
nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb502ddcd39
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd784c5ad8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fb502ddcd39
RDX: 0000000000000000 RSI: 00000000000089e2 RDI: 0000000000000005
RBP: 0000000000000000 R08: 00007fb502e4123c R09: 00007fb502e4123c
R10: 00007fb502e4123c R11: 0000000000000246 R12: 00007ffd784c5afc
R13: 00007ffd784c5b30 R14: 00007ffd784c5b10 R15: 0000000000000012
</TASK>
Allocated by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x3e2/0x700 mm/slub.c:5780
kmalloc_noprof include/linux/slab.h:957 [inline]
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
nr_rt_ioctl+0xbfb/0xd20 net/netrom/nr_route.c:651
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x58/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2540 [inline]
slab_free mm/slub.c:6674 [inline]
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
nr_rt_ioctl+0x2e7/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888048ccf700
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 50 bytes inside of
freed 64-byte region [ffff888048ccf700, ffff888048ccf740)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48ccf
anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff88801a0418c0 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5509, tgid 5509 (dhcpcd-run-hook), ts 35445032815, free_ts 35417982511
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x234/0x290 mm/page_alloc.c:1884
prep_new_page mm/page_alloc.c:1892 [inline]
get_page_from_freelist+0x24d5/0x2570 mm/page_alloc.c:3945
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5240
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2486
alloc_slab_page mm/slub.c:3075 [inline]
allocate_slab+0x86/0x3b0 mm/slub.c:3248
new_slab mm/slub.c:3302 [inline]
___slab_alloc+0xe70/0x1860 mm/slub.c:4656
__slab_alloc+0x65/0x100 mm/slub.c:4779
__slab_alloc_node mm/slub.c:4855 [inline]
slab_alloc_node mm/slub.c:5251 [inline]
__do_kmalloc_node mm/slub.c:5656 [inline]
__kmalloc_noprof+0x47d/0x800 mm/slub.c:5669
kmalloc_noprof include/linux/slab.h:961 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x28a/0x550 security/tomoyo/realpath.c:80
tomoyo_realpath_from_path+0x58d/0x5d0 security/tomoyo/realpath.c:283
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x214/0x580 security/tomoyo/file.c:822
security_inode_getattr+0x12f/0x330 security/security.c:1869
vfs_getattr fs/stat.c:259 [inline]
vfs_fstat fs/stat.c:281 [inline]
vfs_fstatat+0xb1/0x170 fs/stat.c:373
__do_sys_newfstatat fs/stat.c:542 [inline]
__se_sys_newfstatat fs/stat.c:536 [inline]
__x64_sys_newfstatat+0x116/0x190 fs/stat.c:536
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 30 tgid 30 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0xbb8/0xd30 mm/page_alloc.c:2973
vfree+0x25a/0x400 mm/vmalloc.c:3466
delayed_vfree_work+0x55/0x80 mm/vmalloc.c:3385
process_one_work kernel/workqueue.c:3257 [inline]
process_scheduled_works+0xa45/0x1670 kernel/workqueue.c:3340
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3421
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x510/0xa50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
Memory state around the buggy address:
ffff888048ccf600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888048ccf680: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
>ffff888048ccf700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888048ccf780: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff888048ccf800: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
==================================================================
The explanation of the root cause of the bug is:
The crash is a **Use-After-Free (UAF)** in the function `nr_dec_obs` in `net/netrom/nr_route.c`.
### Root Cause Analysis
1. **The Bug**: The function `nr_dec_obs` decrements the reference count of a `nr_neigh` object and then accesses its members (`count` and `locked`) potentially after the object has been freed.
```c
// net/netrom/nr_route.c
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
nr_neigh_put(nr_neigh); // <--- Drops reference. If refcount hits 0, object is freed.
if (nr_neigh->count == 0 && !nr_neigh->locked) // <--- UAF! Accessing 'count' (offset 50) of freed object.
nr_remove_neigh(nr_neigh);
```
2. **Memory Layout Verification**:
The crash report states the read is at offset **50** inside the 64-byte object.
Structure layout of `struct nr_neigh`:
* 0: `struct hlist_node neigh_node` (16 bytes)
* 16: `ax25_address callsign` (7 bytes)
* 23: padding (1 byte)
* 24: `ax25_digi *digipeat` (8 bytes)
* 32: `ax25_cb *ax25` (8 bytes)
* 40: `struct net_device *dev` (8 bytes)
* 48: `unsigned char quality` (1 byte)
* 49: `unsigned char locked` (1 byte)
* **50**: `unsigned short count` (2 bytes) <-- **Exact match**
3. **Failure Scenario**:
Normally, a `nr_neigh` object referenced by a route has a reference count of at least 2 (one for the global `nr_neigh_list`, one for the route). However, in the crash scenario, the `nr_neigh` object has a reference count of **1** when entering the block (likely because it was removed from the global list but still referenced by a route due to a race or inconsistent state cleanup).
When `nr_neigh_put(nr_neigh)` is called, the reference count drops to 0, and the object is freed (`kfree`).
The subsequent check `if (nr_neigh->count == 0 ...)` attempts to read from the freed memory, triggering KASAN.
### Fix Proposal
To fix this, the code must not access `nr_neigh` after `nr_neigh_put`. The condition should be checked before dropping the reference, or the logic rearranged to ensure the object remains valid during access.
Example safe pattern:
```c
nr_neigh->count--;
bool remove = (nr_neigh->count == 0 && !nr_neigh->locked);
nr_neigh_put(nr_neigh);
if (remove)
nr_remove_neigh(nr_neigh);
```
*Note: Care must be taken ensuring `nr_remove_neigh` is safe to call if `nr_neigh_put` has already freed the object (which implies a double-free bug elsewhere if the object was already unlisted), or if `nr_remove_neigh` handles unhashed nodes safely.*
Reply: The bug is a Use-After-Free (UAF) in `net/netrom/nr_route.c`. The function `nr_dec_obs` decrements a reference count using `nr_neigh_put(nr_neigh)` and subsequently accesses `nr_neigh->count` and `nr_neigh->locked`. If `nr_neigh_put` drops the last reference, `nr_neigh` is freed, making the subsequent access invalid.
To fix this, the code should check `nr_neigh->count` and `nr_neigh->locked` *before* calling `nr_neigh_put`.
However, simply reordering the code introduces a potential Double Free or refcount underflow. If `nr_neigh` is not in the global neighbour list (e.g., refcount is 1), `nr_dec_obs` might call `nr_remove_neigh`. `nr_remove_neigh` unconditionally removes the node from the list and calls `nr_neigh_put` (dropping the reference presumably held by the list). If the node was not in the list, `nr_remove_neigh` would incorrectly drop a reference it doesn't own, leading to a double free when `nr_dec_obs` subsequently calls `nr_neigh_put`.
Therefore, the fix involves two changes:
1. Modify `__nr_remove_neigh` to check if the node is actually in the list (`!hlist_unhashed`) before removing it and dropping the reference. This makes `nr_remove_neigh` idempotent and safe to call on unhashed nodes.
2. In `nr_dec_obs`, reorder the operations to access `nr_neigh` members and conditionally call `nr_remove_neigh` *before* calling `nr_neigh_put`.
These changes ensure that we do not access freed memory and do not drop references we do not hold.
Allocated by task 6284:
...
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
...
Freed by task 6284:
...
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
...
The patch is as follows:
```c
--- net/netrom/nr_route.c
+++ net/netrom/nr_route.c
@@ -296,6 +296,8 @@
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
+ if (hlist_unhashed(&nr_neigh->neigh_node))
+ return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
@@ -466,11 +468,10 @@
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
- nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
+ nr_neigh_put(nr_neigh);
+
s->count--;
switch (i) {
```
|
| 20/4 |
2026/01/28 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 7246
output: 23
thoughts: 196
Thoughts: **Investigating a Use-After-Free in net/netrom/nr_route.c**
Okay, here's the situation. I'm looking at a reported Use-After-Free (UAF) bug in `net/netrom/nr_route.c`, specifically within the `nr_dec_obs` function. The core issue, as I understand it, is that we're accessing `nr_neigh->count` and `nr_neigh->locked` *after* a call to `nr_neigh_put(nr_neigh)`. And, of course, that function might have freed the `nr_neigh` structure, leading to memory corruption.
My immediate task is to dig into this. I'll need to confirm the details. I will begin by carefully examining the `nr_dec_obs` function in `net/netrom/nr_route.c`. Understanding its control flow is critical. Next, I'll need to thoroughly review the definition of `struct nr_neigh`. I'll want to double-check the field definitions and offsets to ensure I'm completely clear on what's being accessed. While the initial report seems thorough, I always believe in verifying the foundational details.
The suggested fix, of course, proposes a check prior to calling `nr_neigh_put`. Makes perfect sense. I will need to consider the appropriate location for this check.
Before I go further, let's just do a quick file listing of the `net/netrom/` directory to have a good feel for the ecosystem. I'll make notes for myself.
|
| 21/4 |
2026/01/28 22:56 |
tool |
codesearch-dir-index |
0m
Args:
Results: map[Files:[af_netrom.c nr_dev.c nr_in.c nr_loopback.c nr_out.c nr_route.c nr_subr.c nr_timer.c sysctl_net_netrom.c] Subdirs:<nil>]
|
| 22/4 |
2026/01/28 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 7900
output: 29
thoughts: 90
Thoughts: Here's my thought process, as if I were considering this code:
**Analyzing the netrom Routing Code**
Alright, I'm diving into `net/netrom/nr_route.c`. The stack trace points to `nr_dec_obs` being called by `nr_rt_ioctl`, so I need to understand those functions first and how they interact. I'm also going to examine `nr_neigh_put` and `nr_remove_neigh` as they're likely involved in neighbor management, which is often crucial in routing protocols.
First, I should get an overview of the key entities within `net/netrom/nr_route.c`. I will map out the relevant sections of the code, jotting down the line numbers for quick reference so I can jump between functions and data structures without having to reread the entire file. This way, I can piece together the control flow and data manipulation more efficiently.
|
| 23/4 |
2026/01/28 22:56 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:net/netrom/nr_route.c]
Results: map[Entities:[map[Kind:function Name:__nr_remove_neigh] map[Kind:function Name:nr_add_neigh] map[Kind:function Name:nr_add_node] map[Kind:function Name:nr_ax25_dev_get] map[Kind:function Name:nr_call_to_digi] map[Kind:function Name:nr_dec_obs] map[Kind:function Name:nr_del_neigh] map[Kind:function Name:nr_del_node] map[Kind:function Name:nr_dev_first] map[Kind:function Name:nr_dev_get] map[Kind:function Name:nr_link_failed] map[Kind:function Name:nr_neigh_get_dev] map[Kind:function Name:nr_neigh_next] map[Kind:function Name:nr_neigh_show] map[Kind:function Name:nr_neigh_start] map[Kind:function Name:nr_neigh_stop] map[Kind:function Name:nr_node_get] map[Kind:function Name:nr_node_next] map[Kind:function Name:nr_node_show] map[Kind:function Name:nr_node_start] map[Kind:function Name:nr_node_stop] map[Kind:function Name:nr_remove_neigh] map[Kind:function Name:nr_remove_node_locked] map[Kind:function Name:nr_route_frame] map[Kind:function Name:nr_rt_device_down] map[Kind:function Name:nr_rt_free] map[Kind:function Name:nr_rt_ioctl] map[Kind:function Name:re_sort_routes]]]
|
| 24/4 |
2026/01/28 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 8693
output: 44
thoughts: 91
Thoughts: Here's my thought process, as it stands:
**Diving into the Netrom Code**
Alright, I'm looking at this and the key function here seems to be `nr_dec_obs`. To really understand what's happening, I need to dig into the source code for that, no question. I also need to understand its relationship with `nr_remove_neigh` and `nr_rt_ioctl`, so I should pull those up as well.
Given that these functions deal with neighbors and route IOCTLs, I'm betting the crucial structure definition, `struct nr_neigh`, will be in `include/net/netrom.h`. Let's confirm that by taking a look.
First things first, I'll read through `nr_dec_obs` and go from there. This gives me a starting point.
|
| 25/4 |
2026/01/28 22:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_dec_obs]
Results: map[SourceCode: 445: /*
446: * Decrement the obsolescence count by one. If a route is reduced to a
447: * count of zero, remove it. Also remove any unlocked neighbours with
448: * zero nodes routing via it.
449: */
450: static int nr_dec_obs(void)
451: {
452: struct nr_neigh *nr_neigh;
453: struct nr_node *s;
454: struct hlist_node *nodet;
455: int i;
456:
457: spin_lock_bh(&nr_node_list_lock);
458: nr_node_for_each_safe(s, nodet, &nr_node_list) {
459: nr_node_lock(s);
460: for (i = 0; i < s->count; i++) {
461: switch (s->routes[i].obs_count) {
462: case 0: /* A locked entry */
463: break;
464:
465: case 1: /* From 1 -> 0 */
466: nr_neigh = s->routes[i].neighbour;
467:
468: nr_neigh->count--;
469: nr_neigh_put(nr_neigh);
470:
471: if (nr_neigh->count == 0 && !nr_neigh->locked)
472: nr_remove_neigh(nr_neigh);
473:
474: s->count--;
475:
476: switch (i) {
477: case 0:
478: s->routes[0] = s->routes[1];
479: fallthrough;
480: case 1:
481: s->routes[1] = s->routes[2];
482: break;
483: case 2:
484: break;
485: }
486: break;
487:
488: default:
489: s->routes[i].obs_count--;
490: break;
491:
492: }
493: }
494:
495: if (s->count <= 0)
496: nr_remove_node_locked(s);
497: nr_node_unlock(s);
498: }
499: spin_unlock_bh(&nr_node_list_lock);
500:
501: return 0;
502: }
SourceFile:net/netrom/nr_route.c]
|
| 26/4 |
2026/01/28 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 9805
output: 43
thoughts: 214
Thoughts: **Analyzing a Potential Use-After-Free Vulnerability**
Okay, so the code points directly to the problem: lines 471 and 472 are accessing `nr_neigh->count` and `nr_neigh->locked`, but the preceding lines call `nr_neigh_put`. I know that function's purpose – it's designed to decrease the reference count of the `nr_neigh` object. If the refcount drops to zero, the object is immediately freed, which makes those accesses a classic use-after-free scenario. Boom, right there!
Wait a minute, something doesn't feel quite right... `nr_neigh->count` doesn't *sound* like the standard reference counter. I need to make sure I'm not overlooking something obvious. I'm going to quickly cross-check the definition of the `struct nr_neigh`. I need to ensure that `count` and the object's `locked` status are actually *part* of its structure. If that's the case, then this really *is* a UAF! If not, I've got to re-evaluate...
|
| 27/4 |
2026/01/28 22:57 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeSnippetLines:0 Name:nr_neigh]
Results: map[References:[map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:__nr_remove_neigh SourceFile:net/netrom/nr_route.c SourceLine:296] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_add_neigh SourceFile:net/netrom/nr_route.c SourceLine:382] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_add_node SourceFile:net/netrom/nr_route.c SourceLine:102] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_dec_obs SourceFile:net/netrom/nr_route.c SourceLine:452] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_del_neigh SourceFile:net/netrom/nr_route.c SourceLine:429] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_del_node SourceFile:net/netrom/nr_route.c SourceLine:319] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_link_failed SourceFile:net/netrom/nr_route.c SourceLine:707] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_link_failed SourceFile:net/netrom/nr_route.c SourceLine:707] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_get_dev SourceFile:net/netrom/nr_route.c SourceLine:63] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_get_dev SourceFile:net/netrom/nr_route.c SourceLine:64] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_put SourceFile:include/net/netrom.h SourceLine:137] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_show SourceFile:net/netrom/nr_route.c SourceLine:933] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_show SourceFile:net/netrom/nr_route.c SourceLine:935] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_show SourceFile:net/netrom/nr_route.c SourceLine:935] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_neigh_show SourceFile:net/netrom/nr_route.c SourceLine:935] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_remove_neigh SourceFile:net/netrom/nr_route.c SourceLine:305] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_route_frame SourceFile:net/netrom/nr_route.c SourceLine:749] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_rt_device_down SourceFile:net/netrom/nr_route.c SourceLine:509] map[ReferenceKind:uses ReferencingEntityKind:function ReferencingEntityName:nr_rt_free SourceFile:net/netrom/nr_route.c SourceLine:969]] TruncatedOutput:false]
|
| 28/4 |
2026/01/28 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 11314
output: 40
thoughts: 34
Thoughts: **Navigating the Net/Netrom Codebase**
Okay, so `nr_neigh_put` is apparently defined within `include/net/netrom.h`. That's a good starting point. My primary goal here is to understand the structure surrounding `nr_neigh`. I need to figure out the relationship between `nr_neigh_put` and the data it operates on. Therefore, my next immediate action is to delve into that `netrom.h` header file. I need to locate the definition of `struct nr_neigh`. That structure is, most likely, at the core of understanding how this component functions. I expect to find the member variables there which are important to what `nr_neigh_put` manipulates.
|
| 29/4 |
2026/01/28 22:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/net/netrom.h IncludeLines:true Name:nr_neigh]
Results: map[SourceCode: 89: struct nr_neigh {
90: struct hlist_node neigh_node;
91: ax25_address callsign;
92: ax25_digi *digipeat;
93: ax25_cb *ax25;
94: struct net_device *dev;
95: unsigned char quality;
96: unsigned char locked;
97: unsigned short count;
98: unsigned int number;
99: unsigned char failed;
100: refcount_t refcount;
101: };
SourceFile:include/net/netrom.h]
|
| 30/4 |
2026/01/28 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 11743
output: 42
thoughts: 312
Thoughts: **Analyzing a Potential Use-After-Free Vulnerability**
Alright, let's break down this `struct nr_neigh` situation. It's got both a `count` and a `refcount`, which immediately raises a flag for me. The `count` seems to be tracking something like route usage – how many routes are currently pointing to this neighbor entry. The `refcount`, of course, is the memory lifetime counter.
Now, looking at `nr_dec_obs`, I see:
```c
nr_neigh->count--;
nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
```
The first line decrements the `count`. The next call, `nr_neigh_put`, decrements the `refcount`. This is where my spidey-sense starts tingling. If `refcount` hits zero *within* `nr_neigh_put`, that object gets freed. Then, *after* the call to `nr_neigh_put` completes, we hit `nr_neigh->count` again, potentially leading to a use-after-free!
So, the intended logic, as I interpret it, is this: `nr_dec_obs` is probably handling obsolescence, effectively removing a route or decrementing its usage. The `count` reflects the number of routes using this neighbor. If that count drops to zero *and* the neighbor isn't locked (implying it's safe to remove), we call `nr_remove_neigh` to clean it up.
The problem, though, is the order of operations. `nr_neigh_put` could free the object *before* we've checked the `count` again. We're removing a route, we're decrementing the `count` of routes that reference this neighbor. Then we're calling `nr_neigh_put`, which is reducing `refcount` and potentially freeing the memory, and finally we are accessing the `count` again which might trigger a use-after-free scenario. This is definitely a UAF, and we need to verify the implementation of `nr_neigh_put` to confirm.
|
| 31/4 |
2026/01/28 22:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/net/netrom.h IncludeLines:true Name:nr_neigh_put]
Results: map[SourceCode: 137: static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
138: {
139: if (refcount_dec_and_test(&nr_neigh->refcount)) {
140: if (nr_neigh->ax25)
141: ax25_cb_put(nr_neigh->ax25);
142: kfree(nr_neigh->digipeat);
143: kfree(nr_neigh);
144: }
145: }
SourceFile:include/net/netrom.h]
|
| 32/4 |
2026/01/28 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 12757
output: 44
thoughts: 78
Thoughts: Okay, here's my understanding, thinking through this issue:
**Analyzing the `nr_neigh_put` and `nr_remove_neigh` Logic**
Right, so `nr_neigh_put` definitely releases the `nr_neigh` resource. The core problem is that we're potentially calling it in a way that's incorrect. It seems we need to verify a couple of things before triggering `nr_neigh_put`, specifically, that the `count` and `locked` variables have reached the expected states. This is basic reference counting/locking behavior, so that much is clear.
However, I need to be cautious. The other function in play, `nr_remove_neigh`, is likely also doing things with the same data structures and very possibly, *also* placing a reference or performing list manipulation related to `nr_neigh`. I need to figure out how these two functions interact. What happens if `nr_remove_neigh` frees the same resource? We could see a double-free, a corruption, or some other undesirable memory issues if those functions aren't aligned.
The next logical step is to dive into `nr_remove_neigh` and fully understand its behavior and confirm the shared interactions.
|
| 33/4 |
2026/01/28 22:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_remove_neigh]
Results: map[SourceCode: 305: static void nr_remove_neigh(struct nr_neigh *nr_neigh)
306: {
307: spin_lock_bh(&nr_neigh_list_lock);
308: __nr_remove_neigh(nr_neigh);
309: spin_unlock_bh(&nr_neigh_list_lock);
310: }
SourceFile:net/netrom/nr_route.c]
|
| 34/4 |
2026/01/28 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 13270
output: 45
thoughts: 10
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Investigating `__nr_remove_neigh`**
Hmm, so we're looking at network neighbour removal, are we? My initial thought is immediately drawn to the function `__nr_remove_neigh`. That naming convention strongly suggests it's a core, low-level function within the networking stack. Given the prefix, it's likely responsible for the *internal* mechanics of removing a network neighbor entry, rather than a top-level, user-facing call.
I'm instantly considering the implications. Is this about invalidating an entry due to a timeout, a change in link state, or perhaps an explicit deletion? What kind of locking is involved here? Are we dealing with spinlocks, read-write semaphores, or something more sophisticated to handle concurrent access? And, crucially, what are the potential race conditions we need to be mindful of during removal, especially if this function is called from an interrupt context or multiple threads simultaneously? We're going to need to look at how this function interacts with the neighbour cache, routing tables, and any associated state. What kind of cleanup is performed? Does it deallocate memory, update statistics, and notify other parts of the kernel about the change? We'll have to investigate that function to truly understand.
|
| 35/4 |
2026/01/28 22:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:__nr_remove_neigh]
Results: map[SourceCode: 296: static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
297: {
298: hlist_del_init(&nr_neigh->neigh_node);
299: nr_neigh_put(nr_neigh);
300: }
SourceFile:net/netrom/nr_route.c]
|
| 36/4 |
2026/01/28 22:57 |
llm |
patch-generator |
1m
Model:
Tokens:
input: 13728
output: 45
thoughts: 11344
Thoughts: **Analysis of Net/ROM Neighbour Removal**
Okay, so I've been wrestling with this Net/ROM neighbour removal code, and I *think* I've got a handle on the bug and a good fix. The core of the problem lies in how the `nr_dec_obs` function interacts with reference counting and neighbour list management. I'm seeing a potential Use-After-Free (UAF) condition, and it seems to stem from a subtle race condition related to dropping references and removing neighbours from a global list.
Here’s the breakdown of my thoughts:
1. **Reference Counting and Usage:** I’m dealing with two counters: `refcount` and `count`. `refcount` represents the overall existence of the `nr_neigh` object, handled by the standard kernel `refcount_t`. The `count` variable, I believe, tracks the *logical* usage of a neighbour – how many routes are actively using it. When a route is established, the `count` is incremented. When a route is removed (or, in this case, a route’s observation count drops to zero), the `count` is decremented.
2. **The `nr_dec_obs` Problem:** This function is where it gets tricky. It’s part of the process of decrementing a route's observation count. The code decrements `nr_neigh->count`. If that count goes to zero, the intent is to remove the neighbour from the global list using `nr_remove_neigh`. This function handles the removal, and also calls `nr_neigh_put` to drop the reference.
3. **The Race:** The issue arises because the code checks `count == 0` *after* calling `nr_neigh_put`. Here’s where the UAF comes in: if `nr_neigh_put` *frees* the `nr_neigh` object (because `refcount` hits zero), then the subsequent check of `count` or the call to `nr_remove_neigh` is an access to freed memory. That’s the UAF.
4. **Why `refcount` is 1 when `count` becomes 0**: The original code has an instance of a UAF report which mentions that `nr_neigh_put` freed the object. I need to figure out how `nr_neigh_put` could free the object. My understanding is that when the object is added to the list, its reference count is >= 2. The code in question decrements the count to 0, at which point the object should be removed from the list and freed. The report says the object has a reference count of 1. It also says `nr_neigh_put` freed the object. Thus, there are two possibilities: 1) the object was not added to the list, or 2) the decrement call happened due to a race. The first could happen due to a design problem, which the current implementation should protect against. The second is more likely: A double-removal type race. I need to make sure this is the case.
5. **The Fix - Reordering and Safety:** The core of the fix is to read the values for `count` *before* the `nr_neigh_put` call. The code will look something like this:
```c
nr_neigh->count--;
// Read count before put
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
nr_neigh_put(nr_neigh);
```
The important bit: if `count == 0` and the object is not locked, *then* `nr_remove_neigh` is called, *then* we finally call `nr_neigh_put`.
6. **`nr_remove_neigh` and its Idempotency:** The `nr_remove_neigh` function takes the global lock and removes the neighbour from the list. It currently also calls `nr_neigh_put` which is problematic. I'm going to make a small change to its helper function, `__nr_remove_neigh`, to make it idempotent (safe to call even if the object isn't actually in the list). This is the key. The function will be changed to check if the neighbour is still on the list before attempting to remove it and drop the reference:
```c
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
if (!hlist_unhashed(&nr_neigh->neigh_node)) {
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
|
| 37/4 |
2026/01/28 22:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:__nr_remove_neigh]
Results: map[SourceCode: 296: static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
297: {
298: hlist_del_init(&nr_neigh->neigh_node);
299: nr_neigh_put(nr_neigh);
300: }
SourceFile:net/netrom/nr_route.c]
|
| 38/4 |
2026/01/28 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 26256
output: 44
thoughts: 8
Thoughts: Okay, I'm ready. Let's get this done. I will summarize the thought process as if it were my own. Here we go:
**Analyzing `nr_dec_obs`**
Alright, let's dive into this. I'm looking at `nr_dec_obs` and immediately my mind starts processing. I'm assuming this is a numerical variable, likely representing something like the number of observations related to a particular decision or perhaps the number of decisions an observer has made. My initial approach depends heavily on the context, so I need to establish what "decision" and "observation" refer to specifically.
If this is coming from a statistical modeling context, I'll need to know the distribution this variable is expected to follow. Is it likely to be Poisson, reflecting counts? Or perhaps something else, maybe a count of unique events? Are there any potential biases in the way this data was collected that might influence the interpretation of this variable? Is it a dependent, independent or control variable?
My next consideration is how this variable might interact with others. Are there other variables in this dataset that might be correlated with `nr_dec_obs`? And what are the implications of those correlations? For example, if it's tied to the complexity of the observed systems, an increase in `nr_dec_obs` should be expected. A decrease might suggest simplification.
If I'm thinking about causal inference, I need to consider whether `nr_dec_obs` could be a mediator, moderator, or confounder in the relationship between other variables of interest. Careful consideration will be necessary to account for it's place within the model.
Essentially, I need to know the specific meaning in order to fully comprehend and properly analyze its purpose. Further context is needed.
|
| 39/4 |
2026/01/28 22:59 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_dec_obs]
Results: map[SourceCode: 445: /*
446: * Decrement the obsolescence count by one. If a route is reduced to a
447: * count of zero, remove it. Also remove any unlocked neighbours with
448: * zero nodes routing via it.
449: */
450: static int nr_dec_obs(void)
451: {
452: struct nr_neigh *nr_neigh;
453: struct nr_node *s;
454: struct hlist_node *nodet;
455: int i;
456:
457: spin_lock_bh(&nr_node_list_lock);
458: nr_node_for_each_safe(s, nodet, &nr_node_list) {
459: nr_node_lock(s);
460: for (i = 0; i < s->count; i++) {
461: switch (s->routes[i].obs_count) {
462: case 0: /* A locked entry */
463: break;
464:
465: case 1: /* From 1 -> 0 */
466: nr_neigh = s->routes[i].neighbour;
467:
468: nr_neigh->count--;
469: nr_neigh_put(nr_neigh);
470:
471: if (nr_neigh->count == 0 && !nr_neigh->locked)
472: nr_remove_neigh(nr_neigh);
473:
474: s->count--;
475:
476: switch (i) {
477: case 0:
478: s->routes[0] = s->routes[1];
479: fallthrough;
480: case 1:
481: s->routes[1] = s->routes[2];
482: break;
483: case 2:
484: break;
485: }
486: break;
487:
488: default:
489: s->routes[i].obs_count--;
490: break;
491:
492: }
493: }
494:
495: if (s->count <= 0)
496: nr_remove_node_locked(s);
497: nr_node_unlock(s);
498: }
499: spin_unlock_bh(&nr_node_list_lock);
500:
501: return 0;
502: }
SourceFile:net/netrom/nr_route.c]
|
| 40/4 |
2026/01/28 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 27476
output: 163
thoughts: 760
Thoughts: **Analyzing and Applying the Changes**
Okay, let's break this down. My goal here is to address a potential use-after-free (UAF) vulnerability. I've been given some code, and my expertise tells me where to look.
First, I'm reviewing `__nr_remove_neigh`. This looks straightforward. It's an inline function that, if the `nr_neigh` isn't in a hash list (checked with `hlist_unhashed`), simply returns. If it *is* in a list, it's removed and its reference count is decremented. The change here isn't immediately obvious, but I'll keep it in mind as I process the other edits.
Now, focusing on the core of the problem, the code snippet from `nr_dec_obs`. Here's what's happening: a neighbour `nr_neigh`'s count is decremented. If the count goes to zero *and* the neighbour isn't locked, the code then attempts to remove it via `nr_remove_neigh`. Critically, after the check, the code decrements the reference count with `nr_neigh_put`.
The potential issue is pretty clear: if `nr_neigh->count` is zero, and it's removed, what happens if another thread tries to access it *after* it's been freed but *before* the check has been made? That's my main focus: ensuring that reads to `nr_neigh` after it is potentially deallocated are prevented.
The fix is obvious, and it's what I'm going to implement: I'll move the call to `nr_neigh_put` *after* the `nr_remove_neigh` check. This ensures that the reference count is decremented *only* after it's guaranteed safe to do so. This approach is standard practice for this type of issue.
Let's think through the scenarios.
Scenario 1: Refcount is 1. `nr_remove_neigh` does nothing (since `__nr_remove_neigh` is safe for double-put, by checking unhashed). The following `nr_neigh_put` decrements to zero, freeing it.
Scenario 2: Refcount is 2. `nr_remove_neigh` removes the item and decrements the refcount to 1. The following `nr_neigh_put` decrements to zero, freeing it.
Scenario 3: It is possible the `nr_neigh` is not in the list (refcount=1).
- `nr_remove_neigh` does nothing (since `hlist_unhashed` is checked). `nr_neigh_put` frees it.
Now, is `hlist_unhashed` really a safe check? The docs say it returns true if `pprev` is NULL. Does this align with the expected behavior here?
Yes, it does. `INIT_HLIST_NODE` *initializes* `pprev` to NULL. When added to the hash list, it's set to a valid pointer. When removed with `hlist_del_init`, it's set back to NULL.
So `hlist_unhashed` is correct, and will provide a safe check here.
Are there any other possible race conditions with list membership? Let's check:
`nr_add_neigh`:
```c
nr_neigh = kzalloc(...)
if (!nr_neigh) return ...
// init fields
refcount_set(&nr_neigh->refcount, 1);
INIT_HLIST_NODE(&nr_neigh->neigh_node); // pprev = NULL
// ...
hlist_add_head(&nr_neigh->neigh_node, ...) // pprev set
```
So, after allocation, the `nr_neigh` struct is initialized, and the `neigh_node` field *will* have `pprev=NULL` before it's even added to the list. That confirms the code's consistency.
It's all looking good. I am going to make the two edits, specifically:
1. Make no change to `__nr_remove_neigh`. It's already correct.
2. Move the `nr_neigh_put` *after* the count check in `nr_dec_obs`.
I am not combining the edits as the code is too far apart.
I'm confident in these changes. Let's get them applied.
|
| 41/4 |
2026/01/28 22:59 |
tool |
codeeditor |
0m
Args: map[CurrentCode:static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
} NewCode:static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
if (hlist_unhashed(&nr_neigh->neigh_node))
return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
} SourceFile:net/netrom/nr_route.c]
Results:
|
| 42/4 |
2026/01/28 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 29367
output: 209
thoughts: 9
Thoughts: Okay, here's my summary, presented as a stream of thought:
**Focusing In on `nr_dec_obs`**
Alright, let's zero in on this `nr_dec_obs` variable. My gut tells me this is where the action is, the key piece of the puzzle we need to refine. It’s the variable that needs the most urgent attention. We have to make sure the variable is functioning as intended. We need to define the function of this variable specifically, and how its edits must affect the program as a whole.
|
| 43/4 |
2026/01/28 22:59 |
tool |
codeeditor |
0m
Args: map[CurrentCode: case 1: /* From 1 -> 0 */
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
s->count--; NewCode: case 1: /* From 1 -> 0 */
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
nr_neigh_put(nr_neigh);
s->count--; SourceFile:net/netrom/nr_route.c]
Results:
|
| 44/4 |
2026/01/28 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 29710
output: 774
thoughts: 229
Thoughts: **UAF Bug Resolved: A Comprehensive Approach**
Okay, so I've squashed that use-after-free bug in the `nr_dec_obs` function. My approach was meticulous, as always. First, I reordered the code in `nr_dec_obs` to ensure that `nr_neigh->count` and `locked` are accessed *before* `nr_neigh_put`. This simple rearrangement eliminates the UAF read by ensuring the data is valid at the time it's accessed. Elegant, really.
Then, to tackle a potentially hidden double-free scenario, I modified `__nr_remove_neigh`. Now, it explicitly checks if the node is actually hashed (present in the list) before attempting to remove and put it. This prevents a nasty double-put/double-free if `nr_remove_neigh` is called on a node that isn't supposed to be there, which can happen if the `refcount` was already at 1 before that logic was entered. We have to be careful with refcounts.
This combined fix covers both the explicit UAF report *and* that subtle, potentially insidious, double-free lurking in the shadows. I consider this a complete solution to the problem, and a good example of careful code analysis.
Now, I need to make sure `nr_remove_neigh` calls `__nr_remove_neigh` safely. Since `nr_remove_neigh` acquires a lock, checking `hlist_unhashed` *within* `__nr_remove_neigh` is perfectly fine. That should be a bulletproof combination. Yes, the fix looks complete. Time to move on.
|
| 45/3 |
2026/01/28 23:00 |
action |
test-patch |
9m
Results: map[PatchDiff:diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 9cc29ae85..496b328d1 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -295,6 +295,8 @@ static void nr_remove_node_locked(struct nr_node *nr_node)
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
+ if (hlist_unhashed(&nr_neigh->neigh_node))
+ return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
@@ -462,16 +464,17 @@ static int nr_dec_obs(void)
case 0: /* A locked entry */
break;
- case 1: /* From 1 -> 0 */
- nr_neigh = s->routes[i].neighbour;
+ case 1: /* From 1 -> 0 */
+ nr_neigh = s->routes[i].neighbour;
- nr_neigh->count--;
- nr_neigh_put(nr_neigh);
+ nr_neigh->count--;
+
+ if (nr_neigh->count == 0 && !nr_neigh->locked)
+ nr_remove_neigh(nr_neigh);
- if (nr_neigh->count == 0 && !nr_neigh->locked)
- nr_remove_neigh(nr_neigh);
+ nr_neigh_put(nr_neigh);
- s->count--;
+ s->count--;
switch (i) {
case 0:
TestError:]
|
| 46/1 |
2026/01/28 23:09 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:davem@davemloft.net Name:David S. Miller To:true] map[Email:edumazet@google.com Name:Eric Dumazet To:true] map[Email:horms@kernel.org Name:Simon Horman To:false] map[Email:kuba@kernel.org Name:Jakub Kicinski To:true] map[Email:linux-hams@vger.kernel.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:netdev@vger.kernel.org Name: To:true] map[Email:pabeni@redhat.com Name:Paolo Abeni To:true]]]
|
| 47/1 |
2026/01/28 23:09 |
agent |
description-generator |
1m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with writing a commit description for
a kernel bug fixing commit. The description should start with a one-line summary,
and then include description of the bug being fixed, and how it's fixed by the provided patch.
Your final reply should contain only the text of the commit description.
Phrase the one-line summary so that it is not longer than 72 characters.
The rest of the description must be word-wrapped at 72 characters.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
==================================================================
BUG: KASAN: slab-use-after-free in nr_dec_obs net/netrom/nr_route.c:471 [inline]
BUG: KASAN: slab-use-after-free in nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
Read of size 2 at addr ffff888048ccf732 by task syz-executor102/6284
CPU: 1 UID: 0 PID: 6284 Comm: syz-executor102 Not tainted syzkaller #1 PREEMPT(full)
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x10e/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x17e/0x810 mm/kasan/report.c:482
kasan_report+0x147/0x180 mm/kasan/report.c:595
nr_dec_obs net/netrom/nr_route.c:471 [inline]
nr_rt_ioctl+0x594/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fb502ddcd39
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffd784c5ad8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 00007fb502ddcd39
RDX: 0000000000000000 RSI: 00000000000089e2 RDI: 0000000000000005
RBP: 0000000000000000 R08: 00007fb502e4123c R09: 00007fb502e4123c
R10: 00007fb502e4123c R11: 0000000000000246 R12: 00007ffd784c5afc
R13: 00007ffd784c5b30 R14: 00007ffd784c5b10 R15: 0000000000000012
</TASK>
Allocated by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__kmalloc_cache_noprof+0x3e2/0x700 mm/slub.c:5780
kmalloc_noprof include/linux/slab.h:957 [inline]
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
nr_rt_ioctl+0xbfb/0xd20 net/netrom/nr_route.c:651
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 6284:
kasan_save_stack mm/kasan/common.c:57 [inline]
kasan_save_track+0x3e/0x80 mm/kasan/common.c:78
kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x58/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2540 [inline]
slab_free mm/slub.c:6674 [inline]
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
nr_rt_ioctl+0x2e7/0xd20 net/netrom/nr_route.c:692
sock_do_ioctl+0xdc/0x300 net/socket.c:1254
sock_ioctl+0x576/0x790 net/socket.c:1375
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888048ccf700
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 50 bytes inside of
freed 64-byte region [ffff888048ccf700, ffff888048ccf740)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x48ccf
anon flags: 0x4fff00000000000(node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000000 ffff88801a0418c0 0000000000000000 dead000000000001
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x52c40(GFP_NOFS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP), pid 5509, tgid 5509 (dhcpcd-run-hook), ts 35445032815, free_ts 35417982511
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x234/0x290 mm/page_alloc.c:1884
prep_new_page mm/page_alloc.c:1892 [inline]
get_page_from_freelist+0x24d5/0x2570 mm/page_alloc.c:3945
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5240
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2486
alloc_slab_page mm/slub.c:3075 [inline]
allocate_slab+0x86/0x3b0 mm/slub.c:3248
new_slab mm/slub.c:3302 [inline]
___slab_alloc+0xe70/0x1860 mm/slub.c:4656
__slab_alloc+0x65/0x100 mm/slub.c:4779
__slab_alloc_node mm/slub.c:4855 [inline]
slab_alloc_node mm/slub.c:5251 [inline]
__do_kmalloc_node mm/slub.c:5656 [inline]
__kmalloc_noprof+0x47d/0x800 mm/slub.c:5669
kmalloc_noprof include/linux/slab.h:961 [inline]
kzalloc_noprof include/linux/slab.h:1094 [inline]
tomoyo_encode2 security/tomoyo/realpath.c:45 [inline]
tomoyo_encode+0x28a/0x550 security/tomoyo/realpath.c:80
tomoyo_realpath_from_path+0x58d/0x5d0 security/tomoyo/realpath.c:283
tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
tomoyo_path_perm+0x214/0x580 security/tomoyo/file.c:822
security_inode_getattr+0x12f/0x330 security/security.c:1869
vfs_getattr fs/stat.c:259 [inline]
vfs_fstat fs/stat.c:281 [inline]
vfs_fstatat+0xb1/0x170 fs/stat.c:373
__do_sys_newfstatat fs/stat.c:542 [inline]
__se_sys_newfstatat fs/stat.c:536 [inline]
__x64_sys_newfstatat+0x116/0x190 fs/stat.c:536
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xe8/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 30 tgid 30 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1433 [inline]
__free_frozen_pages+0xbb8/0xd30 mm/page_alloc.c:2973
vfree+0x25a/0x400 mm/vmalloc.c:3466
delayed_vfree_work+0x55/0x80 mm/vmalloc.c:3385
process_one_work kernel/workqueue.c:3257 [inline]
process_scheduled_works+0xa45/0x1670 kernel/workqueue.c:3340
worker_thread+0x8a0/0xda0 kernel/workqueue.c:3421
kthread+0x711/0x8a0 kernel/kthread.c:463
ret_from_fork+0x510/0xa50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:246
Memory state around the buggy address:
ffff888048ccf600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888048ccf680: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
>ffff888048ccf700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888048ccf780: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff888048ccf800: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
==================================================================
The explanation of the root cause of the bug is:
The crash is a **Use-After-Free (UAF)** in the function `nr_dec_obs` in `net/netrom/nr_route.c`.
### Root Cause Analysis
1. **The Bug**: The function `nr_dec_obs` decrements the reference count of a `nr_neigh` object and then accesses its members (`count` and `locked`) potentially after the object has been freed.
```c
// net/netrom/nr_route.c
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
nr_neigh_put(nr_neigh); // <--- Drops reference. If refcount hits 0, object is freed.
if (nr_neigh->count == 0 && !nr_neigh->locked) // <--- UAF! Accessing 'count' (offset 50) of freed object.
nr_remove_neigh(nr_neigh);
```
2. **Memory Layout Verification**:
The crash report states the read is at offset **50** inside the 64-byte object.
Structure layout of `struct nr_neigh`:
* 0: `struct hlist_node neigh_node` (16 bytes)
* 16: `ax25_address callsign` (7 bytes)
* 23: padding (1 byte)
* 24: `ax25_digi *digipeat` (8 bytes)
* 32: `ax25_cb *ax25` (8 bytes)
* 40: `struct net_device *dev` (8 bytes)
* 48: `unsigned char quality` (1 byte)
* 49: `unsigned char locked` (1 byte)
* **50**: `unsigned short count` (2 bytes) <-- **Exact match**
3. **Failure Scenario**:
Normally, a `nr_neigh` object referenced by a route has a reference count of at least 2 (one for the global `nr_neigh_list`, one for the route). However, in the crash scenario, the `nr_neigh` object has a reference count of **1** when entering the block (likely because it was removed from the global list but still referenced by a route due to a race or inconsistent state cleanup).
When `nr_neigh_put(nr_neigh)` is called, the reference count drops to 0, and the object is freed (`kfree`).
The subsequent check `if (nr_neigh->count == 0 ...)` attempts to read from the freed memory, triggering KASAN.
### Fix Proposal
To fix this, the code must not access `nr_neigh` after `nr_neigh_put`. The condition should be checked before dropping the reference, or the logic rearranged to ensure the object remains valid during access.
Example safe pattern:
```c
nr_neigh->count--;
bool remove = (nr_neigh->count == 0 && !nr_neigh->locked);
nr_neigh_put(nr_neigh);
if (remove)
nr_remove_neigh(nr_neigh);
```
*Note: Care must be taken ensuring `nr_remove_neigh` is safe to call if `nr_neigh_put` has already freed the object (which implies a double-free bug elsewhere if the object was already unlisted), or if `nr_remove_neigh` handles unhashed nodes safely.*
The diff of the bug fix is:
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 9cc29ae85..496b328d1 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -295,6 +295,8 @@ static void nr_remove_node_locked(struct nr_node *nr_node)
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
+ if (hlist_unhashed(&nr_neigh->neigh_node))
+ return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
@@ -462,16 +464,17 @@ static int nr_dec_obs(void)
case 0: /* A locked entry */
break;
- case 1: /* From 1 -> 0 */
- nr_neigh = s->routes[i].neighbour;
+ case 1: /* From 1 -> 0 */
+ nr_neigh = s->routes[i].neighbour;
- nr_neigh->count--;
- nr_neigh_put(nr_neigh);
+ nr_neigh->count--;
+
+ if (nr_neigh->count == 0 && !nr_neigh->locked)
+ nr_remove_neigh(nr_neigh);
- if (nr_neigh->count == 0 && !nr_neigh->locked)
- nr_remove_neigh(nr_neigh);
+ nr_neigh_put(nr_neigh);
- s->count--;
+ s->count--;
switch (i) {
case 0:
Additional description of the patch:
The bug is a Use-After-Free (UAF) in `net/netrom/nr_route.c`. The function `nr_dec_obs` decrements a reference count using `nr_neigh_put(nr_neigh)` and subsequently accesses `nr_neigh->count` and `nr_neigh->locked`. If `nr_neigh_put` drops the last reference, `nr_neigh` is freed, making the subsequent access invalid.
To fix this, the code should check `nr_neigh->count` and `nr_neigh->locked` *before* calling `nr_neigh_put`.
However, simply reordering the code introduces a potential Double Free or refcount underflow. If `nr_neigh` is not in the global neighbour list (e.g., refcount is 1), `nr_dec_obs` might call `nr_remove_neigh`. `nr_remove_neigh` unconditionally removes the node from the list and calls `nr_neigh_put` (dropping the reference presumably held by the list). If the node was not in the list, `nr_remove_neigh` would incorrectly drop a reference it doesn't own, leading to a double free when `nr_dec_obs` subsequently calls `nr_neigh_put`.
Therefore, the fix involves two changes:
1. Modify `__nr_remove_neigh` to check if the node is actually in the list (`!hlist_unhashed`) before removing it and dropping the reference. This makes `nr_remove_neigh` idempotent and safe to call on unhashed nodes.
2. In `nr_dec_obs`, reorder the operations to access `nr_neigh` members and conditionally call `nr_remove_neigh` *before* calling `nr_neigh_put`.
These changes ensure that we do not access freed memory and do not drop references we do not hold.
Allocated by task 6284:
...
nr_add_node+0x84a/0x23a0 net/netrom/nr_route.c:146
...
Freed by task 6284:
...
kfree+0x1c0/0x660 mm/slub.c:6882
nr_dec_obs net/netrom/nr_route.c:469 [inline]
...
The patch is as follows:
```c
--- net/netrom/nr_route.c
+++ net/netrom/nr_route.c
@@ -296,6 +296,8 @@
static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
{
+ if (hlist_unhashed(&nr_neigh->neigh_node))
+ return;
hlist_del_init(&nr_neigh->neigh_node);
nr_neigh_put(nr_neigh);
}
@@ -466,11 +468,10 @@
nr_neigh = s->routes[i].neighbour;
nr_neigh->count--;
- nr_neigh_put(nr_neigh);
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
+ nr_neigh_put(nr_neigh);
+
s->count--;
switch (i) {
```
Reply: net/netrom: Fix use-after-free in nr_dec_obs
A use-after-free occurs in nr_dec_obs() when a neighbor's reference
count is decremented and the object is freed before its 'count' and
'locked' fields are accessed.
The function nr_dec_obs() calls nr_neigh_put() before checking
nr_neigh->count and nr_neigh->locked. If nr_neigh_put() drops the
last reference, the object is freed, causing a UAF on the subsequent
access.
To fix this, move the nr_neigh_put() call after the field accesses.
However, simply moving the call reveals a potential issue in
nr_remove_neigh(). This function unconditionally calls nr_neigh_put()
under the assumption that it is removing the node from the list and
consuming the list's reference. If the node is not in the list (unhashed),
nr_remove_neigh() would incorrectly drop a reference it does not hold,
leading to a potential double-free when nr_neigh_put() is called again
in nr_dec_obs().
Modify __nr_remove_neigh() to check hlist_unhashed() and only remove the
node and drop the reference if it is actually hashed. This ensures
nr_remove_neigh() is safe to call on unhashed nodes and prevents
refcount underflows.
|
| 48/2 |
2026/01/28 23:09 |
llm |
description-generator |
0m
Model:
Tokens:
input: 8316
output: 29
thoughts: 338
Thoughts: **Analyzing a Kernel Bug Fix: A Thought Process**
Okay, so I'm looking at this kernel bug fix – a UAF in `net/netrom/nr_route.c`. The core of the problem is that `nr_neigh_put()` is being called prematurely, before the code accesses `nr_neigh->count` and `nr_neigh->locked`. The proposed patch looks like it addresses this in two ways: it's doing a hash check in `__nr_remove_neigh` and moving the `nr_neigh_put()` call in `nr_dec_obs` to the right location.
Before I can give this a proper commit description, I need to verify that this description is accurate and also completely understand the root cause. This means I need to double-check the details of how `nr_neigh_put` and `nr_remove_neigh` actually work. Specifically, I need to confirm these key aspects:
* Does `nr_neigh_put` actually decrement the reference count and free the structure if the count hits zero?
* Does `nr_remove_neigh` indeed call `__nr_remove_neigh` as suggested?
* And finally, the refcounting mechanism for `nr_neigh` -- does it all make sense in the context of this explanation? I want to make sure I haven't missed a key aspect of this memory management.
Time to dive into the code. Let's use `codeexpert` and start by examining `net/netrom/nr_route.c`. I need to nail down the definitions of `nr_neigh_put`, `nr_remove_neigh`, `nr_dec_obs`, and the structure definition of `nr_neigh` itself. I'll read the code now, starting with what's defined in the netrom routing file. Let's see what's in there...
|
| 49/2 |
2026/01/28 23:09 |
tool |
codesearch-file-index |
0m
Args: map[SourceFile:net/netrom/nr_route.c]
Results: map[Entities:[map[Kind:function Name:__nr_remove_neigh] map[Kind:function Name:nr_add_neigh] map[Kind:function Name:nr_add_node] map[Kind:function Name:nr_ax25_dev_get] map[Kind:function Name:nr_call_to_digi] map[Kind:function Name:nr_dec_obs] map[Kind:function Name:nr_del_neigh] map[Kind:function Name:nr_del_node] map[Kind:function Name:nr_dev_first] map[Kind:function Name:nr_dev_get] map[Kind:function Name:nr_link_failed] map[Kind:function Name:nr_neigh_get_dev] map[Kind:function Name:nr_neigh_next] map[Kind:function Name:nr_neigh_show] map[Kind:function Name:nr_neigh_start] map[Kind:function Name:nr_neigh_stop] map[Kind:function Name:nr_node_get] map[Kind:function Name:nr_node_next] map[Kind:function Name:nr_node_show] map[Kind:function Name:nr_node_start] map[Kind:function Name:nr_node_stop] map[Kind:function Name:nr_remove_neigh] map[Kind:function Name:nr_remove_node_locked] map[Kind:function Name:nr_route_frame] map[Kind:function Name:nr_rt_device_down] map[Kind:function Name:nr_rt_free] map[Kind:function Name:nr_rt_ioctl] map[Kind:function Name:re_sort_routes]]]
|
| 50/2 |
2026/01/28 23:09 |
llm |
description-generator |
0m
Model:
Tokens:
input: 9560
output: 133
thoughts: 214
Thoughts: **Analyzing the Netrom Code**
Alright, I've got the lay of the land, I understand the functions involved. Now, I need to get a clear picture of the `nr_neigh` structure. My intuition is telling me it's likely defined in a header file, something along the lines of `include/net/netrom.h`. I'll do a quick check of `net/netrom/nr_route.c` to see if it's hiding in there, but I'm betting on a header. Actually, it would be easiest to just search the code base for the `struct nr_neigh` definition directly to be sure.
Beyond that, I'm interested in the actual implementation of several functions. Specifically, I want to dive into `nr_dec_obs`, `nr_remove_neigh`, `__nr_remove_neigh`, and `nr_neigh_put`. I noticed `nr_neigh_put` wasn't explicitly listed earlier, so it might be inlined within a header or defined elsewhere, maybe in another part of the file or in another file entirely, like a helper function.
So, I'm going to scan `net/netrom/nr_route.c` to hunt down the implementations of `nr_dec_obs`, `nr_remove_neigh`, and potentially `nr_neigh_put` to solidify my understanding.
|
| 51/2 |
2026/01/28 23:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_dec_obs]
Results: map[SourceCode: 445: /*
446: * Decrement the obsolescence count by one. If a route is reduced to a
447: * count of zero, remove it. Also remove any unlocked neighbours with
448: * zero nodes routing via it.
449: */
450: static int nr_dec_obs(void)
451: {
452: struct nr_neigh *nr_neigh;
453: struct nr_node *s;
454: struct hlist_node *nodet;
455: int i;
456:
457: spin_lock_bh(&nr_node_list_lock);
458: nr_node_for_each_safe(s, nodet, &nr_node_list) {
459: nr_node_lock(s);
460: for (i = 0; i < s->count; i++) {
461: switch (s->routes[i].obs_count) {
462: case 0: /* A locked entry */
463: break;
464:
465: case 1: /* From 1 -> 0 */
466: nr_neigh = s->routes[i].neighbour;
467:
468: nr_neigh->count--;
469: nr_neigh_put(nr_neigh);
470:
471: if (nr_neigh->count == 0 && !nr_neigh->locked)
472: nr_remove_neigh(nr_neigh);
473:
474: s->count--;
475:
476: switch (i) {
477: case 0:
478: s->routes[0] = s->routes[1];
479: fallthrough;
480: case 1:
481: s->routes[1] = s->routes[2];
482: break;
483: case 2:
484: break;
485: }
486: break;
487:
488: default:
489: s->routes[i].obs_count--;
490: break;
491:
492: }
493: }
494:
495: if (s->count <= 0)
496: nr_remove_node_locked(s);
497: nr_node_unlock(s);
498: }
499: spin_unlock_bh(&nr_node_list_lock);
500:
501: return 0;
502: }
SourceFile:net/netrom/nr_route.c]
|
| 52/2 |
2026/01/28 23:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:nr_remove_neigh]
Results: map[SourceCode: 305: static void nr_remove_neigh(struct nr_neigh *nr_neigh)
306: {
307: spin_lock_bh(&nr_neigh_list_lock);
308: __nr_remove_neigh(nr_neigh);
309: spin_unlock_bh(&nr_neigh_list_lock);
310: }
SourceFile:net/netrom/nr_route.c]
|
| 53/2 |
2026/01/28 23:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netrom/nr_route.c IncludeLines:true Name:__nr_remove_neigh]
Results: map[SourceCode: 296: static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
297: {
298: hlist_del_init(&nr_neigh->neigh_node);
299: nr_neigh_put(nr_neigh);
300: }
SourceFile:net/netrom/nr_route.c]
|
| 54/2 |
2026/01/28 23:10 |
llm |
description-generator |
0m
Model:
Tokens:
input: 11241
output: 82
thoughts: 544
Thoughts: **Analyzing a Potential Use-After-Free Vulnerability**
Okay, the user's report lines up with what I'm seeing in the code. In the `nr_dec_obs` function, lines 468-472 seem problematic. Specifically, line 469, `nr_neigh_put(nr_neigh)`, is immediately suspect because it *might* free the `nr_neigh` structure. Then, line 471 accesses `nr_neigh->count`. That's the classic UAF scenario I'm looking for.
My initial thought is to simply move the `nr_neigh_put(nr_neigh)` call *after* the check on line 471:
```c
nr_neigh->count--;
// nr_neigh_put(nr_neigh); // Moved down
if (nr_neigh->count == 0 && !nr_neigh->locked)
nr_remove_neigh(nr_neigh);
nr_neigh_put(nr_neigh);
```
However, I need to understand what's happening in `nr_remove_neigh` now, and whether or not there are any other side effects.
Looking at `nr_remove_neigh`, it appears to call `__nr_remove_neigh`:
```c
296: static inline void __nr_remove_neigh(struct nr_neigh *nr_neigh)
297: {
298: hlist_del_init(&nr_neigh->neigh_node);
299: nr_neigh_put(nr_neigh);
300: }
```
So, `nr_remove_neigh` calls `nr_neigh_put` again, after removing the neighbour from a list. I assume that after the neighbour is removed from a list, it also decrements the reference. I now need to get some context and understand the logic of this code.
The logic in `nr_dec_obs` seems to relate to the removal of a route that uses `nr_neigh`. We decrement `nr_neigh->count`, which probably means the number of routes using it. This is followed by dropping the reference to `nr_neigh`. I'm going to bet that `nr_neigh->count` is *not* a refcount, because this code is written in C.
Okay, let's step back and identify the details of what's happening. The key here is to determine how the `nr_neigh` structure is managed. I need to understand what `nr_neigh_put` does and what the `nr_neigh` struct actually looks like. I'm guessing that it has some sort of reference counting mechanism, probably an `atomic_t ref` or similar. I need to check how it all fits together. Given the naming conventions, it is likely in `include/net/netrom.h`. I'll go have a look in that file.
|
| 55/2 |
2026/01/28 23:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/net/netrom.h IncludeLines:true Name:nr_neigh_put]
Results: map[SourceCode: 137: static __inline__ void nr_neigh_put(struct nr_neigh *nr_neigh)
138: {
139: if (refcount_dec_and_test(&nr_neigh->refcount)) {
140: if (nr_neigh->ax25)
141: ax25_cb_put(nr_neigh->ax25);
142: kfree(nr_neigh->digipeat);
143: kfree(nr_neigh);
144: }
145: }
SourceFile:include/net/netrom.h]
|
| 56/2 |
2026/01/28 23:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/net/netrom.h IncludeLines:true Name:nr_neigh]
Results: map[SourceCode: 89: struct nr_neigh {
90: struct hlist_node neigh_node;
91: ax25_address callsign;
92: ax25_digi *digipeat;
93: ax25_cb *ax25;
94: struct net_device *dev;
95: unsigned char quality;
96: unsigned char locked;
97: unsigned short count;
98: unsigned int number;
99: unsigned char failed;
100: refcount_t refcount;
101: };
SourceFile:include/net/netrom.h]
|
| 57/2 |
2026/01/28 23:10 |
llm |
description-generator |
1m
Model:
Tokens:
input: 12885
output: 304
thoughts: 5710
Thoughts: **net/netrom: Fix use-after-free in nr_dec_obs**
Okay, here's the situation. I've been looking at this code in `net/netrom/nr_route.c`, and there's a nasty Use-After-Free (UAF) bug lurking in `nr_dec_obs()`. It's all about how `nr_neigh` objects, which represent neighbors, are managed. Each neighbor has a `count` (unsigned short) that tracks the number of routes using it and a `refcount` managed with `nr_neigh_put` and the hlist in `nr_neigh_list`.
The problem boils down to this: `nr_neigh_put()` is called too early in `nr_dec_obs()`. It decrements a reference counter. The bug is that we do an access to `nr_neigh->count` and `!nr_neigh->locked` *after* the `nr_neigh_put()` call. If `nr_neigh_put` drops the last reference (meaning `refcount` is now 0), the `nr_neigh` object is freed. Any subsequent access to the `count` or `locked` fields would result in the UAF.
So, the obvious fix is to move `nr_neigh_put(nr_neigh)` down, so the accesses come *before* the decrement. But, there is a catch! The function `nr_remove_neigh()` unconditionally calls `nr_neigh_put()`. This function assumes that the neighbor is in the global list, so that it can decrement the list's reference. However, if the neighbor is *not* in the list, then `nr_remove_neigh()` is dropping a reference it doesn't own (a double-free or reference count underflow). This can happen because we also have a `nr_neigh` linked by a route.
The fix I've worked out involves modifying `__nr_remove_neigh()` to prevent that double decrement. Now, it checks if the neighbor is actually in the list (using `hlist_unhashed()`) before calling `nr_neigh_put()`. This makes `nr_remove_neigh` idempotent when called on an unhashed neighbor.
So, the overall fix does two things:
1. Move the `nr_neigh_put()` after accessing `nr_neigh->count` and `nr_neigh->locked` to prevent the UAF.
2. Modify `__nr_remove_neigh()` to prevent an unnecessary decrement in `nr_remove_neigh()` so we don't end up dropping a ref when the neighbor is not in the list.
The first part of the fix prevents the UAF. The second is a correctness improvement. This solves the reported KASAN issue: BUG: KASAN: slab-use-after-free in nr_dec_obs net/netrom/nr_route.c:471 \[inline] Read of size 2 at addr ... The access at 471 is now safe. Looks like it's a solid fix!
|