public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: bonding: fix NULL deref in bond_debug_rlb_hash_show
@ 2026-03-15 19:44 Xiang Mei
  2026-03-15 19:49 ` Xiang Mei
  2026-03-17  0:08 ` Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Xiang Mei @ 2026-03-15 19:44 UTC (permalink / raw)
  To: netdev
  Cc: jv, andrew+netdev, davem, edumazet, kuba, pabeni, bestswngs,
	Xiang Mei

rlb_clear_slave intentionally keeps RLB hash-table entries on
the rx_hashtbl_used_head list with slave set to NULL when no
replacement slave is available. However, bond_debug_rlb_hash_show
visites client_info->slave without checking if it's NULL.

Other used-list iterators in bond_alb.c already handle this NULL-slave
state safely:

- rlb_update_client returns early on !client_info->slave
- rlb_req_update_slave_clients, rlb_clear_slave, and rlb_rebalance
compare slave values before visiting
- lb_req_update_subnet_clients continues if slave is NULL

The following NULL deref crash can be trigger in
bond_debug_rlb_hash_show:

[    1.289791] BUG: kernel NULL pointer dereference, address: 0000000000000000
[    1.290262] #PF: supervisor read access in kernel mode
[    1.290494] #PF: error_code(0x0000) - not-present page
[    1.290724] PGD 102a98067 P4D 102a98067 PUD 102831067 PMD 0
[    1.291013] Oops: Oops: 0000 [#1] SMP NOPTI
[    1.291202] CPU: 1 UID: 0 PID: 145 Comm: exploit Not tainted 7.0.0-rc3-virtme #1 PREEMPTLAZY
[    1.291555] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.17.0-0-gb52ca86e094d-prebuilt.qemu.or4
[    1.292058] RIP: 0010:bond_debug_rlb_hash_show (drivers/net/bonding/bond_debugfs.c:41)
[    1.292286] Code: 83 fb ff 74 3c 48 c1 e3 06 49 03 9c 24 f0 00 00 00 48 c7 c6 d5 aa 9d 83 48 89 ef 48 8b 43 30 48 85

Code starting with the faulting instruction
===========================================
   0:	83 fb ff             	cmp    $0xffffffff,%ebx
   3:	74 3c                	je     0x41
   5:	48 c1 e3 06          	shl    $0x6,%rbx
   9:	49 03 9c 24 f0 00 00 	add    0xf0(%r12),%rbx
  10:	00
  11:	48 c7 c6 d5 aa 9d 83 	mov    $0xffffffff839daad5,%rsi
  18:	48 89 ef             	mov    %rbp,%rdi
  1b:	48 8b 43 30          	mov    0x30(%rbx),%rax
  1f:	48                   	rex.W
  20:	85                   	.byte 0x85
[    1.293101] RSP: 0018:ffffc900004a7d00 EFLAGS: 00010286
[    1.293333] RAX: 0000000000000000 RBX: ffff888102b48200 RCX: ffff888102b48204
[    1.293631] RDX: ffff888102b48200 RSI: ffffffff839daad5 RDI: ffff888102815078
[    1.293924] RBP: ffff888102815078 R08: ffff888102b4820e R09: 0000000000000000
[    1.294267] R10: 0000000000000000 R11: 0000000000000000 R12: ffff888100f929c0
[    1.294564] R13: ffff888100f92a00 R14: 0000000000000001 R15: ffffc900004a7ed8
[    1.294864] FS:  0000000001395380(0000) GS:ffff888196e75000(0000) knlGS:0000000000000000
[    1.295239] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[    1.295480] CR2: 0000000000000000 CR3: 0000000102adc004 CR4: 0000000000772ef0
[    1.295775] PKRU: 55555554
[    1.295897] Call Trace:
[    1.296031]  <TASK>
[    1.296134]  seq_read_iter (fs/seq_file.c:231)
[    1.296341]  seq_read (fs/seq_file.c:164)
[    1.296493]  full_proxy_read (fs/debugfs/file.c:378 (discriminator 1))
[    1.296658]  vfs_read (fs/read_write.c:572)
[    1.296804]  ? _raw_spin_unlock (./arch/x86/include/asm/paravirt-spinlock.h:40 ./arch/x86/include/asm/paravirt-spinlock.h:72 ./include/linux/spinlock.h:204 ./include/linux/spinlock_api_smp.h:168 kernel/locking/spinlock.c:186)
[    1.296981]  ksys_read (fs/read_write.c:717)
[    1.297132]  do_syscall_64 (arch/x86/entry/syscall_64.c:63 (discriminator 1) arch/x86/entry/syscall_64.c:94 (discriminator 1))
[    1.297325]  entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130)
[    1.297553] RIP: 0033:0x41c9d1
[    1.297693] Code: f7 d8 64 89 02 b8 ff ff ff ff eb ba e8 f8 14 00 00 0f 1f 84 00 00 00 00 00 f3 0f 1e fa 80 3d 8d 9c

