From: Song Liu <songliubraving@fb.com>
To: Martin Lau <kafai@fb.com>
Cc: Networking <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Kernel Team <Kernel-team@fb.com>
Subject: Re: [PATCH bpf-next 1/6] bpf: btf: Avoid WARN_ON when CONFIG_REFCOUNT_FULL=y
Date: Tue, 8 May 2018 21:09:05 +0000 [thread overview]
Message-ID: <66DB0A5D-04A4-4F6A-AF44-166D2FE9ACF6@fb.com> (raw)
In-Reply-To: <20180504214955.1058805-2-kafai@fb.com>
> On May 4, 2018, at 2:49 PM, Martin KaFai Lau <kafai@fb.com> wrote:
>
> If CONFIG_REFCOUNT_FULL=y, refcount_inc() WARN when refcount is 0.
> When creating a new btf, the initial btf->refcnt is 0 and
> triggered the following:
>
> [ 34.855452] refcount_t: increment on 0; use-after-free.
> [ 34.856252] WARNING: CPU: 6 PID: 1857 at lib/refcount.c:153 refcount_inc+0x26/0x30
> ....
> [ 34.868809] Call Trace:
> [ 34.869168] btf_new_fd+0x1af6/0x24d0
> [ 34.869645] ? btf_type_seq_show+0x200/0x200
> [ 34.870212] ? lock_acquire+0x3b0/0x3b0
> [ 34.870726] ? security_capable+0x54/0x90
> [ 34.871247] __x64_sys_bpf+0x1b2/0x310
> [ 34.871761] ? __ia32_sys_bpf+0x310/0x310
> [ 34.872285] ? bad_area_access_error+0x310/0x310
> [ 34.872894] do_syscall_64+0x95/0x3f0
>
> This patch uses refcount_set() instead.
>
> Reported-by: Yonghong Song <yhs@fb.com>
> Tested-by: Yonghong Song <yhs@fb.com>
> Signed-off-by: Martin KaFai Lau <kafai@fb.com>
> ---
> kernel/bpf/btf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 22e1046a1a86..fa0dce0452e7 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -1977,7 +1977,7 @@ static struct btf *btf_parse(void __user *btf_data, u32 btf_data_size,
>
> if (!err) {
> btf_verifier_env_free(env);
> - btf_get(btf);
> + refcount_set(&btf->refcnt, 1);
> return btf;
> }
>
> --
> 2.9.5
>
Acked-by: Song Liu <songliubraving@fb.com>
next prev parent reply other threads:[~2018-05-08 21:10 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-04 21:49 [PATCH bpf-next 0/6] Introduce BTF ID Martin KaFai Lau
2018-05-04 21:49 ` [PATCH bpf-next 1/6] bpf: btf: Avoid WARN_ON when CONFIG_REFCOUNT_FULL=y Martin KaFai Lau
2018-05-08 21:09 ` Song Liu [this message]
2018-05-04 21:49 ` [PATCH bpf-next 2/6] bpf: btf: Introduce BTF ID Martin KaFai Lau
2018-05-08 21:09 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 3/6] bpf: btf: Add struct bpf_btf_info Martin KaFai Lau
2018-05-08 21:09 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 4/6] bpf: btf: Some test_btf clean up Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 5/6] bpf: btf: Update tools/include/uapi/linux/btf.h with BTF ID Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-04 21:49 ` [PATCH bpf-next 6/6] bpf: btf: Tests for BPF_OBJ_GET_INFO_BY_FD and BPF_BTF_GET_FD_BY_ID Martin KaFai Lau
2018-05-08 21:18 ` Song Liu
2018-05-09 16:08 ` [PATCH bpf-next 0/6] Introduce BTF ID Daniel Borkmann
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=66DB0A5D-04A4-4F6A-AF44-166D2FE9ACF6@fb.com \
--to=songliubraving@fb.com \
--cc=Kernel-team@fb.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
/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