Skip to content

net/smc: fix use-after-free in smc_rx_pipe_buf_release()

Hidayath Khan linux-rdma linux-s390 netdev 2 versions – Applied

Status from this message: This series was applied to netdev/net.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyApplied 2/2
  2. v11 patch 2 repliesSuperseded

Changes in v2 from the cover letter

- Patch 1/2 is new. It is a prerequisite for 2/2.
- Patch 2/2 replaces the conn->rmb_desc = NULL approach from v1 with a conn->freed check. The NULL store exposed smc_cdc_msg_recv_action() and the sock_diag dump to NULL dereferences on paths that do not take the socket lock.

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2net/smc: stop killed, freed and out_of_sync sharing a bytenet/smc/smc.h+3 -30 repliesApplied
2/2net/smc: fix use-after-free in smc_rx_pipe_buf_release()net/smc/smc_rx.c+5 -60 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMahanta JambigiSimon Horman
SeriesR-b
1/2R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH net v2 0/2] net/smc: fix use-after-free in smc_rx_pipe_buf_release()

smc_rx_pipe_buf_release() tests sk_state before taking the socket lock and then dereferences conn->rmb_desc and conn->lgr. A concurrent close runs smc_conn_free() in between, which releases those structures. On the is_reg_err path smcr_buf_unuse() frees the descriptor outright, so this is a use-after-free.

Patch 2/2 fixes this by taking the socket lock first and testing conn->freed instead. smc_conn_free() sets that flag before releasing anything, under the same lock, so the two paths exclude each other.

Patch 1/2 is a prerequisite. conn->freed shares a byte with killed and out_of_sync as single-bit bitfields. out_of_sync is written from the receive tasklet without the socket lock, so a concurrent store to freed from process context can be lost in the read-modify-write. Patch 1/2 gives each flag its own byte so stores do not interfere.

Hidayath Khan (2):
net/smc: stop killed, freed and out_of_sync sharing a byte net/smc: fix use-after-free in smc_rx_pipe_buf_release()

 net/smc/smc.h    |  6 +++---
 net/smc/smc_rx.c | 11 +++++------
 2 files changed, 8 insertions(+), 9 deletions(-)

---
v2:
- Patch 1/2 is new. It is a prerequisite for 2/2.
- Patch 2/2 replaces the conn->rmb_desc = NULL approach from v1 with a conn->freed check. The NULL store exposed smc_cdc_msg_recv_action() and the sock_diag dump to NULL dereferences on paths that do not take the socket lock.

Signature · 1 line
2.52.0