Skip to content

Commit 3a9af0b

Browse files
keestorvalds
authored andcommitted
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>
1 parent 52644c9 commit 3a9af0b

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎samples/seccomp/bpf-fancy.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
int main(int argc, char **argv)
2727
{
28-
struct bpf_labels l;
28+
struct bpf_labels l = {
29+
.count = 0,
30+
};
2931
static const char msg1[] = "Please type something: ";
3032
static const char msg2[] = "You typed: ";
3133
char buf[256];

‎samples/seccomp/bpf-helper.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111

1212
#include <stdio.h>
13+
#include <stdlib.h>
1314
#include <string.h>
1415

1516
#include "bpf-helper.h"
@@ -63,6 +64,11 @@ __u32 seccomp_bpf_label(struct bpf_labels *labels, const char *label)
6364
{
6465
struct __bpf_label *begin = labels->labels, *end;
6566
int id;
67+
68+
if (labels->count == BPF_LABELS_MAX) {
69+
fprintf(stderr, "Too many labels\n");
70+
exit(1);
71+
}
6672
if (labels->count == 0) {
6773
begin->label = label;
6874
begin->location = 0xffffffff;

0 commit comments

Comments
 (0)