[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL+tcoA1omzkK=odvcjtt-LtstRB9Dx3MVLC+yezqOp+M1sqsA@mail.gmail.com>
Date: Fri, 13 Dec 2024 22:12:44 +0800
From: Jason Xing <kerneljasonxing@...il.com>
To: Martin KaFai Lau <martin.lau@...ux.dev>
Cc: davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, dsahern@...nel.org, willemdebruijn.kernel@...il.com,
willemb@...gle.com, ast@...nel.org, daniel@...earbox.net, andrii@...nel.org,
eddyz87@...il.com, song@...nel.org, yonghong.song@...ux.dev,
john.fastabend@...il.com, kpsingh@...nel.org, sdf@...ichev.me,
haoluo@...gle.com, jolsa@...nel.org, bpf@...r.kernel.org,
netdev@...r.kernel.org, Jason Xing <kernelxing@...cent.com>
Subject: Re: [PATCH net-next v4 01/11] net-timestamp: add support for bpf_setsockopt()
On Fri, Dec 13, 2024 at 3:35 AM Martin KaFai Lau <martin.lau@...ux.dev> wrote:
>
> On 12/7/24 9:37 AM, Jason Xing wrote:
> > diff --git a/net/core/filter.c b/net/core/filter.c
> > index 6625b3f563a4..f7e9f88e09b1 100644
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -5214,6 +5214,24 @@ static const struct bpf_func_proto bpf_get_socket_uid_proto = {
> > .arg1_type = ARG_PTR_TO_CTX,
> > };
> >
> > +static int sk_bpf_set_cb_flags(struct sock *sk, sockptr_t optval, bool getopt)
>
> It is confusing to take a sockptr_t argument. It is called by the kernel bpf
> prog only. It must be from the kernel memory. Directly pass the "int
> sk_bpf_cb_flags" as the argument.
Thanks. I will fix this.
>
> > +{
> > + int sk_bpf_cb_flags;
> > +
> > + if (getopt)
> > + return -EINVAL;
> > +
> > + if (copy_from_sockptr(&sk_bpf_cb_flags, optval, sizeof(sk_bpf_cb_flags)))
>
> It is an unnecessary copy. Directly use the "int sk_bpf_cb_flags" arg instead.
>
> > + return -EFAULT;
>
> This should never happen.
>
> > +
> > + if (sk_bpf_cb_flags & ~SK_BPF_CB_MASK)
> > + return -EINVAL;
> > +
> > + sk->sk_bpf_cb_flags = sk_bpf_cb_flags;
> > +
> > + return 0;
> > +}
> > +
> > static int sol_socket_sockopt(struct sock *sk, int optname,
> > char *optval, int *optlen,
> > bool getopt)
> > @@ -5230,6 +5248,7 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
> > case SO_MAX_PACING_RATE:
> > case SO_BINDTOIFINDEX:
> > case SO_TXREHASH:
> > + case SK_BPF_CB_FLAGS:
> > if (*optlen != sizeof(int))
> > return -EINVAL;
> > break;
> > @@ -5239,6 +5258,9 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
> > return -EINVAL;
> > }
> >
> > + if (optname == SK_BPF_CB_FLAGS)
> > + return sk_bpf_set_cb_flags(sk, KERNEL_SOCKPTR(optval), getopt);
> > +
> > if (getopt) {
> > if (optname == SO_BINDTODEVICE)
> > return -EINVAL;
Powered by blists - more mailing lists