Re: [PATCH net-next 5/7] phonet: pep: convert getsockopt to sockopt_t
From: Breno Leitao
Date: Fri Jul 17 2026 - 09:03:32 EST
On Fri, Jul 17, 2026 at 09:22:58AM +0100, David Laight wrote:
> > - len = min_t(unsigned int, sizeof(int), len);
> > - if (put_user(len, optlen))
> > + len = min_t(unsigned int, sizeof(int), opt->optlen);
>
> I'm pretty sure that can be min().
Right. opt->optlen is a plain int and sizeof(int) is a non-negative
constant, so min() takes it fine.
I'll switch it to min() in v2, thanks for the review.
> More generally I'm not at all sure about negative lengths.
> Historically the user type would have been 'int', but it got replaced
> by socklen_t which is probably unsigned.
> (IIRC one of the 64bit Unix had started using a 64bit type but I think
> it was sun objected to making that change so socklen_t was born.)
That's now handled one level up, in sockopt_init_user():
if (get_user(len, optlen))
return -EFAULT;
if (len < 0)
return -EINVAL;
> Also truncating below 4 bytes makes no sense here on BE systems.
Sure, but this is pre-existing, isn't it?
> Some code will try to write the significant bytes out, but that
> would be better done in the wrapper.
This is the transitional shim. The ->getsockopt prototype is shared by
every proto:
int (*getsockopt)(struct sock *sk, int level, int optname,
char __user *optval, int __user *optlen);
So it can't take a sockopt_t until every leaf is converted.
Each converted leaf keeps the __user signature, builds the sockopt_t
itself and calls a do_*_getsockopt(sk, optname, sockopt_t *) helper.
Once all the getsockopt leaves are done, sockopt_init_user() moves into
the common caller, the prototype flips to sockopt_t *, and these
per-leaf wrappers are deleted. The full plan is in the phase-1 cover
letter:
https://lore.kernel.org/all/20260401-getsockopt-v2-0-611df6771aff@xxxxxxxxxx/
Thanks for the review,
--breno