From patchwork Wed Jul 5 12:02:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 9826437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3CF2C603B5 for ; Wed, 5 Jul 2017 12:02:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3492027F54 for ; Wed, 5 Jul 2017 12:02:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2909A284C8; Wed, 5 Jul 2017 12:02:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3D8E27F54 for ; Wed, 5 Jul 2017 12:02:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752821AbdGEMCG (ORCPT ); Wed, 5 Jul 2017 08:02:06 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33674 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547AbdGEMCE (ORCPT ); Wed, 5 Jul 2017 08:02:04 -0400 Received: by mail-wm0-f68.google.com with SMTP id j85so31975645wmj.0; Wed, 05 Jul 2017 05:01:58 -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=Ui6AsPfYZsH6QP8rLfPDFSR3dekgP6GHMYY5jzwDb7U=; b=XpbrDTV66ywJxIBvPws/3asXtd6WmAXWk5hMUCxMFR98PYEw8zyNVHj5k31THi8p1D UR51KJS2e5H+MDPzUs1bYT42DhxfL40XRTvfytBwgb3lBdbtOmI0qO+LWCYzhilMzhgC y5TksThWl48B3qRC2uStNfIfj2GuqHx6v4bVX5EyFUGP9XZlBx1Mi2j/PKo0wPyIXFz7 JgHbZSKiMeS7TycWR8Q4hxSqtoT76J7XYiV9yTpwaLlUMtRaj3hch1zFrsgwi+0MKfpG Rzfbak/omcGjkcUOnO7BNDfu/96HWLlI1QpjUigLSijFqHAnPSMlg3HvNBDsfMLvPEEE yIYw== 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=Ui6AsPfYZsH6QP8rLfPDFSR3dekgP6GHMYY5jzwDb7U=; b=YFo77b55AEVoqOUzupHfurrVga7RG9IRBwBubpV45rn7XC6cHa3kOvxW1R+/I85Ccg bCG/gVLv9H0LklQev8p1JCeUzGFpCGdcbMLSkagR1DGYluHBvdWAeXxC2x5Wui+cdcQL 9dtdvifCjZizKBE9ROOVQ93VAB9Fwx8rXlL4BvlSwY2lgePKGHcYwCL6wqOmVPuj2f/K jOma9YbGmXMgU0O4xeamPdk2PjXtcogOZkv5yYbktfjTpm31PjgNlxoz2vHUPwFUntBP MQwvdL4ELlQSeutijyByUn9kIV7Oarxud9AqMx0xwzPsrNaiATGjbkrdFxicBIvhx6vH XBAw== X-Gm-Message-State: AKS2vOy575Wu07r5DzJIFKPmUGJvPnNxzIFQryrrHKg645DnK26Y5MRu 7zIXDuMI+xIhMw== X-Received: by 10.28.191.134 with SMTP id o6mr33828373wmi.11.1499256116889; Wed, 05 Jul 2017 05:01:56 -0700 (PDT) Received: from amir-VirtualBox.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id 143sm155578wmg.9.2017.07.05.05.01.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Jul 2017 05:01:56 -0700 (PDT) From: Amir Goldstein To: Eryu Guan Cc: Miklos Szeredi , linux-unionfs@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH v3 7/7] overlay: test dropping nlink below zero Date: Wed, 5 Jul 2017 15:02:06 +0300 Message-Id: <1499256126-21866-8-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1499256126-21866-1-git-send-email-amir73il@gmail.com> References: <1499256126-21866-1-git-send-email-amir73il@gmail.com> Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP nlink of overlay inode could be dropped indefinitely by adding un-accounted lower hardlinks underneath a mounted overlay and trying to remove them. The simplest way to understand this test is this: Imagine that you have a tool (e.g. xfs_db) with which you can add hardlinks, without changing the value of nlink stored on-disk for the inode. This is exactly what this test does when it adds lower hardlinks underneath a mounted overlay. Commit 5f8415d6b87e ("ovl: persistent overlay inode nlink for indexed inodes") fixes this issue, although the issue was never exposed in any released kernel. With overlayfs indexed copy up and without the fix, the test triggers WARN_ON(inode->i_nlink == 0) in drop_link(). Signed-off-by: Amir Goldstein --- tests/overlay/034 | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/overlay/034.out | 2 + tests/overlay/group | 1 + 3 files changed, 110 insertions(+) create mode 100755 tests/overlay/034 create mode 100644 tests/overlay/034.out diff --git a/tests/overlay/034 b/tests/overlay/034 new file mode 100755 index 0000000..2b4ca73 --- /dev/null +++ b/tests/overlay/034 @@ -0,0 +1,107 @@ +#! /bin/bash +# FS QA Test 034 +# +# Test overlay nlink when adding lower hardlinks. +# +# nlink of overlay inode could be dropped indefinitely by adding +# unaccounted lower hardlinks underneath a mounted overlay and +# trying to remove them. +# +# The simplest way to understand this test is this: +# Imagine that you have a tool (e.g. xfs_db) with which you can add +# hardlinks, without changing the value of nlink stored on-disk for the +# inode. This is exactly what this test does when it adds lower hardlinks +# underneath a mounted overlay. +# +# Commit 5f8415d6b87e ("ovl: persistent overlay inode nlink for indexed +# inodes") fixes this issue, although the issue was never exposed in any +# released kernel. +# +# With overlayfs indexed copy up and without the fix, the test triggers +# WARN_ON(inode->i_nlink == 0) in drop_link(). +# +#----------------------------------------------------------------------- +# Copyright (C) 2017 CTERA Networks. All Rights Reserved. +# Author: Amir Goldstein +# +# This program is free software; you can redistribute it and/or +# modify it under the terms 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. See the +# GNU General Public License for more details. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs overlay +_supported_os Linux +_require_scratch + +# Remove all files from previous tests +_scratch_mkfs + +# Create lower hardlink +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER +mkdir -p $lowerdir +touch $lowerdir/0 +ln $lowerdir/0 $lowerdir/1 + +_scratch_mount + +# Copy up lower hardlink - overlay inode nlink 2 is copied from lower +touch $SCRATCH_MNT/0 + +# Add lower hardlinks while overlay is mounted - overlay inode nlink +# is not being updated +ln $lowerdir/0 $lowerdir/2 +ln $lowerdir/0 $lowerdir/3 + +# Unlink the 2 un-accounted lower hardlinks - overlay inode nlinks +# drops 2 and may reach 0 if the situation is not detected +rm $SCRATCH_MNT/2 +rm $SCRATCH_MNT/3 + +# Check if getting ENOENT when trying to link !I_LINKABLE with nlink 0 +ln $SCRATCH_MNT/0 $SCRATCH_MNT/4 + +# Unlink all hardlinks - if overlay inode nlink is 0, this will trigger +# WARN_ON() in drop_nlink() +rm $SCRATCH_MNT/0 +rm $SCRATCH_MNT/1 +rm $SCRATCH_MNT/4 + +# Verify that orphan index is cleaned on mount +_scratch_cycle_mount +ls $OVL_BASE_SCRATCH_MNT/$OVL_WORK/index 2>/dev/null + +echo "Silence is golden" +status=0 +exit diff --git a/tests/overlay/034.out b/tests/overlay/034.out new file mode 100644 index 0000000..4c8873c --- /dev/null +++ b/tests/overlay/034.out @@ -0,0 +1,2 @@ +QA output created by 034 +Silence is golden diff --git a/tests/overlay/group b/tests/overlay/group index 35cd5a5..b55ed0c 100644 --- a/tests/overlay/group +++ b/tests/overlay/group @@ -36,3 +36,4 @@ 031 auto quick whiteout 032 auto quick copyup hardlink 033 auto quick copyup hardlink +034 auto quick copyup hardlink