From patchwork Tue May 1 15:39:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10374091 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 7A6C7601C7 for ; Tue, 1 May 2018 15:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66361286FB for ; Tue, 1 May 2018 15:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AC3228716; Tue, 1 May 2018 15:39:33 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY 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 AE32C286FB for ; Tue, 1 May 2018 15:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754749AbeEAPjc (ORCPT ); Tue, 1 May 2018 11:39:32 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:47420 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753851AbeEAPjb (ORCPT ); Tue, 1 May 2018 11:39:31 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w41FZenw180914; Tue, 1 May 2018 15:39:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=hBIEhK8ADLEqQjp+vqS/fkBU5s5p2SmtQMjVPD81dKo=; b=JKD63/w37z2Gwkpl9Jt6S8jSMWOsBO4ABnYb4TfTmMlTS9NsGIHrI4sdwlO76IaOSP9w /O9HdKUGBPk3sUDm/ukwwjtFW5L6l1JX+VCQXlRM0VBE6c1FExvxcf49B2y357qrQHh3 947/5c97HbJJd0V1e8n9syvWP+MyW4vo1CGiGCZc0fUV8cRfyh2zizrEKcO05jriRhdT oXJVLLLtkgpgLFRQNJ1ZH05qkcMyoOke+jkrFk9P4SmdDjLf7vPFwYQutScP4J9ZJWSJ vuXObwk8yo/RqFl9bsu/2h9ewu4fDrMIuOJi8dezAPDqE7AzZeciwVRvTwnXRjKejH/E +Q== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2130.oracle.com with ESMTP id 2hmeg5r9km-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 01 May 2018 15:39:29 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w41FdStr013011 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 May 2018 15:39:28 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w41FdRGm006360; Tue, 1 May 2018 15:39:27 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 01 May 2018 08:39:27 -0700 Subject: [PATCH 1/9] generic: test XATTR_REPLACE doesn't take the fs down From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, kanda.motohiro@gmail.com Date: Tue, 01 May 2018 08:39:26 -0700 Message-ID: <152518916637.23023.9591675479884571356.stgit@magnolia> In-Reply-To: <152518916007.23023.4793255395982876953.stgit@magnolia> References: <152518916007.23023.4793255395982876953.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8880 signatures=668698 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1805010154 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Kanda Motohiro reported that expanding a tiny xattr into a large xattr fails on XFS because we remove the tiny xattr from a shortform fork and then try to re-add it after converting the fork to extents format having not removed the ATTR_REPLACE flag. This fails because the attr is no longer present, causing a fs shutdown. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199119 Reported-by: kanda.motohiro@gmail.com Signed-off-by: Darrick J. Wong --- .gitignore | 1 + src/Makefile | 3 +- src/attr_replace_test.c | 60 +++++++++++++++++++++++++++++++++++++++++ tests/generic/706 | 68 +++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/706.out | 2 + tests/generic/group | 1 + 6 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/attr_replace_test.c create mode 100755 tests/generic/706 create mode 100644 tests/generic/706.out -- To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/.gitignore b/.gitignore index 192ca35e..af9743f9 100644 --- a/.gitignore +++ b/.gitignore @@ -53,6 +53,7 @@ /src/append_reader /src/append_writer /src/attr-list-by-handle-cursor-test +/src/attr_replace_test /src/bstat /src/bulkstat_unlink_test /src/bulkstat_unlink_test_modified diff --git a/src/Makefile b/src/Makefile index 6ca56366..c42d3bb1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -25,7 +25,8 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ renameat2 t_getcwd e4compact test-nextquota punch-alternating \ attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \ - dio-invalidate-cache stat_test t_encrypted_d_revalidate + dio-invalidate-cache stat_test t_encrypted_d_revalidate \ + attr_replace_test SUBDIRS = log-writes perf diff --git a/src/attr_replace_test.c b/src/attr_replace_test.c new file mode 100644 index 00000000..c870d165 --- /dev/null +++ b/src/attr_replace_test.c @@ -0,0 +1,60 @@ +// setattr.c by kanda.motohiro@gmail.com +// xfs extended attribute corruption bug reproducer +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define die() do { perror(""); \ +fprintf(stderr, "error=%d at line %d\n", errno, __LINE__); \ +exit(1); } while (0) + +int main(int argc, char *argv[]) +{ + int ret; + int fd; + char *path; + char *name = "user.world"; + char *value; + struct stat sbuf; + size_t size = sizeof(value); + + if (argc != 2) die(); + path = argv[1]; + + fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (fd < 0) die(); + + /* + * The value should be 3/4 the size of a fs block to ensure that we + * get to extents format. + */ + ret = fstat(fd, &sbuf); + if (ret < 0) die(); + size = sbuf.st_blksize * 3 / 4; + if (!size) die(); + value = malloc(size); + if (!value) die(); + + // First, create a small xattr. + memset(value, '0', 1); + ret = fsetxattr(fd, name, value, 1, XATTR_CREATE); + if (ret < 0) die(); + close(fd); + + fd = open(path, O_RDWR); + if (fd < 0) die(); + + // Then, replace it with bigger one, forcing short form to leaf conversion. + memset(value, '1', size); + ret = fsetxattr(fd, name, value, size, XATTR_REPLACE); + if (ret < 0) die(); + close(fd); + + return 0; +} diff --git a/tests/generic/706 b/tests/generic/706 new file mode 100755 index 00000000..9f98c3b1 --- /dev/null +++ b/tests/generic/706 @@ -0,0 +1,68 @@ +#! /bin/bash +# FS QA Test No. 706 +# +# Ensure that we can XATTR_REPLACE a tiny attr into a large attr. +# Kanda Motohiro reports that XATTR_REPLACE'ing +# a single-byte attr with a 2048-byte attr causes a fs shutdown because we +# remove the shortform attr, convert the attr fork to long format, and then +# try to re-add the attr having not cleared ATTR_REPLACE. +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# 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" + +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $testfile +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/attr + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_test_program "attr_replace_test" +_require_attrs +_require_scratch + +rm -f $seqres.full +_scratch_mkfs >>$seqres.full 2>&1 +_scratch_mount >>$seqres.full 2>&1 + +filter_attr_output() { + _filter_scratch | sed -e 's/has a [0-9]* byte value/has a NNNN byte value/g' +} + +./src/attr_replace_test $SCRATCH_MNT/hello +$ATTR_PROG -l $SCRATCH_MNT/hello | filter_attr_output + +status=0 +exit diff --git a/tests/generic/706.out b/tests/generic/706.out new file mode 100644 index 00000000..61c8419a --- /dev/null +++ b/tests/generic/706.out @@ -0,0 +1,2 @@ +QA output created by 706 +Attribute "world" has a NNNN byte value for SCRATCH_MNT/hello diff --git a/tests/generic/group b/tests/generic/group index 19be9267..54a85ea0 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -487,3 +487,4 @@ 482 auto metadata replay 483 auto quick log metadata 484 auto quick +706 auto quick attr