Skip to content

net: move .getsockopt away from __user buffers

Breno Leitao bpf io-uring lkml netdev 3 versions – Applied

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

Get series with b4
b4 am [email protected] change-id 20260130-getsockopt-9f36625eedcb

Versions newest first

  1. v3 Latest4 patches 12 repliesApplied 4/4
  2. v24 patches 5 repliesSuperseded
  3. v1 RFC3 patches 6 repliesSuperseded

Changes in v3 from the cover letter

- Create Two iov in sockopt_t instead of a single one (Stanislav Fomichev)
- Implement the sockptr_to_sockopt() helper (Stanislav Fomichev)
- Link to v2: https://patch.msgid.link/[email protected]

Patches in v3 All 4 applied

#Subject and filesSizeRepliesApplied
1/4net: add getsockopt_iter callback to proto_opsinclude/linux/net.h+23 -00 repliesApplied
2/4net: call getsockopt_iter if availablenet/socket.c+51 -30 repliesApplied
3/4af_packet: convert to getsockopt_iternet/packet/af_packet.c+7 -80 repliesApplied
4/4can: raw: convert to getsockopt_iternet/can/raw.c+13 -150 repliesApplied

Reviews trailers per patch

None of the 4 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchStanislav Fomichev
SeriesA-b
1/4
2/4
3/4
4/4

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

Read the v3 thread

Cover letter [PATCH net-next v3 0/4] net: move .getsockopt away from __user buffers

Currently, the .getsockopt callback requires __user pointers:

int (*getsockopt)(struct socket *sock, int level,

                    int optname, char __user *optval, int __user *optlen);

This prevents kernel callers (io_uring, BPF) from using getsockopt on levels other than SOL_SOCKET, since they pass kernel pointers.

Following Linus' suggestion [0], this series introduces sockopt_t, a type-safe wrapper around iov_iter, and a getsockopt_iter callback that works with both user and kernel buffers. AF_PACKET and CAN raw are converted as initial users, with selftests covering the trickiest conversion patterns.

[0] https://lore.kernel.org/all/CAHk-=whmzrO-BMU=uSVXbuoLi-3tJsO=0kHj1BCPBE3F2kVhTA@mail.gmail.com/

Updates from v2 to v3:

* Use two iov in sockopt_t instead of a single one:
a) .iter_in that is populated by the caller and will be read-only in the protocols callback.

b) .iter_out will be populated by the protocol and it will be sent back to the caller.

- This will avoid changing the protocol reset and changing the data source at the callback, making the driver callback implementation and converstion saner.

* created sockptr_to_sockopt() to convert sockptr to sockopt, making the call to getsockopt_iter straight-forward

---
Changes in v3:
- Create Two iov in sockopt_t instead of a single one (Stanislav Fomichev)
- Implement the sockptr_to_sockopt() helper (Stanislav Fomichev)
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Restore optlen even on error path (getsockopt_iter fails)
- Move af_packet.c and can instead of netlink (given these are the most complicate ones).
- Link to v1: https://patch.msgid.link/[email protected]

---
Breno Leitao (4):
net: add getsockopt_iter callback to proto_ops
net: call getsockopt_iter if available
af_packet: convert to getsockopt_iter
can: raw: convert to getsockopt_iter

 include/linux/net.h    | 23 +++++++++++++++++++++
 net/can/raw.c          | 28 ++++++++++++--------------
 net/packet/af_packet.c | 15 +++++++-------
 net/socket.c           | 54 +++++++++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 94 insertions(+), 26 deletions(-)

---
base-commit: 9c14d60a50c4b726a3613a02e8b74778e9964891
change-id: 20260130-getsockopt-9f36625eedcb

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>