From patchwork Thu Jun 20 09:58:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Bobrowski X-Patchwork-Id: 1119322 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=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="OOILDFfC"; 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 45Ty200HRsz9s4V for ; Thu, 20 Jun 2019 19:58:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 81FD8298931 for ; Thu, 20 Jun 2019 11:58:29 +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 B0C7C2987A9 for ; Thu, 20 Jun 2019 11:58:27 +0200 (CEST) Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (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 D9EE4201013 for ; Thu, 20 Jun 2019 11:58:26 +0200 (CEST) Received: by mail-pl1-x643.google.com with SMTP id g4so1182916plb.5 for ; Thu, 20 Jun 2019 02:58:26 -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=KWqMjogGt80KOsQCQmhghuqKSAs8rmfJD0jxQwQMaMw=; b=OOILDFfC+L009bzfvass5jbLdwsxVtT9oCTTQg6+fa6qiVpguSD1lfsaJLXA20L6ib CtSPYBg7NxBuH5sz75r2fYfheM74hk5MG5JK0vSiWyHHMn2Fx0z1KLqrHSJeNyufkdh7 3Ms2ENwp4AYz2Mz6ZWNryoYRxyOG8ZA85ohjKB1xIU+ILgl6cD0rHMNFlmLZIoBXx8Xl HL1zs256mdVieT1+6vE0f2Q41JhM1sdHDf44F3tbmTFMQaxAqU5eo+ST3nSqxp6uvcCw uxofOKuY9FCfk+D3GmimZ1VC+dhyek4nHRsXCTpnpbo6qowKQ5/OwFUrh1bNVzvnahT/ 6Ljg== 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=KWqMjogGt80KOsQCQmhghuqKSAs8rmfJD0jxQwQMaMw=; b=cyZUcnMn4Ij9Ie2lL3zU9ZbDRriQQdJxXL3PZUPSH9pnfnYLq4hQvnJeCMDijt4A7F zSwWmxkXnSHaTPEV0qW4oN8NsJJ3AOUdzoalkfspG98m+NsvrloUcGF+rAsy8CIO9Qs8 5+CL3c7supum9yL80jFI7Miv7ayK10UwTEvXHJ4V/8Hr4LsTtmNBnz5YTp1WDtDSx6s+ epUNBD9zA9IyXZygPBHgTd5mLffkDbtJuTxGB9QibZvB+PPhNoQumS9kuh9JqQ+kMPpg TPuWgu9MBfVQdpYjILfEfICtpCHWDnZcMf78bdvu5KDxuMjM8EZhFTJS99ND1RV0Tiq2 SsZw== X-Gm-Message-State: APjAAAXSzyi6JjUZF+o/cz9HPLZcaJOqVRffRiP31vaExa7SGDsJM3Ef PRjICmMIG+9Wnu+SzVFz9cLbL5ztKA== X-Google-Smtp-Source: APXvYqzZvhn3tUwmj+ygNS/3LahVkUZjmwRhLAS3025oveF7j2rkZWq/Y3mQeJuUNuXzjUIoLsDPvg== X-Received: by 2002:a17:902:934a:: with SMTP id g10mr114562678plp.18.1561024704893; Thu, 20 Jun 2019 02:58:24 -0700 (PDT) Received: from neo.Home ([114.78.0.167]) by smtp.gmail.com with ESMTPSA id c69sm6456769pje.6.2019.06.20.02.58.22 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 20 Jun 2019 02:58:23 -0700 (PDT) Date: Thu, 20 Jun 2019 19:58:18 +1000 From: Matthew Bobrowski To: ltp@lists.linux.it Message-ID: <98bc3a5d9591387964b913c497f930a11ea4f7a8.1561018312.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, SPF_HELO_NONE,SPF_NONE autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: jack@suse.cz Subject: [LTP] [PATCH v5 2/4] syscalls/fanotify14: new test to validate FAN_REPORT_FID interface return values 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" A newly defined test file has been introduced to validate that the fanotify interface returns the correct error values upon specifying invalid flags and masks in conjunction with FAN_REPORT_FID. A new line entry within runtest/syscalls for this new test file. Signed-off-by: Matthew Bobrowski Reviewed-by: Amir Goldstein --- runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + testcases/kernel/syscalls/fanotify/fanotify.h | 25 ++++ testcases/kernel/syscalls/fanotify/fanotify14.c | 176 ++++++++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify14.c diff --git a/runtest/syscalls b/runtest/syscalls index e682f5087..56f84824a 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -535,6 +535,7 @@ fanotify10 fanotify10 fanotify11 fanotify11 fanotify12 fanotify12 fanotify13 fanotify13 +fanotify14 fanotify14 ioperm01 ioperm01 ioperm02 ioperm02 diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore index 16bdd99e5..bf389c96a 100644 --- a/testcases/kernel/syscalls/fanotify/.gitignore +++ b/testcases/kernel/syscalls/fanotify/.gitignore @@ -11,4 +11,5 @@ /fanotify11 /fanotify12 /fanotify13 +/fanotify14 /fanotify_child diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index a5ac14acb..f9803c1cc 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -69,6 +69,31 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #ifndef FAN_MARK_FILESYSTEM #define FAN_MARK_FILESYSTEM 0x00000100 #endif +/* New dirent event masks */ +#ifndef FAN_ATTRIB +#define FAN_ATTRIB 0x00000004 +#endif +#ifndef FAN_MOVED_FROM +#define FAN_MOVED_FROM 0x00000040 +#endif +#ifndef FAN_MOVED_TO +#define FAN_MOVED_TO 0x00000080 +#endif +#ifndef FAN_CREATE +#define FAN_CREATE 0x00000100 +#endif +#ifndef FAN_DELETE +#define FAN_DELETE 0x00000200 +#endif +#ifndef FAN_DELETE_SELF +#define FAN_DELETE_SELF 0x00000400 +#endif +#ifndef FAN_MOVE_SELF +#define FAN_MOVE_SELF 0x00000800 +#endif +#ifndef FAN_MOVE +#define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) +#endif #ifndef FAN_OPEN_EXEC #define FAN_OPEN_EXEC 0x00001000 #endif diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c new file mode 100644 index 000000000..8f502115a --- /dev/null +++ b/testcases/kernel/syscalls/fanotify/fanotify14.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved. + * + * Started by Matthew Bobrowski + * + * DESCRIPTION + * This test file has been designed to ensure that the fanotify + * system calls fanotify_init(2) and fanotify_mark(2) return the + * correct error code to the calling process when an invalid flag or + * mask value has been specified in conjunction with FAN_REPORT_FID. + */ +#define _GNU_SOURCE +#include "tst_test.h" +#include "fanotify.h" + +#include + +#if defined(HAVE_SYS_FANOTIFY_H) +#include + +#define MNTPOINT "mntpoint" +#define FILE1 MNTPOINT"/file1" + +/* + * List of inode events that are only available when notification group is + * set to report fid. + */ +#define INODE_EVENTS (FAN_ATTRIB | FAN_CREATE | FAN_DELETE | FAN_MOVE | \ + FAN_DELETE_SELF | FAN_MOVE_SELF) + +static int fanotify_fd; + +/* + * Each test case has been designed in a manner whereby the values defined + * within should result in the interface to return an error to the calling + * process. + */ +static struct test_case_t { + unsigned int init_flags; + unsigned int mark_flags; + unsigned long long mask; +} test_cases[] = { + { + FAN_CLASS_CONTENT | FAN_REPORT_FID, 0, 0 + }, + { + FAN_CLASS_PRE_CONTENT | FAN_REPORT_FID, 0, 0 + }, + { + FAN_CLASS_NOTIF, 0, INODE_EVENTS + }, + { + FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS + } +}; + +static void do_test(unsigned int number) +{ + int ret; + struct test_case_t *tc = &test_cases[number]; + + fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY); + if (fanotify_fd < 0) { + /* + * EINVAL is to be returned to the calling process when + * an invalid notification class is specified in + * conjunction with FAN_REPORT_FID. + */ + if (errno == EINVAL) { + tst_res(TPASS, + "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) " + "failed with error EINVAL as expected", + fanotify_fd, + tc->init_flags); + return; + } + tst_brk(TBROK | TERRNO, + "fanotify_fd=%d, fanotify_init(%x, O_RDONLY) failed", + fanotify_fd, + tc->init_flags); + } + + /* + * A test case with a mask set to zero indicate that they've been + * specifically designed to test and fail on the fanotify_init() + * system call. + */ + if (tc->mask == 0) { + tst_res(TFAIL, + "fanotify_fd=%d fanotify_init(%x, O_RDONLY) " + "unexpectedly succeeded when tests with mask 0 are" + "expected to fail when calling fanotify_init()", + fanotify_fd, + tc->init_flags); + goto out; + } + + ret = fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags, + tc->mask, AT_FDCWD, FILE1); + if (ret < 0) { + /* + * EINVAL is to be returned to the calling process when + * attempting to use INODE_EVENTS without FAN_REPORT_FID + * specified on the notification group, or using + * INODE_EVENTS with mark type FAN_MARK_MOUNT. + */ + if (errno == EINVAL) { + tst_res(TPASS, + "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, " + "%llx, AT_FDCWD, %s) failed with error EINVAL " + "as expected", + ret, + fanotify_fd, + tc->mark_flags, + tc->mask, + FILE1); + goto out; + } + tst_brk(TBROK | TERRNO, + "ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, " + "AT_FDCWD, %s) failed", + ret, + fanotify_fd, + tc->mark_flags, + tc->mask, + FILE1); + } + + tst_res(TFAIL, + "fanotify_fd=%d, ret=%d, fanotify_init(%x, O_RDONLY) and " + "fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) did " + "not return any errors as expected", + fanotify_fd, + ret, + tc->init_flags, + fanotify_fd, + tc->mark_flags, + tc->mask, + FILE1); +out: + SAFE_CLOSE(fanotify_fd); +} + +static void do_setup(void) +{ + int fd; + + /* Check for kernel fanotify support */ + fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY); + SAFE_CLOSE(fd); + + /* Create temporary test file to place marks on */ + SAFE_FILE_PRINTF(FILE1, "0"); +} + +static void do_cleanup(void) +{ + if (fanotify_fd > 0) + SAFE_CLOSE(fanotify_fd); +} + +static struct tst_test test = { + .needs_root = 1, + .test = do_test, + .tcnt = ARRAY_SIZE(test_cases), + .setup = do_setup, + .cleanup = do_cleanup, + .mount_device = 1, + .mntpoint = MNTPOINT, + .all_filesystems = 1 +}; + +#else + TST_TEST_TCONF("System does not have required fanotify support") +#endif