From patchwork Thu May 3 15:22:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 908091 X-Patchwork-Delegate: chrubis@suse.cz 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 40cJmw2tJkz9s4t for ; Fri, 4 May 2018 01:22:52 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B59D73E75E0 for ; Thu, 3 May 2018 17:22:49 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id C75133E70A3 for ; Thu, 3 May 2018 17:22:47 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id 5E3BA1A00667 for ; Thu, 3 May 2018 17:22:43 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D841FAD64; Thu, 3 May 2018 15:22:41 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id B30A21E0C5F; Thu, 3 May 2018 17:22:41 +0200 (CEST) From: Jan Kara To: ltp@lists.linux.it Date: Thu, 3 May 2018 17:22:36 +0200 Message-Id: <20180503152236.17488-1-jack@suse.cz> X-Mailer: git-send-email 2.13.6 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.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-3.smtp.seeweb.it Cc: Amir Goldstein , Jan Kara Subject: [LTP] [PATCH] inotify07: Add test for kernel crash during event notification 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" When a removal of the last mark on inode / vfsmount races with a notification about new event on that object, the kernel can crash. Test for this failure. The problem was fixed by kernel commit d90a10e2444b "fsnotify: Fix fsnotify_mark_connector race". Signed-off-by: Jan Kara --- testcases/kernel/syscalls/inotify/inotify07.c | 104 ++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 testcases/kernel/syscalls/inotify/inotify07.c Resend to the new LTP list address... diff --git a/testcases/kernel/syscalls/inotify/inotify07.c b/testcases/kernel/syscalls/inotify/inotify07.c new file mode 100644 index 000000000000..d20a824f0e8d --- /dev/null +++ b/testcases/kernel/syscalls/inotify/inotify07.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2015 SUSE Linux. 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. + * + * Started by Jan Kara + * + * DESCRIPTION + * Test for inotify mark connector destruction race. + * + * Kernels prior to 4.17 have a race when the last fsnotify mark on the inode + * is being deleted while another process reports event happening on that + * inode. When the race is hit, the kernel crashes or loops. + * + * The problem has been fixed by commit: + * d90a10e2444b "fsnotify: Fix fsnotify_mark_connector race" + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tst_test.h" +#include "inotify.h" + +#if defined(HAVE_SYS_INOTIFY_H) +#include + +/* Number of test loops to run the test for */ +#define TEARDOWNS 1000000 + +static void verify_inotify(void) +{ + int inotify_fd, fd; + int wd; + pid_t pid; + int tests; + char *name = "stress_fname"; + + fd = SAFE_OPEN(name, O_CREAT | O_RDWR, 0600); + pid = SAFE_FORK(); + if (pid == 0) { + char buf[64]; + + memset(buf, 'a', sizeof(buf)); + while (1) { + SAFE_WRITE(0, fd, buf, sizeof(buf)); + SAFE_LSEEK(fd, 0, SEEK_SET); + } + /* Never reached */ + } + SAFE_CLOSE(fd); + + inotify_fd = myinotify_init1(0); + if (inotify_fd < 0) + tst_brk(TBROK | TERRNO, "inotify_init failed"); + for (tests = 0; tests < TEARDOWNS; tests++) { + wd = myinotify_add_watch(inotify_fd, name, IN_MODIFY); + if (wd < 0) + tst_brk(TBROK | TERRNO, "inotify_add_watch() failed."); + wd = myinotify_rm_watch(inotify_fd, wd); + if (wd < 0) + tst_brk(TBROK | TERRNO, "inotify_rm_watch() failed."); + } + SAFE_CLOSE(inotify_fd); + /* We survived for given time - test succeeded */ + tst_res(TPASS, "kernel survived inotify beating"); + + /* Kill the child writing to file and wait for it */ + SAFE_KILL(pid, SIGKILL); + SAFE_WAIT(NULL); +} + +static struct tst_test test = { + .timeout = 600, + .needs_tmpdir = 1, + .forks_child = 1, + .test_all = verify_inotify, +}; + +#else + TST_TEST_TCONF("system doesn't have required inotify support"); +#endif