From patchwork Mon Apr 4 23:59:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 606192 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qf8DM4KmYz9sC4 for ; Tue, 5 Apr 2016 10:02:11 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3qf8DM3Ym1zDqJg for ; Tue, 5 Apr 2016 10:02:11 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3qf8CB3SDCzDq6B for ; Tue, 5 Apr 2016 10:01:10 +1000 (AEST) Received: by ozlabs.org (Postfix) id 3qf8CB30Lbz9sD2; Tue, 5 Apr 2016 10:01:10 +1000 (AEST) Delivered-To: linuxppc-dev@ozlabs.org Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) (using TLSv1.2 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qf8CB2PJDz9sCp for ; Tue, 5 Apr 2016 10:01:10 +1000 (AEST) Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Apr 2016 10:01:09 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Apr 2016 10:01:07 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: cyrilbur@gmail.com X-IBM-RcptTo: linuxppc-dev@ozlabs.org Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id DEF32357805A for ; Tue, 5 Apr 2016 10:01:06 +1000 (EST) Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u3500wZ565994920 for ; Tue, 5 Apr 2016 10:01:06 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u3500XBA004799 for ; Tue, 5 Apr 2016 10:00:34 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u3500XWd004050; Tue, 5 Apr 2016 10:00:33 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 550D2A01FB; Tue, 5 Apr 2016 10:00:09 +1000 (AEST) From: Cyril Bur To: linuxppc-dev@ozlabs.org Subject: [PATCH V2 1/5] selftests/powerpc: Add exec() test to check for spr sanitisation Date: Tue, 5 Apr 2016 09:59:23 +1000 Message-Id: <1459814367-3057-1-git-send-email-cyrilbur@gmail.com> X-Mailer: git-send-email 2.7.4 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16040500-0009-0000-0000-000006B777B7 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mikey@neuling.org MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Signed-off-by: Cyril Bur --- tools/testing/selftests/powerpc/syscalls/Makefile | 3 +- .../testing/selftests/powerpc/syscalls/spr_exec.c | 78 ++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/powerpc/syscalls/spr_exec.c diff --git a/tools/testing/selftests/powerpc/syscalls/Makefile b/tools/testing/selftests/powerpc/syscalls/Makefile index b35c794..291ba45 100644 --- a/tools/testing/selftests/powerpc/syscalls/Makefile +++ b/tools/testing/selftests/powerpc/syscalls/Makefile @@ -1,10 +1,11 @@ -TEST_PROGS := ipc_unmuxed +TEST_PROGS := ipc_unmuxed spr_exec CFLAGS += -I../../../../../usr/include all: $(TEST_PROGS) $(TEST_PROGS): ../harness.c +spr_exec: ../utils.c include ../../lib.mk diff --git a/tools/testing/selftests/powerpc/syscalls/spr_exec.c b/tools/testing/selftests/powerpc/syscalls/spr_exec.c new file mode 100644 index 0000000..5ecd6ca --- /dev/null +++ b/tools/testing/selftests/powerpc/syscalls/spr_exec.c @@ -0,0 +1,78 @@ +/* + * Copyright 2016, Cyril Bur, IBM Corp. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * This test checks that the TAR (an SPR) is correctly sanitised across + * execve() + */ +#include +#include +#include +#include +#include + +#include "utils.h" + +static char *name; +static int count; + +static int exec_spr(void) +{ + unsigned long tar; + char buffer[10]; + char *args[3]; + + asm __volatile__( + "mfspr %[tar], 815" + : [tar] "=r" (tar) + ); + /* Read TAR */ + FAIL_IF(tar != 0); + + tar = 1; + asm __volatile__( + "mtspr 815, %[tar]" + : + : [tar] "r" (tar) + ); + + FAIL_IF(sprintf(buffer, "%d", count + 1) == -1); + args[0] = name; + args[1] = buffer; + args[2] = NULL; + FAIL_IF(execve(name, args, NULL) == -1); + + return 0; +} + +static int exec_spr_check(void) +{ + unsigned long tar; + + asm __volatile__( + "mfspr %[tar], 815;" + : [tar] "=r" (tar) + ); + /* Read TAR */ + FAIL_IF(tar != 0); + + return 0; +} + +int main(int argc, char *argv[]) +{ + SKIP_IF(!have_hwcap2(PPC_FEATURE2_TAR)); + name = argv[0]; + /* Do this a few times to be sure isn't a false negative */ + if (argc == 1 || atoi(argv[1]) < 10) { + if (argc > 1) + count = atoi(argv[1]); + return test_harness(exec_spr, "spr_exec"); + } else { + return test_harness(exec_spr_check, "spr_exec_check"); + } +}