archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <>
To: Martin Lau <>, Wenwen Wang <>
Cc: Kangjie Lu <>, Alexei Starovoitov <>,
	"open list:BPF (Safe dynamic programs and tools)" 
	"open list:BPF (Safe dynamic programs and tools)" 
Subject: Re: [PATCH v2] bpf: btf: Fix a missing-check bug
Date: Fri, 26 Oct 2018 00:58:31 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <20181024203548.glxgu3bqd47minmg@kafai-mbp>

On 10/24/2018 10:42 PM, Martin Lau wrote:
> On Wed, Oct 24, 2018 at 06:22:46PM +0000, Martin Lau wrote:
>> On Wed, Oct 24, 2018 at 05:26:23PM +0000, Martin Lau wrote:
>>> On Wed, Oct 24, 2018 at 08:00:19AM -0500, Wenwen Wang wrote:
>>>> In btf_parse(), the header of the user-space btf data 'btf_data' is firstly
>>>> parsed and verified through btf_parse_hdr(). In btf_parse_hdr(), the header
>>>> is copied from user-space 'btf_data' to kernel-space 'btf->hdr' and then
>>>> verified. If no error happens during the verification process, the whole
>>>> data of 'btf_data', including the header, is then copied to 'data' in
>>>> btf_parse(). It is obvious that the header is copied twice here. More
>>>> importantly, no check is enforced after the second copy to make sure the
>>>> headers obtained in these two copies are same. Given that 'btf_data'
>>>> resides in the user space, a malicious user can race to modify the header
>>>> between these two copies. By doing so, the user can inject inconsistent
>>>> data, which can cause undefined behavior of the kernel and introduce
>>>> potential security risk.
>> btw, I am working on a patch that copies the btf_data before parsing/verifying
>> the header.  That should avoid this from happening but that will
>> require a bit more code churns for the bpf branch.
> It is what I have in mind:
> It is not a good idea to check the BTF header before copying the
> user btf_data.  The verified header may not be the one actually
> copied to btf->data (e.g. userspace may modify the passed in
> btf_data in between).  Like the one fixed in
> commit 8af03d1ae2e1 ("bpf: btf: Fix a missing check bug").
> This patch copies the user btf_data before parsing/verifying
> the BTF header.
> Fixes: 69b693f0aefa ("bpf: btf: Introduce BPF Type Format (BTF)")
> Signed-off-by: Martin KaFai Lau <>

I've added Co-developed-by tag and applied it to bpf tree, thanks everyone!

      parent reply	other threads:[~2018-10-25 22:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-24 13:00 Wenwen Wang
2018-10-24 17:26 ` Martin Lau
2018-10-24 18:22   ` Martin Lau
2018-10-24 20:42     ` Martin Lau
2018-10-24 21:50       ` Song Liu
2018-10-25 22:58       ` Daniel Borkmann [this message]

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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH v2] bpf: btf: Fix a missing-check bug' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).