From: David Miller <davem@davemloft.net>
To: daniel@iogearbox.net
Cc: ast@fb.com, kafai@fb.com, john.fastabend@gmail.com,
netdev@vger.kernel.org
Subject: Re: [PATCH net] bpf: prevent leaking pointer via xadd on unpriviledged
Date: Thu, 29 Jun 2017 15:45:10 -0400 (EDT) [thread overview]
Message-ID: <20170629.154510.1016576510128739964.davem@davemloft.net> (raw)
In-Reply-To: <1fe53aa29cf003f14acf4b490e5eff038718444a.1498697608.git.daniel@iogearbox.net>
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Thu, 29 Jun 2017 03:04:59 +0200
> Leaking kernel addresses on unpriviledged is generally disallowed,
> for example, verifier rejects the following:
>
> 0: (b7) r0 = 0
> 1: (18) r2 = 0xffff897e82304400
> 3: (7b) *(u64 *)(r1 +48) = r2
> R2 leaks addr into ctx
>
> Doing pointer arithmetic on them is also forbidden, so that they
> don't turn into unknown value and then get leaked out. However,
> there's xadd as a special case, where we don't check the src reg
> for being a pointer register, e.g. the following will pass:
>
> 0: (b7) r0 = 0
> 1: (7b) *(u64 *)(r1 +48) = r0
> 2: (18) r2 = 0xffff897e82304400 ; map
> 4: (db) lock *(u64 *)(r1 +48) += r2
> 5: (95) exit
>
> We could store the pointer into skb->cb, loose the type context,
> and then read it out from there again to leak it eventually out
> of a map value. Or more easily in a different variant, too:
>
> 0: (bf) r6 = r1
> 1: (7a) *(u64 *)(r10 -8) = 0
> 2: (bf) r2 = r10
> 3: (07) r2 += -8
> 4: (18) r1 = 0x0
> 6: (85) call bpf_map_lookup_elem#1
> 7: (15) if r0 == 0x0 goto pc+3
> R0=map_value(ks=8,vs=8,id=0),min_value=0,max_value=0 R6=ctx R10=fp
> 8: (b7) r3 = 0
> 9: (7b) *(u64 *)(r0 +0) = r3
> 10: (db) lock *(u64 *)(r0 +0) += r6
> 11: (b7) r0 = 0
> 12: (95) exit
>
> from 7 to 11: R0=inv,min_value=0,max_value=0 R6=ctx R10=fp
> 11: (b7) r0 = 0
> 12: (95) exit
>
> Prevent this by checking xadd src reg for pointer types. Also
> add a couple of test cases related to this.
>
> Fixes: 1be7f75d1668 ("bpf: enable non-root eBPF programs")
> Fixes: 17a5267067f3 ("bpf: verifier (add verifier core)")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Applied and queued up for -stable, thanks Daniel.
prev parent reply other threads:[~2017-06-29 19:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-29 1:04 [PATCH net] bpf: prevent leaking pointer via xadd on unpriviledged Daniel Borkmann
2017-06-29 3:41 ` Alexei Starovoitov
2017-06-29 16:44 ` Martin KaFai Lau
2017-06-29 16:53 ` Edward Cree
2017-06-29 19:45 ` David Miller [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:
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=20170629.154510.1016576510128739964.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).