[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220728163104.usdkmsxjyqwaitxu@kafai-mbp.dhcp.thefacebook.com>
Date: Thu, 28 Jul 2022 09:31:04 -0700
From: Martin KaFai Lau <kafai@...com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Stanislav Fomichev <sdf@...gle.com>, bpf@...r.kernel.org,
netdev@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
David Miller <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, kernel-team@...com,
Paolo Abeni <pabeni@...hat.com>
Subject: Re: [PATCH bpf-next 02/14] bpf: net: Avoid sock_setsockopt() taking
sk lock when called from bpf
On Wed, Jul 27, 2022 at 06:49:03PM -0700, Jakub Kicinski wrote:
> On Wed, 27 Jul 2022 17:45:46 -0700 Martin KaFai Lau wrote:
> > > bool setsockopt_capable(struct user_namespace *ns, int cap)
> > > {
> > > if (!in_task()) {
> > > /* Running in irq/softirq -> setsockopt invoked by bpf program.
> > > * [not sure, is it safe to assume no regular path leads
> > > to setsockopt from sirq?]
> > > */
> > > return true;
> > > }
> > >
> > > /* Running in process context, task has bpf_ctx set -> invoked
> > > by bpf program. */
> > > if (current->bpf_ctx != NULL)
> > > return true;
> > >
> > > return ns_capable(ns, cap);
> > > }
> > >
> > > And then do /ns_capable/setsockopt_capable/ in net/core/sock.c
> > >
> > > But that might be more fragile than passing the flag, idk.
> > I think it should work. From a quick look, all bpf_setsockopt usage has
> > bpf_ctx. The one from bpf_tcp_ca (struct_ops) and bpf_iter is trampoline
> > which also has bpf_ctx. Not sure about the future use cases.
> >
> > To be honest, I am not sure if I have missed cases and also have similar questions
> > your have in the above sample code. This may deserve a separate patch
> > set for discussion. Using a bit in sockptr is mostly free now.
> > WDYT ?
>
> Sorry to chime in but I vote against @in_bpf. I had to search the git
> history recently to figure out what SK_USER_DATA_BPF means. It's not
> going to be obvious to a networking person what semantics to attribute
> to "in bpf".
If I understand the concern correctly, it may not be straight forward to
grip the reason behind the testings at in_bpf() [ the in_task() and
the current->bpf_ctx test ] ? Yes, it is a valid point.
The optval.is_bpf bit can be directly traced back to the bpf_setsockopt
helper and should be easier to reason about.
Powered by blists - more mailing lists