bpf: enforce correct alignment for instructions
Subsystems (4)
PATCH 1/1 bpf: enforce correct alignment for instructions
After commit 9facc336876f ("bpf: reject any prog that failed read-only lock") offsetof(struct bpf_binary_header, image) became 3 instead of 4, breaking powerpc BPF badly, since instructions need to be word aligned.
--- include/linux/filter.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/filter.h +3 -1
@@ -472,7 +472,9 @@ struct sock_fprog_kern {struct bpf_binary_header {u16 pages;u16 locked:1 ; -u8 image[]; + +/* Some arches need word alignment for their instructions */ +u8 image[]__aligned(4) ; };struct bpf_prog {
Signature · 1 line
2.18.0.rc1.244.gcf134e6275-goog
David Miller
maintainerFrom: Eric Dumazet <[email protected]>
Date: Wed, 20 Jun 2018 17:24:09 -0700
Quoted 6 lines
After commit
9facc336876f("bpf: reject any prog that failed read-only lock")offsetof(struct bpf_binary_header, image)became 3 instead of 4, breaking powerpc BPF badly, since instructions need to be word aligned.Fixes 9facc336876f ("bpf: reject any prog that failed read-only lock")Signed-off-by Eric Dumazet <[email protected]>
I'll apply this directly, thanks Eric.
Quoted 12 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Wed, 20 Jun 2018 17:24:09 -0700Quoted 6 lines
After commit
9facc336876f("bpf: reject any prog that failed read-only lock")offsetof(struct bpf_binary_header, image)became 3 instead of 4, breaking powerpc BPF badly, since instructions need to be word aligned.Fixes 9facc336876f ("bpf: reject any prog that failed read-only lock")Signed-off-by Eric Dumazet <[email protected]>I'll apply this directly, thanks Eric.
Thanks David :)
Daniel Borkmann
maintainerQuoted 8 lines · Eric Dumazet
Quoted 7 lines · David Miller
From: Eric Dumazet <[email protected]>
Date: Wed, 20 Jun 2018 17:24:09 -0700Quoted 4 lines
After commit
9facc336876f("bpf: reject any prog that failed read-only lock")offsetof(struct bpf_binary_header, image)became 3 instead of 4, breaking powerpc BPF badly, since instructions need to be word aligned.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixes 9facc336876f ("bpf: reject any prog that failed read-only lock")Signed-off-by Eric Dumazet <[email protected]>I'll apply this directly, thanks Eric.
Thanks David :)
Sigh, sorry for the breakage, looks like I got fooled by x86 gcc.
struct bpf_binary_header {
u16 pages; /* 0 2 */
u16 locked:1; /* 2:15 2 */
/* XXX 15 bits hole, try to pack */
u8 image[0]; /* 4 0 */
/* size: 4, cachelines: 1, members: 3 */
/* bit holes: 1, sum bit holes: 15 bits */
/* last cacheline: 4 bytes */
};Thanks Eric!
David Miller
maintainerFrom: Daniel Borkmann <[email protected]>
Date: Thu, 21 Jun 2018 23:03:09 +0200
Quoted 14 lines · Eric Dumazet
Quoted 13 lines · David Miller
Quoted 11 lines
From: Eric Dumazet <[email protected]>
Date: Wed, 20 Jun 2018 17:24:09 -0700Quoted 6 lines
After commit
9facc336876f("bpf: reject any prog that failed read-only lock")offsetof(struct bpf_binary_header, image)became 3 instead of 4, breaking powerpc BPF badly, since instructions need to be word aligned.Fixes 9facc336876f ("bpf: reject any prog that failed read-only lock")Signed-off-by Eric Dumazet <[email protected]>I'll apply this directly, thanks Eric.
Quoted 7 lines
Quoted 1 line
Thanks David :)
Sigh, sorry for the breakage, looks like I got fooled by x86 gcc.
struct
bpf_binary_header{u16 pages; /* 0 2 */ u16 locked:1; /* 2:15 2 */
Note that you can also just make locked a plan u16 for now until you need more flag bits, the code generated will be more efficient especially on non-x86.