Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 0/7] net/handshake: anchor request lifetime to a pinned file reference
@ 2026-05-21 14:47 Chuck Lever
  2026-05-21 14:47 ` [PATCH net v2 1/7] net/handshake: Drain pending requests at net namespace exit Chuck Lever
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Chuck Lever @ 2026-05-21 14:47 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman
  Cc: Chris Mason, Christian Brauner, kernel-tls-handshake, linux-nvme,
	netdev, Chuck Lever, Hannes Reinecke, Alistair Francis

handshake_nl_accept_doit() has accumulated four follow-on fixes
since 3b3009ea8abb ("net/handshake: Create a NETLINK service for
handling handshake requests"): 7ea9c1ec66bc, 7798b59409c3,
fe67b063f687, and dabac51b8102.  Each was a local refcount or
NULL-check correction; none moved where the file reference is
owned, and the same code keeps producing the same class of bug.
Reworking the ownership is what breaks the pattern.

For the duration of a request, sock->file has no single owner.
Submit publishes the request without taking a file reference;
accept_doit acquires one inside the handler, after the request
has already left the pending list.  The consumer can drop its
own reference at any time, including the moment between
handshake_req_next() popping the request and accept_doit
reaching get_file().  The submit-side sock_hold() pins only
struct sock; struct socket and sock->file remain under the
consumer's control via the file descriptor.

This series places the file reference under unambiguous
ownership.  handshake_req_submit() pins it on the request and
completion or cancel drops it (patches 4-5); the submit-side
sock_hold() then becomes redundant, and dropping it also closes
a publish-before-pin race the late sock_hold itself opened
(patch 6).  The handshake_complete() API and its consumers move
to a uniform negative-errno sign convention (patch 3), with the
matching sign correction in nvme-tcp (patch 2).  An unrelated
netns-exit leak gets its own fix (patch 1), and new KUnit
file-count assertions verify the refcount contract (patch 7).

Three things in this restructuring want a careful look.  In
handshake_complete(), the fput() of the request's file
reference has to come after hp_done() -- fput() can transitively
run handshake_sk_destruct() and free the request, so the patch
stashes hr_file in a local first.  handshake_sk_destruct()
itself is kept on purpose: it owns rhashtable removal and
kfree, and remains the backstop if a consumer path bypasses
handshake_complete() entirely.  Third, handshake_req_next() now
returns its request with an extra get_file() held under
hn_lock; accept_doit must consume that reference (FD_PREPARE on
success, explicit fput on the fdf.err path), and any future
caller has to honor the same contract.

---
Changes in v2:
- Patch 3: move HANDSHAKE_A_DONE_STATUS upper bound into netlink policy (Jakub)
- Link to v1: https://patch.msgid.link/20260518-handshake-file-pin-v1-0-4bbcb7e62fda@oracle.com

---
Chuck Lever (7):
      net/handshake: Drain pending requests at net namespace exit
      nvme-tcp: store negative errno in queue->tls_err
      net/handshake: Pass negative errno through handshake_complete()
      net/handshake: Take a long-lived file reference at submit
      net/handshake: hand off the pinned file reference to accept_doit
      net/handshake: Close the submit-side sock_hold race
      net/handshake: Verify file-reference balance in submit paths

 Documentation/netlink/specs/handshake.yaml |  8 +++++
 drivers/nvme/host/tcp.c                    |  2 +-
 net/handshake/genl.c                       |  3 +-
 net/handshake/genl.h                       |  1 +
 net/handshake/handshake-test.c             | 38 ++++++++++++++++++++++-
 net/handshake/handshake.h                  |  6 ++--
 net/handshake/netlink.c                    | 19 +++---------
 net/handshake/request.c                    | 50 ++++++++++++++++++++++++------
 net/handshake/tlshd.c                      |  4 +--
 9 files changed, 101 insertions(+), 30 deletions(-)
---
base-commit: 42734af6632ebebf90552f0e2dce4d8e72dbb9be
change-id: 20260516-handshake-file-pin-21390f5f3513

Best regards,
--  
Chuck Lever <chuck.lever@oracle.com>


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

end of thread, other threads:[~2026-05-26  1:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-21 14:47 [PATCH net v2 0/7] net/handshake: anchor request lifetime to a pinned file reference Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 1/7] net/handshake: Drain pending requests at net namespace exit Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 2/7] nvme-tcp: store negative errno in queue->tls_err Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 3/7] net/handshake: Pass negative errno through handshake_complete() Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 4/7] net/handshake: Take a long-lived file reference at submit Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 5/7] net/handshake: hand off the pinned file reference to accept_doit Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 6/7] net/handshake: Close the submit-side sock_hold race Chuck Lever
2026-05-21 14:47 ` [PATCH net v2 7/7] net/handshake: Verify file-reference balance in submit paths Chuck Lever
2026-05-25 18:35 ` [PATCH net v2 0/7] net/handshake: anchor request lifetime to a pinned file reference Jakub Kicinski
2026-05-26  1:55   ` Chuck Lever

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