Code starting with the faulting instruction
===========================================
   0:	f7 d8                	neg    %eax
   2:	64 89 02             	mov    %eax,%fs:(%rdx)
   5:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
   a:	eb ba                	jmp    0xffffffffffffffc6
   c:	e8 f8 14 00 00       	call   0x1509
  11:	0f 1f 84 00 00 00 00 	nopl   0x0(%rax,%rax,1)
  18:	00
  19:	f3 0f 1e fa          	endbr64
  1d:	80                   	.byte 0x80
  1e:	3d                   	.byte 0x3d
  1f:	8d                   	.byte 0x8d
  20:	9c                   	pushf
[    1.298516] RSP: 002b:00007ffdd99e07d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
[    1.298834] RAX: ffffffffffffffda RBX: 0000000000000001 RCX: 000000000041c9d1
[    1.299163] RDX: 0000000000001000 RSI: 00007ffdd99e07f0 RDI: 0000000000000003
[    1.299483] RBP: 00007ffdd99e1800 R08: 00007ffdd99e0740 R09: 0000000000000014
[    1.299786] R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffdd99e1918
[    1.300106] R13: 00007ffdd99e1928 R14: 00000000004b0868 R15: 0000000000000001
[    1.300419]  </TASK>
[    1.300523] Modules linked in:
[    1.300667] CR2: 0000000000000000
[    1.300820] ---[ end trace 0000000000000000 ]---

Add a NULL check and print "(none)" for entries with no assigned slave.

Fixes: caafa84251b88 ("bonding: add the debugfs interface to see RLB hash table")
Reported-by: Weiming Shi <bestswngs@gmail.com>
Signed-off-by: Xiang Mei <xmei5@asu.edu>
---
 drivers/net/bonding/bond_debugfs.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/net/bonding/bond_debugfs.c b/drivers/net/bonding/bond_debugfs.c
index 8adbec7c5084..8967b65f6d84 100644
--- a/drivers/net/bonding/bond_debugfs.c
+++ b/drivers/net/bonding/bond_debugfs.c
@@ -34,11 +34,17 @@ static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
 	for (; hash_index != RLB_NULL_INDEX;
 	     hash_index = client_info->used_next) {
 		client_info = &(bond_info->rx_hashtbl[hash_index]);
-		seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
-			&client_info->ip_src,
-			&client_info->ip_dst,
-			&client_info->mac_dst,
-			client_info->slave->dev->name);
+		if (client_info->slave)
+			seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
+				   &client_info->ip_src,
+				   &client_info->ip_dst,
+				   &client_info->mac_dst,
+				   client_info->slave->dev->name);
+		else
+			seq_printf(m, "%-15pI4 %-15pI4 %-17pM (none)\n",
+				   &client_info->ip_src,
+				   &client_info->ip_dst,
+				   &client_info->mac_dst);
 	}
 
 	spin_unlock_bh(&bond->mode_lock);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-17  0:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-15 19:44 [PATCH net] net: bonding: fix NULL deref in bond_debug_rlb_hash_show Xiang Mei
2026-03-15 19:49 ` Xiang Mei
2026-03-17  0:08 ` Jakub Kicinski
2026-03-17  0:54   ` Xiang Mei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox