Skip to content

mptcp token hash ordering and token 0 lookups

Hang Nan lkml mptcp netdev stable 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest0 of 3 patches 1 replyIn review
  2. v40 of 3 patches 0 repliesSuperseded

Changes in v5 from the cover letter

- Add a KUnit case for the token 0 guard, as asked by netdev-bot+sinfo.

Patches in v5 No applies recorded yet

None of the 3 patches the cover letter announces are in this archive.

Reviews trailers per patch

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

Read the v5 thread

Cover letter [PATCH net v5 0/3] mptcp token hash ordering and token 0 lookups

From: NanHang <[email protected]>

This series restores acquire ordering for the mptcp token lookup and fixes two pre-existing defects in that hash table which ordering alone cannot cover.

Patch 1 converts mptcp_token_get_sock() and mptcp_token_iter_next() to refcount_inc_not_zero_acquire(). These sockets live in a SLAB_TYPESAFE_BY_RCU slab, so the re-check of msk->token and sock_net() after the increment only rejects a recycled socket if those loads are ordered after the increment; without the acquire they can be satisfied before it, against the previous owner's contents.

Patch 2 rejects token 0 in mptcp_token_get_sock(). Token 0 is never assigned, but it is what mptcp_token_destroy() stores into a socket being torn down, and what a freshly allocated msk holds until it is hashed. For a lookup for token 0 both validations compare 0 with 0 and accept such a socket; the token is copied from the wire by mptcp_parse_option(), so a peer can ask for it. The join path then uses the result, including msk->pm.anno_list, which is initialised only later.

Patch 3 makes mptcp_token_iter_next() re-read the token after the increment and drop the socket unless it is non-zero and still hashes to the slot being walked, so a socket recycled in the same network namespace is not handed to mptcp_diag or the userspace path manager before it is initialised.

None of the three has a runtime trigger. Patch 1 is argued at the instruction level (on arm64 the CAS becomes CASA; on x86-64 both variants compile to the same lock cmpxchg) and KCSAN cannot observe it, since it does not model reordering of marked accesses. Patches 2 and 3 are static arguments; patch 2 now carries a KUnit case that fails without the guard, which is as far as the state can be constructed without the race.

v1 -> v2:
- Point the Fixes: tags at the commits that introduced each lockless lookup instead of at the refcount consolidation (sashiko review).

v2 -> v3:
- Rewrite the rationale of the ordering patch: the acquire pairs with the SLAB_TYPESAFE_BY_RCU reuse window published by sock_init_data_uid(), not with mptcp_token_destroy() (sashiko review).
- Add the token 0 and iterator patches, reported by the same review.

v3 -> v4:
- Drop "net: core: take the reuseport migration reference with acquire ordering". reuseport_migrate_sock() does not validate anything after the increment, and the listener state that could be raced is re-checked under queue->rskq_lock in inet_csk_reqsk_queue_add(), so the acquire orders nothing there (sashiko review).

v4 -> v5:
- Add a KUnit case for the token 0 guard, as asked by netdev-bot+sinfo.

Hang Nan (3):
net: mptcp: take token lookup references with acquire ordering
net: mptcp: reject token 0 in mptcp_token_get_sock()
net: mptcp: verify the token slot in mptcp_token_iter_next()

 net/mptcp/token.c      | 13 ++++++++---
 net/mptcp/token_test.c | 51 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3