Re: bpf pointer alignment validation

2017-05-10 Thread David Miller
From: Daniel Borkmann Date: Wed, 10 May 2017 18:21:50 +0200 > On 05/10/2017 05:57 PM, David Miller wrote: >> From: Daniel Borkmann >> Date: Wed, 10 May 2017 17:51:50 +0200 >> >>> Would probably be good nevertheless to have this as a flag for >>> program loads, which gets then passed through to t

Re: bpf pointer alignment validation

2017-05-10 Thread Daniel Borkmann
On 05/10/2017 05:57 PM, David Miller wrote: From: Daniel Borkmann Date: Wed, 10 May 2017 17:51:50 +0200 Would probably be good nevertheless to have this as a flag for program loads, which gets then passed through to the verifier to explicitly enable strict alignment checks. Might certainly ai

Re: bpf pointer alignment validation

2017-05-10 Thread Alexei Starovoitov
On 5/10/17 8:57 AM, David Miller wrote: From: Daniel Borkmann Date: Wed, 10 May 2017 17:51:50 +0200 Would probably be good nevertheless to have this as a flag for program loads, which gets then passed through to the verifier to explicitly enable strict alignment checks. Might certainly aide d

Re: bpf pointer alignment validation

2017-05-10 Thread David Miller
From: Daniel Borkmann Date: Wed, 10 May 2017 17:51:50 +0200 > Would probably be good nevertheless to have this as a flag for > program loads, which gets then passed through to the verifier to > explicitly enable strict alignment checks. > > Might certainly aide developing & testing programs on a

Re: bpf pointer alignment validation

2017-05-10 Thread Daniel Borkmann
On 05/10/2017 05:33 PM, David Miller wrote: From: Alexei Starovoitov Date: Tue, 9 May 2017 22:57:37 -0700 On Tue, May 09, 2017 at 02:32:34PM -0400, David Miller wrote: +static u32 calc_align(u32 imm) +{ + u32 align = 1; + + if (!imm) + return 1U << 31; + + whi

Re: bpf pointer alignment validation

2017-05-10 Thread David Miller
From: Alexei Starovoitov Date: Tue, 9 May 2017 22:57:37 -0700 > On Tue, May 09, 2017 at 02:32:34PM -0400, David Miller wrote: >> >> +static u32 calc_align(u32 imm) >> +{ >> +u32 align = 1; >> + >> +if (!imm) >> +return 1U << 31; >> + >> +while (!(imm & 1)) { >> +

RE: bpf pointer alignment validation

2017-05-10 Thread David Laight
From: Alexei Starovoitov > Sent: 10 May 2017 06:58 > > +static u32 calc_align(u32 imm) > > +{ > > + u32 align = 1; > > + > > + if (!imm) > > + return 1U << 31; > > + > > + while (!(imm & 1)) { > > + imm >>= 1; > > + align <<= 1; > > + } > > + return align; >

Re: bpf pointer alignment validation

2017-05-09 Thread Alexei Starovoitov
On Tue, May 09, 2017 at 02:32:34PM -0400, David Miller wrote: > > +static u32 calc_align(u32 imm) > +{ > + u32 align = 1; > + > + if (!imm) > + return 1U << 31; > + > + while (!(imm & 1)) { > + imm >>= 1; > + align <<= 1; > + } > + return al

Re: bpf pointer alignment validation

2017-05-09 Thread David Miller
From: Daniel Borkmann Date: Mon, 08 May 2017 12:49:25 +0200 > Could you also add test cases specifically to this for test_verifier > in bpf selftests? I'm thinking of the cases when we have no pkt id > and offset originated from reg->off (accumulated through const imm > ops on reg) and insn->off,

Re: bpf pointer alignment validation

2017-05-08 Thread Alexei Starovoitov
On Fri, May 05, 2017 at 10:47:09PM -0400, David Miller wrote: > From: David Miller > Date: Fri, 05 May 2017 16:20:44 -0400 (EDT) > > > Anyways, I'll play with this design and see what happens... > > Feedback is of course welcome. > > Here is a prototype that works for me with test_pkt_access.c,

Re: bpf pointer alignment validation

2017-05-08 Thread David Miller
From: Daniel Borkmann Date: Mon, 08 May 2017 12:49:25 +0200 > On 05/06/2017 04:47 AM, David Miller wrote: >> From: David Miller >> Date: Fri, 05 May 2017 16:20:44 -0400 (EDT) >> >>> Anyways, I'll play with this design and see what happens... >>> Feedback is of course welcome. >> >> Here is a pro

Re: bpf pointer alignment validation

2017-05-08 Thread Daniel Borkmann
On 05/06/2017 04:47 AM, David Miller wrote: From: David Miller Date: Fri, 05 May 2017 16:20:44 -0400 (EDT) Anyways, I'll play with this design and see what happens... Feedback is of course welcome. Here is a prototype that works for me with test_pkt_access.c, which otherwise won't load on sp

Re: bpf pointer alignment validation

2017-05-05 Thread David Miller
From: David Miller Date: Fri, 05 May 2017 16:20:44 -0400 (EDT) > Anyways, I'll play with this design and see what happens... > Feedback is of course welcome. Here is a prototype that works for me with test_pkt_access.c, which otherwise won't load on sparc. diff --git a/include/linux/bpf_verifie

bpf pointer alignment validation

2017-05-05 Thread David Miller
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