From: David Laight <david.laight.linux@gmail.com>
To: Breno Leitao <leitao@debian.org>
Cc: sdf@fomichev.me, "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"Alexander Aring" <alex.aring@gmail.com>,
"Stefan Schmidt" <stefan@datenfreihafen.org>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Remi Denis-Courmont" <courmisch@gmail.com>,
"Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>,
"John Fastabend" <john.fastabend@gmail.com>,
"Sabrina Dubroca" <sd@queasysnail.net>,
"Shuah Khan" <shuah@kernel.org>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-wpan@vger.kernel.org, linux-kselftest@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH net-next 5/7] phonet: pep: convert getsockopt to sockopt_t
Date: Fri, 17 Jul 2026 09:22:58 +0100 [thread overview]
Message-ID: <20260717092258.776e63db@pumpkin> (raw)
In-Reply-To: <20260716-getsockopt_phase4-v1-5-4f45cb12dce7@debian.org>
On Thu, 16 Jul 2026 06:00:03 -0700
Breno Leitao <leitao@debian.org> wrote:
> Continue converting the proto-layer getsockopt callbacks to the
> sockopt_t interface, splitting pep_getsockopt() into a
> do_pep_getsockopt() helper that takes a sockopt_t.
>
> The thin pep_getsockopt() wrapper keeps its __user signature for now:
> it builds a user-backed sockopt_t with sockopt_init_user(), calls the
> helper, and writes the returned length back to optlen. The helper uses
> copy_to_iter() instead of copy_to_user(). No functional change.
>
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
> net/phonet/pep.c | 36 ++++++++++++++++++++++++++----------
> 1 file changed, 26 insertions(+), 10 deletions(-)
>
> diff --git a/net/phonet/pep.c b/net/phonet/pep.c
> index 60d1a5375725b..c7f4ce894af56 100644
> --- a/net/phonet/pep.c
> +++ b/net/phonet/pep.c
> @@ -1078,17 +1078,11 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
> return err;
> }
>
> -static int pep_getsockopt(struct sock *sk, int level, int optname,
> - char __user *optval, int __user *optlen)
> +static int do_pep_getsockopt(struct sock *sk, int optname, sockopt_t *opt)
> {
> struct pep_sock *pn = pep_sk(sk);
> int len, val;
>
> - if (level != SOL_PNPIPE)
> - return -ENOPROTOOPT;
> - if (get_user(len, optlen))
> - return -EFAULT;
> -
> switch (optname) {
> case PNPIPE_ENCAP:
> val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE;
> @@ -1112,11 +1106,33 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
> return -ENOPROTOOPT;
> }
>
> - 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().
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.)
Also truncating below 4 bytes makes no sense here on BE systems.
Some code will try to write the significant bytes out, but that
would be better done in the wrapper.
> + opt->optlen = len;
> + if (copy_to_iter(&val, len, &opt->iter_out) != len)
> return -EFAULT;
> - if (copy_to_user(optval, &val, len))
> + return 0;
> +}
> +
> +static int pep_getsockopt(struct sock *sk, int level, int optname,
> + char __user *optval, int __user *optlen)
> +{
> + sockopt_t opt;
> + int err;
> +
> + if (level != SOL_PNPIPE)
> + return -ENOPROTOOPT;
> +
> + err = sockopt_init_user(&opt, optval, optlen);
Have I not looked at these before?
Why is this here, not in the outer code?
David
> + if (err)
> + return err;
> +
> + err = do_pep_getsockopt(sk, optname, &opt);
> + if (err)
> + return err;
> +
> + if (put_user(opt.optlen, optlen))
> return -EFAULT;
> +
> return 0;
> }
>
>
next prev parent reply other threads:[~2026-07-17 8:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 12:59 [PATCH net-next 0/7] net: convert rawv6, ieee802154, phonet and tls getsockopt to sockopt_t Breno Leitao
2026-07-16 12:59 ` [PATCH net-next 1/7] ipv6: raw: drop unused level argument from do_rawv6_getsockopt Breno Leitao
2026-07-16 13:00 ` [PATCH net-next 2/7] ipv6: raw: convert do_rawv6_getsockopt to sockopt_t Breno Leitao
2026-07-16 13:00 ` [PATCH net-next 3/7] ieee802154: convert dgram getsockopt " Breno Leitao
2026-07-16 13:00 ` [PATCH net-next 4/7] phonet: pep: do not write beyond optlen in getsockopt Breno Leitao
2026-07-17 6:50 ` Rémi Denis-Courmont
2026-07-16 13:00 ` [PATCH net-next 5/7] phonet: pep: convert getsockopt to sockopt_t Breno Leitao
2026-07-17 6:52 ` Rémi Denis-Courmont
2026-07-17 8:22 ` David Laight [this message]
2026-07-16 13:00 ` [PATCH net-next 6/7] tls: " Breno Leitao
2026-07-16 13:00 ` [PATCH net-next 7/7] selftests: net: getsockopt_iter: cover rawv6, ieee802154, phonet and tls Breno Leitao
2026-07-17 6:53 ` Rémi Denis-Courmont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260717092258.776e63db@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=alex.aring@gmail.com \
--cc=courmisch@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=remi.denis-courmont@nokia.com \
--cc=sd@queasysnail.net \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=stefan@datenfreihafen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox