From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Eduard Zingerman <eddyz87@gmail.com>, Hao Luo <haoluo@google.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Stanislav Fomichev <sdf@fomichev.me>,
Thomas Gleixner <tglx@linutronix.de>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v2 bpf-next 3/3] bpf: Implement bpf_check_basics_ok() as a macro.
Date: Tue, 2 Jul 2024 20:12:33 +0200 [thread overview]
Message-ID: <20240702181233.URQ43uFX@linutronix.de> (raw)
In-Reply-To: <ZoQqc_dNjxF1-AR-@krava>
On 2024-07-02 18:27:31 [+0200], Jiri Olsa wrote:
> On Tue, Jul 02, 2024 at 04:21:43PM +0200, Sebastian Andrzej Siewior wrote:
> > sparse complains about the argument type for filter that is passed to
> > bpf_check_basics_ok(). There are two users of the function where the
> > variable is with __user attribute one without. The pointer is only
> > checked against NULL so there is no access to the content and so no need
> > for any user-wrapper.
> >
> > Adding the __user to the declaration doesn't solve anything because
> > there is one kernel user so it will be wrong again.
> > Splitting the function in two seems an overkill because the function is
> > small and simple.
>
> could we just retype the __user argument? like
>
> bpf_check_basics_ok((const struct sock_filter *) fprog->filter, ...)
If we keep the function and add a cast here then cast the __user part
away and it would be wrong if we do something else with the pointer.
If it is understood that that will never happen…
> > --- a/net/core/filter.c
> > +++ b/net/core/filter.c
> > @@ -1035,16 +1035,20 @@ static bool chk_code_allowed(u16 code_to_probe)
…
> > + /* macro instead of a function to avoid woring about _filter which might be a
> > + * user or kernel pointer. It does not matter for the NULL check.
> > + */
> > +#define bpf_check_basics_ok(fprog_filter, fprog_flen) \
> > +({ \
> > + bool __ret = true; \
> > + u16 __flen = fprog_flen; \
>
> why not use fprog_flen directly? I'm not sure I get the changelog
> explanation
This was to avoid expanding `fprog_flen' twice. But looking at the
actual output, the code generation seems to be unaffected.
> thanks,
> jirka
Sebastian
next prev parent reply other threads:[~2024-07-02 19:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 14:21 [PATCH v2 bpf-next 0/3] bpf: sparse cleanup Sebastian Andrzej Siewior
2024-07-02 14:21 ` [PATCH v2 bpf-next 1/3] bpf: Add casts to keep sparse quiet Sebastian Andrzej Siewior
2024-07-03 21:39 ` Alexei Starovoitov
2024-07-04 8:00 ` Sebastian Andrzej Siewior
2024-07-07 0:42 ` Alexei Starovoitov
2024-07-02 14:21 ` [PATCH v2 bpf-next 2/3] bpf: Move a few bpf_func_proto declarations Sebastian Andrzej Siewior
2024-07-02 22:30 ` Andrii Nakryiko
2024-07-02 14:21 ` [PATCH v2 bpf-next 3/3] bpf: Implement bpf_check_basics_ok() as a macro Sebastian Andrzej Siewior
2024-07-02 16:27 ` Jiri Olsa
2024-07-02 18:12 ` Sebastian Andrzej Siewior [this message]
2024-07-02 22:26 ` Andrii Nakryiko
2024-07-03 12:39 ` Sebastian Andrzej Siewior
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=20240702181233.URQ43uFX@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=olsajiri@gmail.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=tglx@linutronix.de \
--cc=yonghong.song@linux.dev \
/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