All of lore.kernel.org
 help / color / mirror / Atom feed
* bpf pointer alignment validation
@ 2017-05-05 20:20 David Miller
  2017-05-06  2:47 ` David Miller
  0 siblings, 1 reply; 14+ messages in thread
From: David Miller @ 2017-05-05 20:20 UTC (permalink / raw)
  To: ast; +Cc: daniel, netdev


Alexei and Daniel, I just wanted to let you guys know that I'm working
on an alignment tracker in the BPF verifier.

After trying several approaches I think what is going to work is to
maintain state like this:

1) For non-pointer registers, we record what we can prove is the
   minimum alignment of the value held in the register.

   So for example:

	r5 <<= 2

   would result in a min_align value of '4'.

   These alignment values assist us when check_packet_ptr_add() has to
   transition a pointer register and allocate an ID to it.

2) Packet pointer registers have a base alignment (which is something
   relative to NET_IP_ALIGN).

   Then there is something called an auxiliary offset alignment.

   Any time we add some non-constant value to a pointer, we apply the
   value's min alignment to the pointer register's auxiliary offset
   alignment.

Then check_pkt_ptr_alignment has it's logic adjusted such that it
takes all of this new information into account.

First, it makes the existing test:

        if ((NET_IP_ALIGN + reg->off + off) % size != 0) {

except that NET_IP_ALIGN is replaced with the packet pointer base
alignment (which we'll set in the context load helpers, thus putting
the NET_IP_ALIGN detail back into the networking code).

So that turns into something like:

        if ((reg->ptr_base_align + reg->off + off) % size != 0) {

Next, if an ID has been assigned, we have to also check the auxiliary
alignment:

	if (reg->id && (reg->aux_off_align % size) != 0) {

Otherwise, we can prove that the size access will work.

I think in order for this to work properly, we also have to stop
"forgetting" the reg->off value when we assign an ID to a pointer
register.  However, the reg->range we still have to always kill in
this situation.

Anyways, I'll play with this design and see what happens...  Feedback
is of course welcome.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2017-05-10 16:45 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-05 20:20 bpf pointer alignment validation David Miller
2017-05-06  2:47 ` David Miller
2017-05-08 10:49   ` Daniel Borkmann
2017-05-08 15:04     ` David Miller
2017-05-09 18:32     ` David Miller
2017-05-10  5:57       ` Alexei Starovoitov
2017-05-10 11:12         ` David Laight
2017-05-10 15:33         ` David Miller
2017-05-10 15:51           ` Daniel Borkmann
2017-05-10 15:57             ` David Miller
2017-05-10 16:15               ` Alexei Starovoitov
2017-05-10 16:21               ` Daniel Borkmann
2017-05-10 16:45                 ` David Miller
2017-05-08 17:30   ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.