From patchwork Thu Apr 19 19:55:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 901468 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40RqVj0b2Jz9s1t for ; Fri, 20 Apr 2018 05:56:13 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0F12F3E7B31 for ; Thu, 19 Apr 2018 21:55:56 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 47F8F3E7701 for ; Thu, 19 Apr 2018 21:55:34 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id B428A140184D for ; Thu, 19 Apr 2018 21:55:33 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E8546AF0D; Thu, 19 Apr 2018 19:55:32 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 19 Apr 2018 21:55:03 +0200 Message-Id: <20180419195503.7194-11-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180419195503.7194-1-pvorel@suse.cz> References: <20180419195503.7194-1-pvorel@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: linux-integrity@vger.kernel.org, Mimi Zohar Subject: [LTP] [RFC PATCH v3 10/10] ima/ima_mmap: Rewrite to new library X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Filename passed as getopt parameter. Signed-off-by: Petr Vorel --- .../kernel/security/integrity/ima/src/ima_mmap.c | 75 +++++++++++----------- .../security/integrity/ima/tests/ima_violations.sh | 2 +- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/testcases/kernel/security/integrity/ima/src/ima_mmap.c b/testcases/kernel/security/integrity/ima/src/ima_mmap.c index 9045e79a0..5bc688bd4 100644 --- a/testcases/kernel/security/integrity/ima/src/ima_mmap.c +++ b/testcases/kernel/security/integrity/ima/src/ima_mmap.c @@ -14,48 +14,49 @@ * Open and mmap a file and sleep. Another process will open the * mmapped file in read mode, resulting in a open_writer violation. */ -#include -#include -#include -#include -#include -#include -#include "test.h" -char *TCID = "ima_mmap"; -int TST_TOTAL = 1; +#include "tst_test.h" #define SLEEP_AFTER_CLOSE 3 +#define MMAPSIZE 1024 -int main(int argc, char *argv[]) +static char *filename; +static void *file; +static int fd; + +static struct tst_option options[] = { + {"f:", &filename, + "-f file File to mmap"}, + {NULL, NULL, NULL} +}; + +static void cleanup(void) +{ + if (file) + SAFE_MUNMAP(file, MMAPSIZE); + + if (fd > 0) + SAFE_CLOSE(fd); +} + +static void run(void) { - int fd; - void *file; - char *filename; - - if (argc != 2) - printf("%s: filename\n", argv[1]); - filename = argv[1]; - - fd = open(filename, O_CREAT | O_RDWR, S_IRWXU); - if (fd < 0) { - perror("open"); - return (-1); - } - - file = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (file == (void *)-1) { - perror("mmap"); - return (-1); - } - close(fd); - - tst_resm(TINFO, "sleep %ds", SLEEP_AFTER_CLOSE); + if (!filename) + tst_brk(TBROK, "Usage: %s -f filename", TCID); + + fd = SAFE_OPEN(filename, O_CREAT | O_RDWR, S_IRWXU); + + file = SAFE_MMAP(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + SAFE_CLOSE(fd); + + tst_res(TINFO, "sleep %ds", SLEEP_AFTER_CLOSE); sleep(SLEEP_AFTER_CLOSE); - if (munmap(file, 1024) < 0) { - perror("unmap"); - return (-1); - } - tst_exit(); + tst_res(TPASS, "test completed"); } + +static struct tst_test test = { + .options = options, + .test_all = run, + .cleanup = cleanup, +}; diff --git a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh index 8742f4593..f3f40d455 100755 --- a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh +++ b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh @@ -142,7 +142,7 @@ test3() echo 'testing testing' > $FILE - ima_mmap $FILE & + ima_mmap -f $FILE & # wait for violations appear in logs tst_sleep 1s