diff options
author | Kees Cook <keescook@chromium.org> | 2015-02-17 16:47:58 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-17 17:34:55 -0500 |
commit | 3a9af0bd34410a255d27024ea1bc28dc4e3a0044 (patch) | |
tree | fc248a3d7edb3e0ef323c9352f6467a476a86b01 | |
parent | 52644c9ab3faefbfbf07a19c24c4e74e33cfd796 (diff) |
samples/seccomp: improve label helper
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>
-rw-r--r-- | samples/seccomp/bpf-fancy.c | 4 | ||||
-rw-r--r-- | samples/seccomp/bpf-helper.c | 6 |
2 files changed, 9 insertions, 1 deletions
diff --git a/samples/seccomp/bpf-fancy.c b/samples/seccomp/bpf-fancy.c index 8eb483aaec46..e8b24f443709 100644 --- a/samples/seccomp/bpf-fancy.c +++ b/samples/seccomp/bpf-fancy.c | |||
@@ -25,7 +25,9 @@ | |||
25 | 25 | ||
26 | int main(int argc, char **argv) | 26 | int main(int argc, char **argv) |
27 | { | 27 | { |
28 | struct bpf_labels l; | 28 | struct bpf_labels l = { |
29 | .count = 0, | ||
30 | }; | ||
29 | static const char msg1[] = "Please type something: "; | 31 | static const char msg1[] = "Please type something: "; |
30 | static const char msg2[] = "You typed: "; | 32 | static const char msg2[] = "You typed: "; |
31 | char buf[256]; | 33 | char buf[256]; |
diff --git a/samples/seccomp/bpf-helper.c b/samples/seccomp/bpf-helper.c index 579cfe331886..05cb4d5ff9f5 100644 --- a/samples/seccomp/bpf-helper.c +++ b/samples/seccomp/bpf-helper.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <stdio.h> | 12 | #include <stdio.h> |
13 | #include <stdlib.h> | ||
13 | #include <string.h> | 14 | #include <string.h> |
14 | 15 | ||
15 | #include "bpf-helper.h" | 16 | #include "bpf-helper.h" |
@@ -63,6 +64,11 @@ __u32 seccomp_bpf_label(struct bpf_labels *labels, const char *label) | |||
63 | { | 64 | { |
64 | struct __bpf_label *begin = labels->labels, *end; | 65 | struct __bpf_label *begin = labels->labels, *end; |
65 | int id; | 66 | int id; |
67 | |||
68 | if (labels->count == BPF_LABELS_MAX) { | ||
69 | fprintf(stderr, "Too many labels\n"); | ||
70 | exit(1); | ||
71 | } | ||
66 | if (labels->count == 0) { | 72 | if (labels->count == 0) { |
67 | begin->label = label; | 73 | begin->label = label; |
68 | begin->location = 0xffffffff; | 74 | begin->location = 0xffffffff; |