Skip to content

net/smc: fix clcsock lifetime vs asynchronous paths

Mahanta Jambigi linux-rdma linux-s390 netdev 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest3 patches 0 repliesNew
  2. v13 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Rebased onto net-next (eb6d6c80d354) instead of the torvalds tree (7e1392a42ea2). The patch content is unchanged; the only differences are unrelated net-next context: patch 2 now shows the READ_ONCE() around limit_smc_hs, and hunk labels were re-derived.
- Patch 1: clarify the commit message to say the issue was found by code inspection rather than from a reported regression, and to describe the conn->freed rationale more precisely.
- No functional change to the series.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3net/smc: keep clcsock until socket releasenet/smc/af_smc.c net/smc/smc_close.c+15 -50 replies
2/3net/smc: remove the clcsock release locknet/smc/af_smc.c net/smc/smc.h net/smc/smc_close.c +1 more+42 -890 replies
3/3net/smc: document the clcsock lifetimenet/smc/af_smc.c net/smc/smc.h net/smc/smc_close.c +1 more+25 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH net-next v2 0/3] net/smc: fix clcsock lifetime vs asynchronous paths

The internal TCP socket (clcsock) of an SMC socket is freed by asynchronous paths: link group termination reaches smc_close_active_abort() and peer close reaches smc_close_passive_work(), and both can run while the SMC socket is still referenced by an open file descriptor. A task that uses the fd at that moment, for example getsockopt() or a socket diag dump, then operates on a released socket.

Free the clcsock only when no socket file can reference it: from the socket release paths, after the socket has been unhashed, and from the abnormal close paths once the socket has no file left. The decision is made under the socket lock, and the accept path holds the same lock across the accept-queue state check and sock_graft(), so a connection that is being accepted cannot lose its clcsock to an asynchronous close. The clcsock_release_lock is no longer needed: a socket operation on a file is serialized with smc_release() by the file reference, and the listen work is covered by flush_work() and cancel_work_sync() in smc_clcsock_release().

Trade-off: with an open file, a clcsock now stays allocated after an abnormal close until the application closes the SMC fd. The SMC connection is already torn down and its TCP connection has been reset or shut down; only the local TCP socket remains allocated until then.

Patch 1 makes the lifetime change and is self-contained. Patch 2 removes the lock and the checks it made necessary, and serializes the accept path with the asynchronous close. Patch 3 documents the invariant and adds a destructor warning for it. The diag dump keeps its NULL check: a socket is hashed in smc_sk_init(), before its clcsock is created.

This is hardening found by code walk, not a fix for a reported regression, so the series targets net-next and carries no Fixes: tag.

---
Changes in v2:
- Rebased onto net-next (eb6d6c80d354) instead of the torvalds tree (7e1392a42ea2). The patch content is unchanged; the only differences are unrelated net-next context: patch 2 now shows the READ_ONCE() around limit_smc_hs, and hunk labels were re-derived.
- Patch 1: clarify the commit message to say the issue was found by code inspection rather than from a reported regression, and to describe the conn->freed rationale more precisely.
- No functional change to the series.

Mahanta Jambigi (3):
net/smc: keep clcsock until socket release
net/smc: remove the clcsock release lock
net/smc: document the clcsock lifetime

 net/smc/af_smc.c    | 123 +++++++++++++++++---------------------------
 net/smc/smc.h       |   8 ++-
 net/smc/smc_close.c |  35 +++++++++----
 net/smc/smc_diag.c  |   3 ++
 net/smc/smc_inet.c  |   9 ++--
 5 files changed, 82 insertions(+), 96 deletions(-)

base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d

Signature · 1 line
2.50.1 (Apple Git-155)