bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: Lorenz Bauer <lmb@cloudflare.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	John Fastabend <john.fastabend@gmail.com>
Cc: kernel-team@cloudflare.com, Lorenz Bauer <lmb@cloudflare.com>,
	Andrii Nakryiko <andriin@fb.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: RE: [PATCH bpf v2 1/1] bpf: fix OOB read when printing XDP link fdinfo
Date: Mon, 19 Jul 2021 16:11:43 -0700	[thread overview]
Message-ID: <60f606afc66a1_1e832208e7@john-XPS-13-9370.notmuch> (raw)
In-Reply-To: <20210719085134.43325-2-lmb@cloudflare.com>

Lorenz Bauer wrote:
> We got the following UBSAN report on one of our testing machines:
> 
>     ================================================================================
>     UBSAN: array-index-out-of-bounds in kernel/bpf/syscall.c:2389:24
>     index 6 is out of range for type 'char *[6]'
>     CPU: 43 PID: 930921 Comm: systemd-coredum Tainted: G           O      5.10.48-cloudflare-kasan-2021.7.0 #1
>     Hardware name: <snip>
>     Call Trace:
>      dump_stack+0x7d/0xa3
>      ubsan_epilogue+0x5/0x40
>      __ubsan_handle_out_of_bounds.cold+0x43/0x48
>      ? seq_printf+0x17d/0x250
>      bpf_link_show_fdinfo+0x329/0x380
>      ? bpf_map_value_size+0xe0/0xe0
>      ? put_files_struct+0x20/0x2d0
>      ? __kasan_kmalloc.constprop.0+0xc2/0xd0
>      seq_show+0x3f7/0x540
>      seq_read_iter+0x3f8/0x1040
>      seq_read+0x329/0x500
>      ? seq_read_iter+0x1040/0x1040
>      ? __fsnotify_parent+0x80/0x820
>      ? __fsnotify_update_child_dentry_flags+0x380/0x380
>      vfs_read+0x123/0x460
>      ksys_read+0xed/0x1c0
>      ? __x64_sys_pwrite64+0x1f0/0x1f0
>      do_syscall_64+0x33/0x40
>      entry_SYSCALL_64_after_hwframe+0x44/0xa9
>     <snip>
>     ================================================================================
>     ================================================================================
>     UBSAN: object-size-mismatch in kernel/bpf/syscall.c:2384:2
> 
> From the report, we can infer that some array access in bpf_link_show_fdinfo at index 6
> is out of bounds. The obvious candidate is bpf_link_type_strs[BPF_LINK_TYPE_XDP] with
> BPF_LINK_TYPE_XDP == 6. It turns out that BPF_LINK_TYPE_XDP is missing from bpf_types.h
> and therefore doesn't have an entry in bpf_link_type_strs:
> 
>     pos:	0
>     flags:	02000000
>     mnt_id:	13
>     link_type:	(null)
>     link_id:	4
>     prog_tag:	bcf7977d3b93787c
>     prog_id:	4
>     ifindex:	1
> 
> Fixes: aa8d3a716b59 ("bpf, xdp: Add bpf_link-based XDP attachment API")
> Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
> ---
>  include/linux/bpf_types.h | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h
> index a9db1eae6796..ae3ac3a2018c 100644
> --- a/include/linux/bpf_types.h
> +++ b/include/linux/bpf_types.h
> @@ -134,4 +134,5 @@ BPF_LINK_TYPE(BPF_LINK_TYPE_CGROUP, cgroup)
>  BPF_LINK_TYPE(BPF_LINK_TYPE_ITER, iter)
>  #ifdef CONFIG_NET
>  BPF_LINK_TYPE(BPF_LINK_TYPE_NETNS, netns)
> +BPF_LINK_TYPE(BPF_LINK_TYPE_XDP, xdp)
>  #endif
> -- 
> 2.30.2
> 

Still lgtm.

Acked-by; John Fastabend <john.fastabend@gmail.com>

  reply	other threads:[~2021-07-20  0:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19  8:51 [PATCH bpf v2 0/1] bpf: fix OOB read when printing XDP link fdinfo Lorenz Bauer
2021-07-19  8:51 ` [PATCH bpf v2 1/1] " Lorenz Bauer
2021-07-19 23:11   ` John Fastabend [this message]
2021-07-19 22:31 ` [PATCH bpf v2 0/1] " 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=60f606afc66a1_1e832208e7@john-XPS-13-9370.notmuch \
    --to=john.fastabend@gmail.com \
    --cc=andrii@kernel.org \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=kernel-team@cloudflare.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lmb@cloudflare.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;
as well as URLs for NNTP newsgroup(s).