[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220105061040.snl7hqsogeqxxruo@ast-mbp.dhcp.thefacebook.com>
Date: Tue, 4 Jan 2022 22:10:40 -0800
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Kumar Kartikeya Dwivedi <memxor@...il.com>
Cc: bpf@...r.kernel.org, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, netdev@...r.kernel.org,
netfilter-devel@...r.kernel.org, Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
Maxim Mikityanskiy <maximmi@...dia.com>,
Pablo Neira Ayuso <pablo@...filter.org>,
Florian Westphal <fw@...len.de>,
Jesper Dangaard Brouer <brouer@...hat.com>,
Toke Høiland-Jørgensen <toke@...hat.com>
Subject: Re: [PATCH bpf-next v6 02/11] bpf: Fix UAF due to race between
btf_try_get_module and load_module
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.
Powered by blists - more mailing lists