[PATCH net-next v2 0/7] net: convert rawv6, ieee802154, phonet and tls getsockopt to sockopt_t

Breno Leitao posted 7 patches 4 days, 9 hours ago
net/ieee802154/socket.c                       |  38 ++-
net/ipv6/raw.c                                |  27 +-
net/phonet/pep.c                              |  36 ++-
net/tls/tls_main.c                            |  80 +++--
tools/testing/selftests/net/getsockopt_iter.c | 424 ++++++++++++++++++++++++++
5 files changed, 533 insertions(+), 72 deletions(-)
[PATCH net-next v2 0/7] net: convert rawv6, ieee802154, phonet and tls getsockopt to sockopt_t
Posted by Breno Leitao 4 days, 9 hours ago
Now that sockopt_init_user() was already merged, builds a user-backed
sockopt_t from the __user pair. A getsockopt leaf can then take
a sockopt_t behind a thin __user wrapper: the wrapper builds it, calls
the leaf, and writes the length back to optlen. The leaf copies with
copy_to_iter() instead of copy_to_user().

Convert four more leaves the way udp and raw already were: ipv6 raw
(do_rawv6_getsockopt), ieee802154 dgram, phonet pep, and tls
(do_tls_getsockopt and its per-option helpers). 

Converting phonet surfaced a pre-existing bug: pep_getsockopt() clamps the
length it reports but writes a full int with put_user(), overrunning an
optval buffer shorter than sizeof(int). It is fixed in its own patch, with
a Fixes: tag, before the phonet conversion, so it can be backported alone.

The last patch adds getsockopt_iter selftest fixtures for rawv6,
ieee802154, phonet and tls, checking the returned length and errno across
exact, oversized and short buffers, an unknown optname and a bad level.

For full motivation about these changes, please check the initial thread
at link
https://lore.kernel.org/all/20260401-getsockopt-v2-0-611df6771aff@debian.org/#t

Signed-off-by: Breno Leitao <leitao@debian.org>
---
Changes in v2:
- Replace min_t() by umin() (David)
- Link to v1: https://patch.msgid.link/20260716-getsockopt_phase4-v1-0-4f45cb12dce7@debian.org

---
Breno Leitao (7):
      ipv6: raw: drop unused level argument from do_rawv6_getsockopt
      ipv6: raw: convert do_rawv6_getsockopt to sockopt_t
      ieee802154: convert dgram getsockopt to sockopt_t
      phonet: pep: do not write beyond optlen in getsockopt
      phonet: pep: convert getsockopt to sockopt_t
      tls: convert getsockopt to sockopt_t
      selftests: net: getsockopt_iter: cover rawv6, ieee802154, phonet and tls

 net/ieee802154/socket.c                       |  38 ++-
 net/ipv6/raw.c                                |  27 +-
 net/phonet/pep.c                              |  36 ++-
 net/tls/tls_main.c                            |  80 +++--
 tools/testing/selftests/net/getsockopt_iter.c | 424 ++++++++++++++++++++++++++
 5 files changed, 533 insertions(+), 72 deletions(-)
---
base-commit: f6f3b36c15ed44de1fbb44e645e4fae8c4a4453e
change-id: 20260715-getsockopt_phase4-180209cfc60a

Best regards,
--  
Breno Leitao <leitao@debian.org>
Re: [PATCH net-next v2 0/7] net: convert rawv6, ieee802154, phonet and tls getsockopt to sockopt_t
Posted by Joe Damato 2 days, 11 hours ago
On Mon, Jul 20, 2026 at 09:17:41AM -0700, Breno Leitao wrote:
> Now that sockopt_init_user() was already merged, builds a user-backed
> sockopt_t from the __user pair. A getsockopt leaf can then take
> a sockopt_t behind a thin __user wrapper: the wrapper builds it, calls
> the leaf, and writes the length back to optlen. The leaf copies with
> copy_to_iter() instead of copy_to_user().
> 
> Convert four more leaves the way udp and raw already were: ipv6 raw
> (do_rawv6_getsockopt), ieee802154 dgram, phonet pep, and tls
> (do_tls_getsockopt and its per-option helpers). 
> 
> Converting phonet surfaced a pre-existing bug: pep_getsockopt() clamps the
> length it reports but writes a full int with put_user(), overrunning an
> optval buffer shorter than sizeof(int). It is fixed in its own patch, with
> a Fixes: tag, before the phonet conversion, so it can be backported alone.
> 
> The last patch adds getsockopt_iter selftest fixtures for rawv6,
> ieee802154, phonet and tls, checking the returned length and errno across
> exact, oversized and short buffers, an unknown optname and a bad level.
> 
> For full motivation about these changes, please check the initial thread
> at link
> https://lore.kernel.org/all/20260401-getsockopt-v2-0-611df6771aff@debian.org/#t
> 
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> Changes in v2:
> - Replace min_t() by umin() (David)
> - Link to v1: https://patch.msgid.link/20260716-getsockopt_phase4-v1-0-4f45cb12dce7@debian.org

Other than the nit I mentioned about min vs min_t on the one patch, it looks
good overall to me, so for the series:

Reviewed-by: Joe Damato <joe@dama.to>
Re: [PATCH net-next v2 0/7] net: convert rawv6, ieee802154, phonet and tls getsockopt to sockopt_t
Posted by Breno Leitao 1 day, 11 hours ago
On Wed, Jul 22, 2026 at 06:42:41AM -0700, Joe Damato wrote:
> On Mon, Jul 20, 2026 at 09:17:41AM -0700, Breno Leitao wrote:
> > Now that sockopt_init_user() was already merged, builds a user-backed
> > sockopt_t from the __user pair. A getsockopt leaf can then take
> > a sockopt_t behind a thin __user wrapper: the wrapper builds it, calls
> > the leaf, and writes the length back to optlen. The leaf copies with
> > copy_to_iter() instead of copy_to_user().
> > 
> > Convert four more leaves the way udp and raw already were: ipv6 raw
> > (do_rawv6_getsockopt), ieee802154 dgram, phonet pep, and tls
> > (do_tls_getsockopt and its per-option helpers). 
> > 
> > Converting phonet surfaced a pre-existing bug: pep_getsockopt() clamps the
> > length it reports but writes a full int with put_user(), overrunning an
> > optval buffer shorter than sizeof(int). It is fixed in its own patch, with
> > a Fixes: tag, before the phonet conversion, so it can be backported alone.
> > 
> > The last patch adds getsockopt_iter selftest fixtures for rawv6,
> > ieee802154, phonet and tls, checking the returned length and errno across
> > exact, oversized and short buffers, an unknown optname and a bad level.
> > 
> > For full motivation about these changes, please check the initial thread
> > at link
> > https://lore.kernel.org/all/20260401-getsockopt-v2-0-611df6771aff@debian.org/#t
> > 
> > Signed-off-by: Breno Leitao <leitao@debian.org>
> > ---
> > Changes in v2:
> > - Replace min_t() by umin() (David)
> > - Link to v1: https://patch.msgid.link/20260716-getsockopt_phase4-v1-0-4f45cb12dce7@debian.org
> 
> Other than the nit I mentioned about min vs min_t on the one patch, it looks
> good overall to me, so for the series:

Thanks for the review, In fact, I'm using umin() rather than plain min()
on purpose: opt->optlen is a signed int and sizeof(int) is size_t, so
min() trips the signedness check unless the compiler can prove optlen >=
0.

I don't think min() is correct here, it would be min_t() or umin(),
I would say.

--thanks
breno