net: bpf: be friendly to kmemcheck
authorDaniel Borkmann <dborkman@redhat.com>
Mon, 8 Sep 2014 06:04:49 +0000 (08:04 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 Sep 2014 23:58:56 +0000 (16:58 -0700)
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: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/arm/net/bpf_jit_32.c
arch/mips/net/bpf_jit.c
arch/powerpc/net/bpf_jit_comp.c
arch/s390/net/bpf_jit_comp.c
arch/sparc/net/bpf_jit_comp.c
arch/x86/net/bpf_jit_comp.c
include/linux/filter.h
net/core/filter.c

index 2d1a5b93d91c5e566f3c74964bd21bc247425d93..6b45f649eff0c1c205224f2af2e8e4ae1fc79bbe 100644 (file)
@@ -933,7 +933,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
 
        set_memory_ro((unsigned long)header, header->pages);
        fp->bpf_func = (void *)ctx.target;
-       fp->jited = 1;
+       fp->jited = true;
 out:
        kfree(ctx.offsets);
        return;
index cfa83cf2447dc6a8831c1bdf394c1a3fd8b203be..0e97ccd29fe3a6fe37b1b0053b531ccb6149f654 100644 (file)
@@ -1417,7 +1417,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
                bpf_jit_dump(fp->len, alloc_size, 2, ctx.target);
 
        fp->bpf_func = (void *)ctx.target;
-       fp->jited = 1;
+       fp->jited = true;
 
 out:
        kfree(ctx.offsets);
index 40c53ff59124d306f111ed65ceede655ca7f6682..cbae2dfd053cafc22540572652528d4dbedc91fe 100644 (file)
@@ -686,7 +686,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
                ((u64 *)image)[0] = (u64)code_base;
                ((u64 *)image)[1] = local_paca->kernel_toc;
                fp->bpf_func = (void *)image;
-               fp->jited = 1;
+               fp->jited = true;
        }
 out:
        kfree(addrs);
index b734f975c22e6fe4a436ff568412eae9a7f5b1ba..555f5c7e83abfd4e9e62477274ac888f7280092e 100644 (file)
@@ -842,7 +842,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
        if (jit.start) {
                set_memory_ro((unsigned long)header, header->pages);
                fp->bpf_func = (void *) jit.start;
-               fp->jited = 1;
+               fp->jited = true;
        }
 out:
        kfree(addrs);
index f7a736b645e843da002c02338aa0892965a44d42..b2ad9dc5425e261fd580232aff0b22b763542d99 100644 (file)
@@ -801,7 +801,7 @@ cond_branch:                        f_offset = addrs[i + filter[i].jf];
        if (image) {
                bpf_flush_icache(image, image + proglen);
                fp->bpf_func = (void *)image;
-               fp->jited = 1;
+               fp->jited = true;
        }
 out:
        kfree(addrs);
index 9de0b5476b0ca784cbc1296e021355bd422cf075..d56cd1f515bdb8037e67e0cbd45d1bd7b5c0db7f 100644 (file)
@@ -955,7 +955,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
                bpf_flush_icache(header, image + proglen);
                set_memory_ro((unsigned long)header, header->pages);
                prog->bpf_func = (void *)image;
-               prog->jited = 1;
+               prog->jited = true;
        }
 out:
        kfree(addrs);
index 868764fcffb849a2996ff6e9641e50f9d1c65d44..4b59edead908cbd3b3829c8d9a293d4e42d12e82 100644 (file)
@@ -300,9 +300,9 @@ struct bpf_work_struct {
 };
 
 struct bpf_prog {
-       u32                     pages;          /* Number of allocated pages */
-       u32                     jited:1,        /* Is our filter JIT'ed? */
-                               len:31;         /* Number of filter blocks */
+       u16                     pages;          /* Number of allocated pages */
+       bool                    jited;          /* Is our filter JIT'ed? */
+       u32                     len;            /* Number of filter blocks */
        struct sock_fprog_kern  *orig_prog;     /* Original BPF program */
        struct bpf_work_struct  *work;          /* Deferred free work struct */
        unsigned int            (*bpf_func)(const struct sk_buff *skb,
index fa5b7d0f77acb1f8fbc2d3face7bd6a700394daf..dfc716ffa44b3b8264ddd4dffd293f5071f1d862 100644 (file)
@@ -972,7 +972,7 @@ static struct bpf_prog *bpf_prepare_filter(struct bpf_prog *fp)
        int err;
 
        fp->bpf_func = NULL;
-       fp->jited = 0;
+       fp->jited = false;
 
        err = bpf_check_classic(fp->insns, fp->len);
        if (err) {