From patchwork Wed Oct 24 03:27:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Bobrowski X-Patchwork-Id: 989058 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=mbobrowski.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mbobrowski-org.20150623.gappssmtp.com header.i=@mbobrowski-org.20150623.gappssmtp.com header.b="ju77uGkG"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42gnx605VRz9s55 for ; Fri, 26 Oct 2018 00:27:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 328F73E7585 for ; Thu, 25 Oct 2018 15:27:35 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 6D6D43E6AFE for ; Wed, 24 Oct 2018 05:28:09 +0200 (CEST) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 7354C2013A9 for ; Wed, 24 Oct 2018 05:28:03 +0200 (CEST) Received: by mail-pf1-x441.google.com with SMTP id a19-v6so1702432pfo.8 for ; Tue, 23 Oct 2018 20:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ic167uIaONwbkCN0PlpvxCYd1bWDmWQhhlDra6/qo7Q=; b=ju77uGkG7ys078zW/afd08BFnYjxSA1za/YOLaNh59Uyf6FVaHf9vYeQyWj0rdVqZZ 6q+3bDTz/ygHND/gusRT+e/MjDeRXYeSWQfUr+2zcMDI1WDP+nxsh5PztGIvWFQ/J2cj 7EmBG1b4Qwblxhms5xJJLytH4nyyaANYcBn4r8weRwUHiem1u01JdfgxPvWHYLYpHYGU XVz4xA5RkULal2N2xGrw0sa7np+quUxaVCKIGzwC5JGQQ8SstTAo/81pbOb+jkOp68kt IJ0KubGyK9UOj0f0EZ7omwn1nVn786lcqHFpKJAO1KkeLTOMnVP9XhJyMmZ6f6Zt5MSP F0qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ic167uIaONwbkCN0PlpvxCYd1bWDmWQhhlDra6/qo7Q=; b=P2dIo+K9HuSOWD2rDwR2SdhJVHRBQKxAI15d9MLoVLforEUlNqlF6BoMUm2Mdhinbg 8no0t/rDWSoKGJZ1zwxGFr2BsafwxqrrqkTu2ru978KuH0bMI7WBMfj+kDdHf03eMbJ0 KhJXh+SxNDsP+0lsXLDA0aXiFCaQPa6EAYida77TeTk2fNn7eK4Amit6efW9l3skX/01 zGfv5rw+jst7U+MZyzFmXt8G6wcpTEFGqO59tSBUGZJqDKkTiHVlzaq2DJnTda+QRa78 vmOAMtdK2vPuSdWI+ZX2uV/2SxaHqiCfxoffRSdzsfBUG8Qw9WuDdIX7cgDpLLNxhNDP b60w== X-Gm-Message-State: AGRZ1gJ1rgLbGOAPUakCg1GLIFDooqfsa3o1HKcMIqkiLweiLknhu6mV HOrBkFfh4w6EbfS06OrpytLFbwXF19sJ X-Google-Smtp-Source: AJdET5edsPxg5ElVPegvEgewl3v3WIDh9mEnkN9OShCN23wreSAiZkPsbpYOBzr0Sbk9MlBVEjJbeg== X-Received: by 2002:a62:8c0d:: with SMTP id m13-v6mr958724pfd.207.1540351681838; Tue, 23 Oct 2018 20:28:01 -0700 (PDT) Received: from workstation (n114-74-18-206.sbr2.nsw.optusnet.com.au. [114.74.18.206]) by smtp.gmail.com with ESMTPSA id t11-v6sm5158473pgn.38.2018.10.23.20.27.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Oct 2018 20:28:01 -0700 (PDT) Date: Wed, 24 Oct 2018 14:27:56 +1100 From: Matthew Bobrowski To: amir73il@gmail.com, jack@suse.cz Message-ID: <2b2a0e71fd63b7536f0cdfbbc24570283ea98c33.1540348505.git.mbobrowski@mbobrowski.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it X-Mailman-Approved-At: Thu, 25 Oct 2018 15:27:19 +0200 Cc: ltp@lists.linux.it Subject: [LTP] [RFC 2/3] syscalls/fanotify03: included execve() to generate_events() to increase test coverage 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * Created an executable helper program 'fanotify_child' so that can be used within fanotify tests * Defined .resource_files so that additional test resources can be copied across to the tmp working directory i.e. fanotify_child * Updated generate_events() so that it now includes a call to execve() on fanotify_child. This is so that we can increase the overall test coverage by generating more events on a watched object * Updated each tcase events[] to accommodate for the additional events generated by execve() Signed-off-by: Matthew Bobrowski --- testcases/kernel/syscalls/fanotify/.gitignore | 1 + .../kernel/syscalls/fanotify/fanotify03.c | 83 ++++++++++++------- .../kernel/syscalls/fanotify/fanotify_child.c | 14 ++++ 3 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify_child.c diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore index c26f2bd27..af420b8b3 100644 --- a/testcases/kernel/syscalls/fanotify/.gitignore +++ b/testcases/kernel/syscalls/fanotify/.gitignore @@ -8,3 +8,4 @@ /fanotify08 /fanotify09 /fanotify10 +/fanotify_child diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c index cca15aa00..f9418ee6b 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify03.c +++ b/testcases/kernel/syscalls/fanotify/fanotify03.c @@ -35,6 +35,7 @@ #define BUF_SIZE 256 #define TST_TOTAL 3 +#define TEST_APP "fanotify_child" static char fname[BUF_SIZE]; static char buf[BUF_SIZE]; @@ -60,28 +61,31 @@ static struct tcase { { "inode mark permission events", INIT_FANOTIFY_MARK_TYPE(INODE), - FAN_OPEN_PERM | FAN_ACCESS_PERM, 2, + FAN_OPEN_PERM | FAN_ACCESS_PERM, 3, { {FAN_OPEN_PERM, FAN_ALLOW}, - {FAN_ACCESS_PERM, FAN_DENY} + {FAN_ACCESS_PERM, FAN_DENY}, + {FAN_OPEN_PERM, FAN_DENY} } }, { "mount mark permission events", INIT_FANOTIFY_MARK_TYPE(MOUNT), - FAN_OPEN_PERM | FAN_ACCESS_PERM, 2, + FAN_OPEN_PERM | FAN_ACCESS_PERM, 3, { {FAN_OPEN_PERM, FAN_ALLOW}, - {FAN_ACCESS_PERM, FAN_DENY} + {FAN_ACCESS_PERM, FAN_DENY}, + {FAN_OPEN_PERM, FAN_DENY} } }, { "filesystem mark permission events", INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), - FAN_OPEN_PERM | FAN_ACCESS_PERM, 2, + FAN_OPEN_PERM | FAN_ACCESS_PERM, 3, { {FAN_OPEN_PERM, FAN_ALLOW}, - {FAN_ACCESS_PERM, FAN_DENY} + {FAN_ACCESS_PERM, FAN_DENY}, + {FAN_OPEN_PERM, FAN_DENY} } } }; @@ -89,9 +93,10 @@ static struct tcase { static void generate_events(void) { int fd; + char *const argv[] = {TEST_APP, NULL}; /* - * generate sequence of events + * Generate sequence of events */ if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) exit(1); @@ -104,6 +109,9 @@ static void generate_events(void) if (close(fd) == -1) exit(4); + + if (execve(TEST_APP, argv, environ) != -1) + exit(5); } static void child_handler(int tmp) @@ -131,6 +139,7 @@ static void run_child(void) } child_pid = SAFE_FORK(); + if (child_pid == 0) { /* Child will generate events now */ close(fd_notify); @@ -161,38 +170,43 @@ static void check_child(void) static int setup_mark(unsigned int n) { + unsigned int i = 0; struct tcase *tc = &tcases[n]; struct fanotify_mark_type *mark = &tc->mark; + char *const files[] = {fname, TEST_APP}; + tst_res(TINFO, "Test #%d: %s", n, tc->tname); fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY); - if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag, tc->mask, - AT_FDCWD, fname) < 0) { - if (errno == EINVAL && support_perm_events && - mark->flag == FAN_MARK_FILESYSTEM) { - tst_res(TCONF, - "FAN_MARK_FILESYSTEM not supported in kernel?"); - return -1; - } else if (errno == EINVAL) { - tst_brk(TCONF | TERRNO, - "CONFIG_FANOTIFY_ACCESS_PERMISSIONS not " - "configured in kernel?"); + for (; i < ARRAY_SIZE(files); i++) { + if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag, + tc->mask, AT_FDCWD, files[i]) < 0) { + if (errno == EINVAL && support_perm_events && + mark->flag == FAN_MARK_FILESYSTEM) { + tst_res(TCONF, + "FAN_MARK_FILESYSTEM not supported in " + "kernel?"); + return -1; + } else if (errno == EINVAL) { + tst_brk(TCONF | TERRNO, + "CONFIG_FANOTIFY_ACCESS_PERMISSIONS " + "not configured in kernel?"); + } else { + tst_brk(TBROK | TERRNO, + "fanotify_mark (%d, FAN_MARK_ADD | %s, " + "FAN_ACCESS_PERM | FAN_OPEN_PERM, " + "AT_FDCWD, %s) failed.", + fd_notify, mark->name, fname); + } } else { - tst_brk(TBROK | TERRNO, - "fanotify_mark (%d, FAN_MARK_ADD | %s, " - "FAN_ACCESS_PERM | FAN_OPEN_PERM, " - "AT_FDCWD, %s) failed.", - fd_notify, mark->name, fname); + /* + * To distinguish between perm event not supported and + * filesystem mark not supported. + */ + support_perm_events = 1; } - } else { - /* - * To distinguish between perm event not supported and - * filesystem mark not supported. - */ - support_perm_events = 1; } - tst_res(TINFO, "Test #%d: %s", n, tc->tname); return 0; } @@ -294,14 +308,19 @@ static void cleanup(void) SAFE_CLOSE(fd_notify); } +static const char *const resource_files[] = { + TEST_APP, + NULL +}; + static struct tst_test test = { .test = test_fanotify, .tcnt = ARRAY_SIZE(tcases), .setup = setup, .cleanup = cleanup, - .needs_tmpdir = 1, .forks_child = 1, - .needs_root = 1 + .needs_root = 1, + .resource_files = resource_files }; #else diff --git a/testcases/kernel/syscalls/fanotify/fanotify_child.c b/testcases/kernel/syscalls/fanotify/fanotify_child.c new file mode 100644 index 000000000..f43068264 --- /dev/null +++ b/testcases/kernel/syscalls/fanotify/fanotify_child.c @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved. + * + * Started by Matthew Bobrowski + * + * DESCRIPTION + * Simple helper program that can be simply invoked from fanotify tests + */ + +int main(void) +{ + return 0; +}