linux/net/smc
Wen Gu 27aea64838 net/smc: fix illegal rmb_desc access in SMC-D connection dump
[ Upstream commit dbc153fd3c ]

A crash was found when dumping SMC-D connections. It can be reproduced
by following steps:

- run nginx/wrk test:
  smc_run nginx
  smc_run wrk -t 16 -c 1000 -d <duration> -H 'Connection: Close' <URL>

- continuously dump SMC-D connections in parallel:
  watch -n 1 'smcss -D'

 BUG: kernel NULL pointer dereference, address: 0000000000000030
 CPU: 2 PID: 7204 Comm: smcss Kdump: loaded Tainted: G	E      6.7.0+ #55
 RIP: 0010:__smc_diag_dump.constprop.0+0x5e5/0x620 [smc_diag]
 Call Trace:
  <TASK>
  ? __die+0x24/0x70
  ? page_fault_oops+0x66/0x150
  ? exc_page_fault+0x69/0x140
  ? asm_exc_page_fault+0x26/0x30
  ? __smc_diag_dump.constprop.0+0x5e5/0x620 [smc_diag]
  ? __kmalloc_node_track_caller+0x35d/0x430
  ? __alloc_skb+0x77/0x170
  smc_diag_dump_proto+0xd0/0xf0 [smc_diag]
  smc_diag_dump+0x26/0x60 [smc_diag]
  netlink_dump+0x19f/0x320
  __netlink_dump_start+0x1dc/0x300
  smc_diag_handler_dump+0x6a/0x80 [smc_diag]
  ? __pfx_smc_diag_dump+0x10/0x10 [smc_diag]
  sock_diag_rcv_msg+0x121/0x140
  ? __pfx_sock_diag_rcv_msg+0x10/0x10
  netlink_rcv_skb+0x5a/0x110
  sock_diag_rcv+0x28/0x40
  netlink_unicast+0x22a/0x330
  netlink_sendmsg+0x1f8/0x420
  __sock_sendmsg+0xb0/0xc0
  ____sys_sendmsg+0x24e/0x300
  ? copy_msghdr_from_user+0x62/0x80
  ___sys_sendmsg+0x7c/0xd0
  ? __do_fault+0x34/0x160
  ? do_read_fault+0x5f/0x100
  ? do_fault+0xb0/0x110
  ? __handle_mm_fault+0x2b0/0x6c0
  __sys_sendmsg+0x4d/0x80
  do_syscall_64+0x69/0x180
  entry_SYSCALL_64_after_hwframe+0x6e/0x76

It is possible that the connection is in process of being established
when we dump it. Assumed that the connection has been registered in a
link group by smc_conn_create() but the rmb_desc has not yet been
initialized by smc_buf_create(), thus causing the illegal access to
conn->rmb_desc. So fix it by checking before dump.

Fixes: 4b1b7d3b30 ("net/smc: add SMC-D diag support")
Signed-off-by: Wen Gu <guwen@linux.alibaba.com>
Reviewed-by: Dust Li <dust.li@linux.alibaba.com>
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-02-23 08:12:41 +01:00
..
af_smc.c net/smc: fix dangling sock under state SMC_APPFINCLOSEWAIT 2023-11-20 10:29:21 +01:00
Kconfig
Makefile
smc_cdc.c net/smc: fix dangling sock under state SMC_APPFINCLOSEWAIT 2023-11-20 10:29:21 +01:00
smc_cdc.h net/smc: fix byte_order for rx_curs_confirmed 2019-12-05 09:21:09 +01:00
smc_clc.c net/smc: add missing error check in smc_clc_prfx_set() 2021-10-06 15:31:13 +02:00
smc_clc.h net/smc: provide fallback reason code 2018-07-25 22:25:53 -07:00
smc_close.c net/smc: fix dangling sock under state SMC_APPFINCLOSEWAIT 2023-11-20 10:29:21 +01:00
smc_close.h net/smc: wait for pending work before clcsock release_sock 2023-11-20 10:29:21 +01:00
smc_core.c net/smc: correct settings of RMB window update limit 2022-04-15 14:15:02 +02:00
smc_core.h net/smc: improve delete link processing 2018-07-25 22:25:53 -07:00
smc_diag.c net/smc: fix illegal rmb_desc access in SMC-D connection dump 2024-02-23 08:12:41 +01:00
smc_ib.c net/smc: cancel event worker during device removal 2020-03-18 07:14:25 +01:00
smc_ib.h net/smc: use correct vlan gid of RoCE device 2018-07-25 22:25:53 -07:00
smc_ism.c net/smc: send response to test link signal 2018-08-10 14:38:43 -07:00
smc_ism.h
smc_llc.c net/smc: improve delete link processing 2018-07-25 22:25:53 -07:00
smc_llc.h net/smc: improve delete link processing 2018-07-25 22:25:53 -07:00
smc_pnet.c smc: generic netlink family should be __ro_after_init 2018-09-20 07:49:55 -07:00
smc_pnet.h net/smc: use correct vlan gid of RoCE device 2018-07-25 22:25:53 -07:00
smc_rx.c net/smc: non blocking recvmsg() return -EAGAIN when no data and signal_pending 2022-05-18 09:42:48 +02:00
smc_rx.h
smc_tx.c net/smc: do not wait under send_lock 2019-12-17 20:35:33 +01:00
smc_tx.h net/smc: eliminate cursor read and write calls 2018-07-23 10:57:14 -07:00
smc_wr.c net/smc: use after free fix in smc_wr_tx_put_slot() 2019-12-13 08:51:34 +01:00
smc_wr.h net/smc: Simplify ib_post_(send|recv|srq_recv)() calls 2018-07-24 16:06:37 -06:00
smc.h net/smc: fix dangling sock under state SMC_APPFINCLOSEWAIT 2023-11-20 10:29:21 +01:00