Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966450AbbBCS4j (ORCPT ); Tue, 3 Feb 2015 13:56:39 -0500 Received: from smtp.outflux.net ([198.145.64.163]:39045 "EHLO smtp.outflux.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965907AbbBCS4g (ORCPT ); Tue, 3 Feb 2015 13:56:36 -0500 Date: Tue, 3 Feb 2015 10:56:33 -0800 From: Kees Cook To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Robert Swiecki Subject: [PATCH] samples/seccomp: improve label helper Message-ID: <20150203185633.GA15856@www.outflux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-HELO: www.outflux.net Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Fixes a potential corruption with uninitialized stack memory in the seccomp BPF sample program. Reported-by: Robert Swiecki Signed-off-by: Kees Cook --- samples/seccomp/bpf-fancy.c | 4 +++- samples/seccomp/bpf-helper.c | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 @@ 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]; diff --git a/samples/seccomp/bpf-helper.c b/samples/seccomp/bpf-helper.c index 579cfe331886..f9fa14d81798 100644 --- a/samples/seccomp/bpf-helper.c +++ b/samples/seccomp/bpf-helper.c @@ -10,6 +10,7 @@ */ #include +#include #include #include "bpf-helper.h" @@ -63,6 +64,10 @@ __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; -- 1.9.1 -- Kees Cook Chrome OS Security