All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Maxim Mikityanskiy" <maximmi@nvidia.com>,
	"Pablo Neira Ayuso" <pablo@netfilter.org>,
	"Florian Westphal" <fw@strlen.de>,
	"Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>
Subject: Re: [PATCH bpf-next v6 02/11] bpf: Fix UAF due to race between btf_try_get_module and load_module
Date: Thu, 6 Jan 2022 14:16:03 +0530	[thread overview]
Message-ID: <20220106084603.pgyziuv7wdts4yt7@apollo.legion> (raw)
In-Reply-To: <20220105061040.snl7hqsogeqxxruo@ast-mbp.dhcp.thefacebook.com>

On Wed, Jan 05, 2022 at 11:40:40AM IST, Alexei Starovoitov wrote:
> On Sun, Jan 02, 2022 at 09:51:06PM +0530, Kumar Kartikeya Dwivedi wrote:
> >
> > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> > index 33bb8ae4a804..b5b423de53ab 100644
> > --- a/kernel/bpf/btf.c
> > +++ b/kernel/bpf/btf.c
> > @@ -6338,7 +6338,10 @@ struct module *btf_try_get_module(const struct btf *btf)
> >  		if (btf_mod->btf != btf)
> >  			continue;
> >
> > -		if (try_module_get(btf_mod->module))
> > +		/* We must only consider module whose __init routine has
> > +		 * finished, hence use try_module_get_live.
> > +		 */
> > +		if (try_module_get_live(btf_mod->module))
>
> Instead of patch 1 refactoring for this very specific case can we do:
> 1.
> if (try_module_get(btf_mod->module)) {
>      if (btf_mod->module->state != MODULE_STATE_LIVE)
>         module_put(btf_mod->module);
>      else
>         res = btf_mod->module;
>
> 2.
> preempt_disable();
> if (btf_mod->module->state == MODULE_STATE_LIVE &&
>     try_module_get(btf_mod->module)) ...
> preempt_enable();
>
> 3. add
> case MODULE_STATE_LIVE:
> to btf_module_notify()
> and have an extra flag in struct btf_module to say that it's ready?
>
> I'm mainly concerned about:
> -EXPORT_SYMBOL(try_module_get);
> +EXPORT_SYMBOL(__try_module_get);
> in the patch 1. Not that I care about out of tree modules,
> but we shouldn't be breaking them without a reason.

Alright, we could also export try_module_get, but let's go with option 3.

--
Kartikeya

  reply	other threads:[~2022-01-06  8:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-02 16:21 [PATCH bpf-next v6 00/11] Introduce unstable CT lookup helpers Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 01/11] kernel: Implement try_module_get_live Kumar Kartikeya Dwivedi
2022-01-25 18:50   ` Luis Chamberlain
2022-01-02 16:21 ` [PATCH bpf-next v6 02/11] bpf: Fix UAF due to race between btf_try_get_module and load_module Kumar Kartikeya Dwivedi
2022-01-05  6:10   ` Alexei Starovoitov
2022-01-06  8:46     ` Kumar Kartikeya Dwivedi [this message]
2022-01-02 16:21 ` [PATCH bpf-next v6 03/11] bpf: Populate kfunc BTF ID sets in struct btf Kumar Kartikeya Dwivedi
2022-01-05  6:19   ` Alexei Starovoitov
2022-01-06  8:59     ` Kumar Kartikeya Dwivedi
2022-01-06 23:40       ` Alexei Starovoitov
2022-01-07  6:26         ` Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 04/11] bpf: Remove check_kfunc_call callback and old kfunc BTF ID API Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 05/11] bpf: Introduce mem, size argument pair support for kfunc Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 06/11] bpf: Add reference tracking support to kfunc Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 07/11] net/netfilter: Add unstable CT lookup helpers for XDP and TC-BPF Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 08/11] selftests/bpf: Add test for unstable CT lookup API Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 09/11] selftests/bpf: Add test_verifier support to fixup kfunc call insns Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 10/11] selftests/bpf: Extend kfunc selftests Kumar Kartikeya Dwivedi
2022-01-02 16:21 ` [PATCH bpf-next v6 11/11] selftests/bpf: Add test for race in btf_try_get_module Kumar Kartikeya Dwivedi
2022-01-05  6:20   ` Alexei Starovoitov
2022-01-06  9:04     ` Kumar Kartikeya Dwivedi
2022-01-06 19:39       ` Andrii Nakryiko
2022-01-07  7:22         ` Kumar Kartikeya Dwivedi
2022-01-07 20:10           ` Andrii Nakryiko

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=20220106084603.pgyziuv7wdts4yt7@apollo.legion \
    --to=memxor@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=daniel@iogearbox.net \
    --cc=fw@strlen.de \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=maximmi@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=songliubraving@fb.com \
    --cc=toke@redhat.com \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.