lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQ+woLxmNNbU--YkVc8kqevBszNbNG3WoOwKQadWvBXF-g@mail.gmail.com>
Date: Thu, 29 Aug 2024 09:27:21 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Tze-nan Wu (吳澤南) <Tze-nan.Wu@...iatek.com>
Cc: "sdf@...ichev.me" <sdf@...ichev.me>, 
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>, "kuniyu@...zon.com" <kuniyu@...zon.com>, 
	"bpf@...r.kernel.org" <bpf@...r.kernel.org>, 
	"linux-mediatek@...ts.infradead.org" <linux-mediatek@...ts.infradead.org>, "ast@...nel.org" <ast@...nel.org>, 
	Cheng-Jui Wang (王正睿) <Cheng-Jui.Wang@...iatek.com>, 
	Chen-Yao Chang (張禎耀) <Chen-Yao.Chang@...iatek.com>, 
	wsd_upstream <wsd_upstream@...iatek.com>, "andrii@...nel.org" <andrii@...nel.org>, 
	Bobule Chang (張弘義) <bobule.chang@...iatek.com>, 
	"jolsa@...nel.org" <jolsa@...nel.org>, "daniel@...earbox.net" <daniel@...earbox.net>, 
	"john.fastabend@...il.com" <john.fastabend@...il.com>, "song@...nel.org" <song@...nel.org>, 
	"kuba@...nel.org" <kuba@...nel.org>, "pabeni@...hat.com" <pabeni@...hat.com>, 
	"edumazet@...gle.com" <edumazet@...gle.com>, Yanghui Li (李阳辉) <Yanghui.Li@...iatek.com>, 
	"martin.lau@...ux.dev" <martin.lau@...ux.dev>, 
	"linux-arm-kernel@...ts.infradead.org" <linux-arm-kernel@...ts.infradead.org>, 
	"netdev@...r.kernel.org" <netdev@...r.kernel.org>, "eddyz87@...il.com" <eddyz87@...il.com>, 
	"matthias.bgg@...il.com" <matthias.bgg@...il.com>, "davem@...emloft.net" <davem@...emloft.net>, 
	"kpsingh@...nel.org" <kpsingh@...nel.org>, 
	"angelogioacchino.delregno@...labora.com" <angelogioacchino.delregno@...labora.com>, 
	"yonghong.song@...ux.dev" <yonghong.song@...ux.dev>, "haoluo@...gle.com" <haoluo@...gle.com>
Subject: Re: [PATCH net v4] bpf, net: Check cgroup_bpf_enabled() only once in do_sock_getsockopt()

On Thu, Aug 29, 2024 at 5:45 AM Tze-nan Wu (吳澤南)
<Tze-nan.Wu@...iatek.com> wrote:
>
> On Fri, 2024-08-23 at 19:04 -0700, Stanislav Fomichev wrote:
> >
> > External email : Please do not click links or open attachments until
> > you have verified the sender or the content.
> >  On 08/22, Alexei Starovoitov wrote:
> > > On Thu, Aug 22, 2024 at 12:02 AM Tze-nan Wu (吳澤南)
> > > <Tze-nan.Wu@...iatek.com> wrote:
> > > >
> > > >
> > > > BTW, If this should be handled in kernel, modification shown
> > below
> > > > could fix the issue without breaking the "static_branch" usage in
> > both
> > > > macros:
> > > >
> > > >
> > > > +++ /include/linux/bpf-cgroup.h:
> > > >     -#define BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen)
> > > >     +#define BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen, compat)
> > > >      ({
> > > >             int __ret = 0;
> > > >             if (cgroup_bpf_enabled(CGROUP_GETSOCKOPT))
> > > >                 copy_from_sockptr(&__ret, optlen, sizeof(int));
> > > >      +      else
> > > >      +          *compat = true;
> > > >             __ret;
> > > >      })
> > > >
> > > >     #define BPF_CGROUP_RUN_PROG_GETSOCKOPT(sock, level, optname,
> > > > optval, optlen, max_optlen, retval)
> > > >      ({
> > > >          int __ret = retval;
> > > >     -    if (cgroup_bpf_enabled(CGROUP_GETSOCKOPT) &&
> > > >     -        cgroup_bpf_sock_enabled(sock, CGROUP_GETSOCKOPT))
> > > >     +    if (cgroup_bpf_sock_enabled(sock, CGROUP_GETSOCKOPT))
> > > >              if (!(sock)->sk_prot->bpf_bypass_getsockopt ||
> > > >                ...
> > > >
> > > >   +++ /net/socket.c:
> > > >     int do_sock_getsockopt(struct socket *sock, bool compat, int
> > level,
> > > >      {
> > > >         ...
> > > >         ...
> > > >     +     /* The meaning of `compat` variable could be changed
> > here
> > > >     +      * to indicate if cgroup_bpf_enabled(CGROUP_SOCK_OPS)
> > is
> > > > false.
> > > >     +      */
> > > >         if (!compat)
> > > >     -       max_optlen =
> > BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen);
> > > >     +       max_optlen = BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen,
> > > > &compat);
> > >
> > > This is better, but it's still quite a hack. Let's not override it.
> > > We can have another bool, but the question:
> > > do we really need BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN  ?
> > > copy_from_sockptr(&__ret, optlen, sizeof(int));
> > > should be fast enough to do it unconditionally.
> > > What are we saving here?
> > >
> > > Stan ?
> >
> > Agreed, most likely nobody would notice :-)
>
> Sorry for my late reply, just have the mailer fixed.
>
> If it is feasible to make the `copy_from_sockptr` unconditionally,
> should I submit a new patch that resolve the issue by removing
> `BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN`? Patch A shown as below.
>
>   +++ /net/socket.c:
>    int do_sock_getsockopt(...)
>    {
>   -     int max_optlen __maybe_unused;
>   +     int max_optlen __maybe_unused = 0;
>         const struct proto_ops *ops;
>         int err;
>   ...
>   ...
>         if (!compat) <== wonder if we should keep the condition here?
>   -         max_optlen = BPF_CGROUP_GETSOCKOPT_MAX_OPTLEN(optlen);
>   +         copy_from_sockptr(&max_optlen, optlen, sizeof(int));

This one.
And delete the macro from bpf-cgroup.h

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