samples/seccomp: improve label helper
authorKees Cook <keescook@chromium.org>
Tue, 17 Feb 2015 21:47:58 +0000 (13:47 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 17 Feb 2015 22:34:55 +0000 (14:34 -0800)
Fixes a potential corruption with uninitialized stack memory in the
seccomp BPF sample program.

[akpm@linux-foundation.org: coding-style fixlet]
Signed-off-by: Kees Cook <keescook@chromium.org>
Reported-by: Robert Swiecki <swiecki@google.com>
Tested-by: Robert Swiecki <swiecki@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
samples/seccomp/bpf-fancy.c
samples/seccomp/bpf-helper.c

index 8eb483aaec465efcc1f40c70a8c76d179eb094a2..e8b24f443709dd04a3df7c541e26075b12bb1048 100644 (file)
@@ -25,7 +25,9 @@
 
 int main(int argc, char **argv)
 {
-       struct bpf_labels l;
+       struct bpf_labels l = {
+               .count = 0,
+       };
        static const char msg1[] = "Please type something: ";
        static const char msg2[] = "You typed: ";
        char buf[256];
index 579cfe3318862f360cc45cd440db633e6c6f0664..05cb4d5ff9f5bef632baa98eb687f1781dcb5e5e 100644 (file)
@@ -10,6 +10,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "bpf-helper.h"
@@ -63,6 +64,11 @@ __u32 seccomp_bpf_label(struct bpf_labels *labels, const char *label)
 {
        struct __bpf_label *begin = labels->labels, *end;
        int id;
+
+       if (labels->count == BPF_LABELS_MAX) {
+               fprintf(stderr, "Too many labels\n");
+               exit(1);
+       }
        if (labels->count == 0) {
                begin->label = label;
                begin->location = 0xffffffff;