From patchwork Sat Sep 8 14:24:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 967630 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=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nzAUiOnq"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 426xRL1M5gz9s2P for ; Sun, 9 Sep 2018 00:25:17 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7D3FC3E6669 for ; Sat, 8 Sep 2018 16:25:11 +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 77BF63E607A for ; Sat, 8 Sep 2018 16:25:04 +0200 (CEST) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (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 A11362001A0 for ; Sat, 8 Sep 2018 16:25:03 +0200 (CEST) Received: by mail-wr1-x443.google.com with SMTP id u12-v6so17512809wrr.4 for ; Sat, 08 Sep 2018 07:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5lCDhHlYABQcS8uVeGzpXZkYYCdHkgY+v9zZeiaSFv4=; b=nzAUiOnqhiMlALYHt5hluTFK9ldIRJDgtdfApkNb9cXQG/arKSo+hasXha6NDM+ogt Nv620ZAiWPEMaLEAQaKnfcPQPAq732w76zZQBe2QNcZQcb3lsEobm84AMb/6CHm4gcsd OpHujpokCWsPvIHFSHONGo/7LyFwKZH4uZr/1k8Pj61NQHYtbJAWhjLPvZehlIMwXHDA P+B0qG8B0d2eVoExZCRD2crqIARBtiHg+pZaRUAwlTVxqjk+vbXlHWWpc19jfb130FRx ZMt2lqoqIxv9qhDepScLAV2EALphB5XFR+W2I8IUJATIgUA35XRcNYJGL3IqFHVtSzul RW+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5lCDhHlYABQcS8uVeGzpXZkYYCdHkgY+v9zZeiaSFv4=; b=jbBOzBUqcAPKTyoLQcCm397jm2M3KE+ZEpZBiYsLN2jvXrRXaQWiFLv5xzPcWWUZ0z 1capqh7tg+7Vs8ENCbdGc4FBsu+/b3FsNR9fBh9kBOI/sCWzDg2nFIQ/455v6NGetF+P ci8bZBLhwTBrXxIEVNKfagvd/sqwq5M7X9NDAl8i6s5mcaNFdzsD2F5+GrEZIY1oTzb4 qJ/UunkU6VNXzkp3eiOx9KJzyg8BMyYuJgHreguA1G8LNOT8MpfXogMA7yEHqJ6hTtnR MYMl5DnvbqourXRykK+kSwF3HqLz0EhVbp0/rb4WgokRipwlRSeFF2H5zJkbIY6kFLnm WGng== X-Gm-Message-State: APzg51Bj/FQXJmK2Hly30mXDgRrxZCXj7rTjmniRgVXK0e+K1PmkEPbg U+OUJYh+b3xD1Mtwb38pJLA= X-Google-Smtp-Source: ANB0VdZQS+kZJWzFSm+ITSKLP4RIEPT3Zn0FK/83ZezWhNYOtYr5I26IehpqbcwUiXCZ3nz6IhsmYw== X-Received: by 2002:adf:fd12:: with SMTP id e18-v6mr9769347wrr.280.1536416703083; Sat, 08 Sep 2018 07:25:03 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.68]) by smtp.gmail.com with ESMTPSA id e13-v6sm8781826wrt.76.2018.09.08.07.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 Sep 2018 07:25:02 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Sat, 8 Sep 2018 17:24:53 +0300 Message-Id: <20180908142453.21532-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180908142453.21532-1-amir73il@gmail.com> References: <20180908142453.21532-1-amir73il@gmail.com> 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, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: Jan Kara , ltp@lists.linux.it Subject: [LTP] [PATCH] syscalls/fanotify: new test for mount ignore mask 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" This is a regression test for commit: 9bdda4e9cf2d fsnotify: fix ignore mask logic in fsnotify() Signed-off-by: Amir Goldstein --- runtest/syscalls | 1 + testcases/kernel/syscalls/fanotify/.gitignore | 1 + .../kernel/syscalls/fanotify/fanotify10.c | 248 ++++++++++++++++++ 3 files changed, 250 insertions(+) create mode 100644 testcases/kernel/syscalls/fanotify/fanotify10.c diff --git a/runtest/syscalls b/runtest/syscalls index 62fb890cd..33b8d8625 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -497,6 +497,7 @@ fanotify06 fanotify06 fanotify07 fanotify07 fanotify08 fanotify08 fanotify09 fanotify09 +fanotify10 fanotify10 ioperm01 ioperm01 ioperm02 ioperm02 diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore index ec7553995..c26f2bd27 100644 --- a/testcases/kernel/syscalls/fanotify/.gitignore +++ b/testcases/kernel/syscalls/fanotify/.gitignore @@ -7,3 +7,4 @@ /fanotify07 /fanotify08 /fanotify09 +/fanotify10 diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c new file mode 100644 index 000000000..5245eb6f8 --- /dev/null +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2014 SUSE. All Rights Reserved. + * Copyright (c) 2018 CTERA Networks. All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Further, this software is distributed without any warranty that it is + * free of the rightful claim of any third person regarding infringement + * or the like. Any license provided herein, whether implied or + * otherwise, applies only to this software file. Patent licenses, if + * any, provided herein do not apply to combinations of this program with + * other software, or any other product whatsoever. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Started by Jan Kara + * Forked from fanotify06.c by Amir Goldstein + * + * DESCRIPTION + * Check that fanotify properly merges ignore mask of a mount mark + * with a mask of an inode mark on the same group. Unlike the + * prototype test fanotify06, do not use FAN_MODIFY event for the + * test mask, because it hides the bug. + * + * This is a regression test for commit: + * + * 9bdda4e9cf2d fsnotify: fix ignore mask logic in fsnotify() + */ +#define _GNU_SOURCE +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "fanotify.h" + +#if defined(HAVE_SYS_FANOTIFY_H) +#include + +#define EVENT_MAX 1024 +/* size of the event structure, not counting name */ +#define EVENT_SIZE (sizeof (struct fanotify_event_metadata)) +/* reasonable guess as to size of 1024 events */ +#define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE) + +unsigned int fanotify_prio[] = { + FAN_CLASS_PRE_CONTENT, + FAN_CLASS_CONTENT, + FAN_CLASS_NOTIF +}; +#define FANOTIFY_PRIORITIES ARRAY_SIZE(fanotify_prio) + +#define GROUPS_PER_PRIO 3 + +#define BUF_SIZE 256 +static char fname[BUF_SIZE]; +static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO]; + +static char event_buf[EVENT_BUF_LEN]; + +#define MOUNT_NAME "mntpoint" +static int mount_created; + +static void create_fanotify_groups(void) +{ + unsigned int p, i; + int ret; + + for (p = 0; p < FANOTIFY_PRIORITIES; p++) { + for (i = 0; i < GROUPS_PER_PRIO; i++) { + fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_prio[p] | + FAN_NONBLOCK, + O_RDONLY); + + /* Add mount mark for each group */ + ret = fanotify_mark(fd_notify[p][i], + FAN_MARK_ADD, + FAN_OPEN, + AT_FDCWD, fname); + if (ret < 0) { + tst_brk(TBROK | TERRNO, + "fanotify_mark(%d, FAN_MARK_ADD | " + "FAN_MARK_MOUNT, FAN_OPEN, AT_FDCWD," + " %s) failed", fd_notify[p][i], + fname); + } + /* Add ignore mark for groups with higher priority */ + if (p == 0) + continue; + ret = fanotify_mark(fd_notify[p][i], + FAN_MARK_ADD | FAN_MARK_MOUNT | + FAN_MARK_IGNORED_MASK | + FAN_MARK_IGNORED_SURV_MODIFY, + FAN_OPEN, AT_FDCWD, fname); + if (ret < 0) { + tst_brk(TBROK | TERRNO, + "fanotify_mark(%d, FAN_MARK_ADD | " + "FAN_MARK_IGNORED_MASK | " + "FAN_MARK_IGNORED_SURV_MODIFY, " + "FAN_OPEN, AT_FDCWD, %s) failed", + fd_notify[p][i], fname); + } + } + } +} + +static void cleanup_fanotify_groups(void) +{ + unsigned int i, p; + + for (p = 0; p < FANOTIFY_PRIORITIES; p++) { + for (i = 0; i < GROUPS_PER_PRIO; i++) { + if (fd_notify[p][i] > 0) + SAFE_CLOSE(fd_notify[p][i]); + } + } +} + +static void verify_event(int group, struct fanotify_event_metadata *event) +{ + if (event->mask != FAN_OPEN) { + tst_res(TFAIL, "group %d get event: mask %llx (expected %llx) " + "pid=%u fd=%u", group, (unsigned long long)event->mask, + (unsigned long long)FAN_OPEN, + (unsigned)event->pid, event->fd); + } else if (event->pid != getpid()) { + tst_res(TFAIL, "group %d get event: mask %llx pid=%u " + "(expected %u) fd=%u", group, + (unsigned long long)event->mask, (unsigned)event->pid, + (unsigned)getpid(), event->fd); + } else { + tst_res(TPASS, "group %d get event: mask %llx pid=%u fd=%u", + group, (unsigned long long)event->mask, + (unsigned)event->pid, event->fd); + } +} + +void test01(void) +{ + int ret, fd; + unsigned int p, i; + struct fanotify_event_metadata *event; + + create_fanotify_groups(); + + /* + * generate sequence of events + */ + fd = SAFE_OPEN(fname, O_RDONLY); + SAFE_CLOSE(fd); + + /* First verify all groups without ignore mask got the event */ + for (i = 0; i < GROUPS_PER_PRIO; i++) { + ret = read(fd_notify[0][i], event_buf, EVENT_BUF_LEN); + if (ret < 0) { + if (errno == EAGAIN) { + tst_res(TFAIL, "group %d did not get " + "event", i); + } + tst_brk(TBROK | TERRNO, + "reading fanotify events failed"); + } + if (ret < (int)FAN_EVENT_METADATA_LEN) { + tst_brk(TBROK, + "short read when reading fanotify " + "events (%d < %d)", ret, + (int)EVENT_BUF_LEN); + } + event = (struct fanotify_event_metadata *)event_buf; + if (ret > (int)event->event_len) { + tst_res(TFAIL, "group %d got more than one " + "event (%d > %d)", i, ret, + event->event_len); + } else { + verify_event(i, event); + } + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); + } + for (p = 1; p < FANOTIFY_PRIORITIES; p++) { + for (i = 0; i < GROUPS_PER_PRIO; i++) { + ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN); + if (ret > 0) { + tst_res(TFAIL, "group %d got event", + p*GROUPS_PER_PRIO + i); + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); + } else if (ret == 0) { + tst_brk(TBROK, "zero length " + "read from fanotify fd"); + } else if (errno != EAGAIN) { + tst_brk(TBROK | TERRNO, + "reading fanotify events failed"); + } else { + tst_res(TPASS, "group %d got no event", + p*GROUPS_PER_PRIO + i); + } + } + } + cleanup_fanotify_groups(); +} + +static void setup(void) +{ + SAFE_MKDIR(MOUNT_NAME, 0755); + SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL); + mount_created = 1; + SAFE_CHDIR(MOUNT_NAME); + + sprintf(fname, "tfile_%d", getpid()); + SAFE_FILE_PRINTF(fname, "1"); +} + +static void cleanup(void) +{ + cleanup_fanotify_groups(); + + SAFE_CHDIR("../"); + + if (mount_created && tst_umount(MOUNT_NAME) < 0) + tst_brk(TBROK | TERRNO, "umount failed"); +} + +static struct tst_test test = { + .test_all = test01, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .needs_root = 1 +}; + +#else + TST_TEST_TCONF("system doesn't have required fanotify support"); +#endif