Skip to content

Commit

Permalink
samples/seccomp: improve label helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kees authored and torvalds committed Feb 17, 2015
1 parent 52644c9 commit 3a9af0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion samples/seccomp/bpf-fancy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions samples/seccomp/bpf-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "bpf-helper.h"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a9af0b

Please sign in to comment.