提交 3a9af0bd 编写于 作者: K Kees Cook 提交者: Linus Torvalds

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: NKees Cook <keescook@chromium.org>
Reported-by: NRobert Swiecki <swiecki@google.com>
Tested-by: NRobert Swiecki <swiecki@google.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 52644c9a
...@@ -25,7 +25,9 @@ ...@@ -25,7 +25,9 @@
int main(int argc, char **argv) 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 msg1[] = "Please type something: ";
static const char msg2[] = "You typed: "; static const char msg2[] = "You typed: ";
char buf[256]; char buf[256];
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include "bpf-helper.h" #include "bpf-helper.h"
...@@ -63,6 +64,11 @@ __u32 seccomp_bpf_label(struct bpf_labels *labels, const char *label) ...@@ -63,6 +64,11 @@ __u32 seccomp_bpf_label(struct bpf_labels *labels, const char *label)
{ {
struct __bpf_label *begin = labels->labels, *end; struct __bpf_label *begin = labels->labels, *end;
int id; int id;
if (labels->count == BPF_LABELS_MAX) {
fprintf(stderr, "Too many labels\n");
exit(1);
}
if (labels->count == 0) { if (labels->count == 0) {
begin->label = label; begin->label = label;
begin->location = 0xffffffff; begin->location = 0xffffffff;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册