From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Abhishek Chauhan <quic_abchauha@quicinc.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Andrew Halaney <ahalaney@redhat.com>,
Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
Martin KaFai Lau <martin.lau@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Daniel Borkmann <daniel@iogearbox.net>,
bpf <bpf@vger.kernel.org>
Cc: kernel@quicinc.com,
syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com,
syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
Subject: Re: [PATCH net-next v2] net: validate SO_TXTIME clockid coming from userspace
Date: Wed, 29 May 2024 20:24:27 -0400 [thread overview]
Message-ID: <6657c73bb72fa_37107c2948c@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20240529183130.1717083-1-quic_abchauha@quicinc.com>
Abhishek Chauhan wrote:
> Currently there are no strict checks while setting SO_TXTIME
> from userspace. With the recent development in skb->tstamp_type
> clockid with unsupported clocks results in warn_on_once, which causes
> unnecessary aborts in some systems which enables panic on warns.
>
> Add validation in setsockopt to support only CLOCK_REALTIME,
> CLOCK_MONOTONIC and CLOCK_TAI to be set from userspace.
>
> Link: https://lore.kernel.org/netdev/bc037db4-58bb-4861-ac31-a361a93841d3@linux.dev/
> Link: https://lore.kernel.org/lkml/6bdba7b6-fd22-4ea5-a356-12268674def1@quicinc.com/
> Fixes: 1693c5db6ab8 ("net: Add additional bit to support clockid_t timestamp type")
> Reported-by: syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=d7b227731ec589e7f4f0
> Reported-by: syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=30a35a2e9c5067cc43fa
> Signed-off-by: Abhishek Chauhan <quic_abchauha@quicinc.com>
> Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Willem de Bruijn <willemb@google.com>
> ---
> Changes since v1
> - Moved from net to net-next since
> Fixes tag is available only on net-next
> as mentioned by Martin
> - Added direct link to design discussion as
> mentioned by Willem.
> - Parameter in the sockopt_validate_clockid
> is of type __kernel_clockid_t so changed it from
> int to __kernel_clockid_t as mentioned by
> Willem.
> - Added Acked-by tag.
>
> net/core/sock.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 8629f9aecf91..d497285f283a 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1083,6 +1083,17 @@ bool sockopt_capable(int cap)
> }
> EXPORT_SYMBOL(sockopt_capable);
>
> +static int sockopt_validate_clockid(__kernel_clockid_t value)
The __kernel variants are UAPI. It looks odd to use this in kernel
internal code, and I don't see many examples immediately.
But I believe it is correct, as we're passing a sock_txtime.clockid
field, which has this (UAPI) type.
> +{
> + switch (value) {
> + case CLOCK_REALTIME:
> + case CLOCK_MONOTONIC:
> + case CLOCK_TAI:
> + return 0;
> + }
> + return -EINVAL;
> +}
> +
> /*
> * This is meant for all protocols to use and covers goings on
> * at the socket level. Everything here is generic.
> @@ -1497,6 +1508,11 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
> ret = -EPERM;
> break;
> }
> +
> + ret = sockopt_validate_clockid(sk_txtime.clockid);
> + if (ret)
> + break;
> +
> sock_valbool_flag(sk, SOCK_TXTIME, true);
> sk->sk_clockid = sk_txtime.clockid;
> sk->sk_txtime_deadline_mode =
> --
> 2.25.1
>
next prev parent reply other threads:[~2024-05-30 0:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 18:31 Abhishek Chauhan
2024-05-30 0:24 ` Willem de Bruijn [this message]
2024-06-01 22:50 ` patchwork-bot+netdevbpf
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=6657c73bb72fa_37107c2948c@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=ahalaney@redhat.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kernel@quicinc.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_abchauha@quicinc.com \
--cc=syzbot+30a35a2e9c5067cc43fa@syzkaller.appspotmail.com \
--cc=syzbot+d7b227731ec589e7f4f0@syzkaller.appspotmail.com \
/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
all inboxes | Powered by JetHome®