Commit 286aad3c authored by Daniel Borkmann's avatar Daniel Borkmann Committed by David S. Miller

net: bpf: be friendly to kmemcheck

Reported by Mikulas Patocka, kmemcheck currently barks out a
false positive since we don't have special kmemcheck annotation
for bitfields used in bpf_prog structure.

We currently have jited:1, len:31 and thus when accessing len
while CONFIG_KMEMCHECK enabled, kmemcheck throws a warning that
we're reading uninitialized memory.

As we don't need the whole bit universe for pages member, we
can just split it to u16 and use a bool flag for jited instead
of a bitfield.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Acked-by: default avatarAlexei Starovoitov <ast@plumgrid.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 55309dd3
...@@ -933,7 +933,7 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -933,7 +933,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
set_memory_ro((unsigned long)header, header->pages); set_memory_ro((unsigned long)header, header->pages);
fp->bpf_func = (void *)ctx.target; fp->bpf_func = (void *)ctx.target;
fp->jited = 1; fp->jited = true;
out: out:
kfree(ctx.offsets); kfree(ctx.offsets);
return; return;
......
...@@ -1417,7 +1417,7 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -1417,7 +1417,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
bpf_jit_dump(fp->len, alloc_size, 2, ctx.target); bpf_jit_dump(fp->len, alloc_size, 2, ctx.target);
fp->bpf_func = (void *)ctx.target; fp->bpf_func = (void *)ctx.target;
fp->jited = 1; fp->jited = true;
out: out:
kfree(ctx.offsets); kfree(ctx.offsets);
......
...@@ -686,7 +686,7 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -686,7 +686,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
((u64 *)image)[0] = (u64)code_base; ((u64 *)image)[0] = (u64)code_base;
((u64 *)image)[1] = local_paca->kernel_toc; ((u64 *)image)[1] = local_paca->kernel_toc;
fp->bpf_func = (void *)image; fp->bpf_func = (void *)image;
fp->jited = 1; fp->jited = true;
} }
out: out:
kfree(addrs); kfree(addrs);
......
...@@ -842,7 +842,7 @@ void bpf_jit_compile(struct bpf_prog *fp) ...@@ -842,7 +842,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
if (jit.start) { if (jit.start) {
set_memory_ro((unsigned long)header, header->pages); set_memory_ro((unsigned long)header, header->pages);
fp->bpf_func = (void *) jit.start; fp->bpf_func = (void *) jit.start;
fp->jited = 1; fp->jited = true;
} }
out: out:
kfree(addrs); kfree(addrs);
......
...@@ -801,7 +801,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf]; ...@@ -801,7 +801,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
if (image) { if (image) {
bpf_flush_icache(image, image + proglen); bpf_flush_icache(image, image + proglen);
fp->bpf_func = (void *)image; fp->bpf_func = (void *)image;
fp->jited = 1; fp->jited = true;
} }
out: out:
kfree(addrs); kfree(addrs);
......
...@@ -955,7 +955,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog) ...@@ -955,7 +955,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
bpf_flush_icache(header, image + proglen); bpf_flush_icache(header, image + proglen);
set_memory_ro((unsigned long)header, header->pages); set_memory_ro((unsigned long)header, header->pages);
prog->bpf_func = (void *)image; prog->bpf_func = (void *)image;
prog->jited = 1; prog->jited = true;
} }
out: out:
kfree(addrs); kfree(addrs);
......
...@@ -300,9 +300,9 @@ struct bpf_work_struct { ...@@ -300,9 +300,9 @@ struct bpf_work_struct {
}; };
struct bpf_prog { struct bpf_prog {
u32 pages; /* Number of allocated pages */ u16 pages; /* Number of allocated pages */
u32 jited:1, /* Is our filter JIT'ed? */ bool jited; /* Is our filter JIT'ed? */
len:31; /* Number of filter blocks */ u32 len; /* Number of filter blocks */
struct sock_fprog_kern *orig_prog; /* Original BPF program */ struct sock_fprog_kern *orig_prog; /* Original BPF program */
struct bpf_work_struct *work; /* Deferred free work struct */ struct bpf_work_struct *work; /* Deferred free work struct */
unsigned int (*bpf_func)(const struct sk_buff *skb, unsigned int (*bpf_func)(const struct sk_buff *skb,
......
...@@ -972,7 +972,7 @@ static struct bpf_prog *bpf_prepare_filter(struct bpf_prog *fp) ...@@ -972,7 +972,7 @@ static struct bpf_prog *bpf_prepare_filter(struct bpf_prog *fp)
int err; int err;
fp->bpf_func = NULL; fp->bpf_func = NULL;
fp->jited = 0; fp->jited = false;
err = bpf_check_classic(fp->insns, fp->len); err = bpf_check_classic(fp->insns, fp->len);
if (err) { if (err) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment