From patchwork Mon Oct 8 18:14:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 10631621 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 34A15933 for ; Mon, 8 Oct 2018 23:01:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2705F29CC8 for ; Mon, 8 Oct 2018 23:01:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2542329CE0; Mon, 8 Oct 2018 23:01:02 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, 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 7505729C00 for ; Mon, 8 Oct 2018 23:01:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725782AbeJIGPC (ORCPT ); Tue, 9 Oct 2018 02:15:02 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:42652 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725759AbeJIGPC (ORCPT ); Tue, 9 Oct 2018 02:15:02 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w98IEHCl119949; Mon, 8 Oct 2018 18:15:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=pTM68+1wDHl0HgOXXvQLBt6dVENRmSuTbvxnItqzRmQ=; b=UWUIOozl9ELkfWtVbiIjYjs0hC/cq/av4chiipaFtqw44blltAabOPeqxh9JKN96VCx1 Ne+yqd0JbwpGf2oosaeXlIgSGLSJ61YjAwJ+bQt8wAbTUyFvC6R9wlgTMCiD5zlQJT6g x1KxKhtvN16DdFkp/KTv0ZkCwLoTlWYqqh3M2h/O63PxyW9TmlgLxlBO5D3UxgKwC4q5 N/NgioHPODrUiY4NbtIqt4oKgDKQXACkEYaAgFehmQFO/x4LIWoFX21gWW24J/TvnTJO QvFhz7wlz02kez+Uu8j4eRjy/MTz3CPVBoMUoZoegtCN+Bk7PzIG6o4VXvri1DInV64F fA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2mxnpqrb0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 08 Oct 2018 18:15:19 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w98IFIkI001455 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Oct 2018 18:15:18 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w98IFIhf016742; Mon, 8 Oct 2018 18:15:18 GMT Received: from tpasj.localdomain (/183.90.36.31) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 08 Oct 2018 18:15:18 +0000 From: Anand Jain To: fstests@vger.kernel.org Cc: linux-btrfs@vger.kernel.org Subject: [PATCH v2] fstests: btrfs verify hardening agaist duplicate fsid Date: Tue, 9 Oct 2018 02:14:52 +0800 Message-Id: <1539022492-3449-1-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538383475-2532-1-git-send-email-anand.jain@oracle.com> References: <1538383475-2532-1-git-send-email-anand.jain@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9040 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=13 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-1807170000 definitions=main-1810080171 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We have a known bug in btrfs, that we let the device path be changed after the device has been mounted. So using this loop hole the new copied device would appears as if its mounted immediately after its been copied. So this test case reproduces this issue. For example: Initially.. /dev/mmcblk0p4 is mounted as / lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT mmcblk0 179:0 0 29.2G 0 disk |-mmcblk0p4 179:4 0 4G 0 part / |-mmcblk0p2 179:2 0 500M 0 part /boot |-mmcblk0p3 179:3 0 256M 0 part [SWAP] `-mmcblk0p1 179:1 0 256M 0 part /boot/efi btrfs fi show Label: none uuid: 07892354-ddaa-4443-90ea-f76a06accaba Total devices 1 FS bytes used 1.40GiB devid 1 size 4.00GiB used 3.00GiB path /dev/mmcblk0p4 Copy mmcblk0 to sda dd if=/dev/mmcblk0 of=/dev/sda And immediately after the copy completes the change in the device superblock is notified which the automount scans using btrfs device scan and the new device sda becomes the mounted root device. lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 1 14.9G 0 disk |-sda4 8:4 1 4G 0 part / |-sda2 8:2 1 500M 0 part |-sda3 8:3 1 256M 0 part `-sda1 8:1 1 256M 0 part mmcblk0 179:0 0 29.2G 0 disk |-mmcblk0p4 179:4 0 4G 0 part |-mmcblk0p2 179:2 0 500M 0 part /boot |-mmcblk0p3 179:3 0 256M 0 part [SWAP] `-mmcblk0p1 179:1 0 256M 0 part /boot/efi btrfs fi show / Label: none uuid: 07892354-ddaa-4443-90ea-f76a06accaba Total devices 1 FS bytes used 1.40GiB devid 1 size 4.00GiB used 3.00GiB path /dev/sda4 The bug is quite nasty that you can't either unmount /dev/sda4 or /dev/mmcblk0p4. And the problem does not get solved until you take the sda out of the system on to another system to change its fsid using the 'btrfstune -u' command. Signed-off-by: Anand Jain --- tests/btrfs/173 | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/173.out | 6 ++++ tests/btrfs/group | 1 + 3 files changed, 95 insertions(+) create mode 100755 tests/btrfs/173 create mode 100644 tests/btrfs/173.out diff --git a/tests/btrfs/173 b/tests/btrfs/173 new file mode 100755 index 000000000000..b466ae921e19 --- /dev/null +++ b/tests/btrfs/173 @@ -0,0 +1,88 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2018 Oracle. All Rights Reserved. +# +# FS QA Test 173 +# +# Fuzzy test for FS image duplication. +# Could be fixed by +# [patch] btrfs: harden agaist duplicate fsid +# +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +mnt=$TEST_DIR/$seq.mnt +_cleanup() +{ + rm -rf $mnt > /dev/null 2>&1 + 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 + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch_dev_pool 2 +_scratch_dev_pool_get 2 + +dev_foo=$(echo $SCRATCH_DEV_POOL | awk '{print $1}') +dev_bar=$(echo $SCRATCH_DEV_POOL | awk '{print $2}') + +echo dev_foo=$dev_foo >> $seqres.full +echo dev_bar=$dev_bar >> $seqres.full +echo | tee -a $seqres.full + +rm -rf $mnt > /dev/null 2>&1 +mkdir $mnt +_mkfs_dev $dev_foo +_mount $dev_foo $mnt + +check_btrfs_mount() +{ + local x=$(findmnt $mnt | grep -v TARGET | awk '{print $2}') + [[ $x == $dev_foo ]] && echo DEV_FOO + [[ $x == $dev_bar ]] && echo DEV_BAR +} + +echo MNT $(check_btrfs_mount) + +for sb_bytenr in 65536 67108864 +do + echo -n "dd status=none if=$dev_foo of=$dev_bar bs=1 "\ + "seek=$sb_bytenr skip=$sb_bytenr count=4096" >> $seqres.full + dd status=none if=$dev_foo of=$dev_bar bs=1 seek=$sb_bytenr \ + skip=$sb_bytenr count=4096 >> $seqres.full 2>&1 + echo ..:$? >> $seqres.full +done + +#Original device is mounted, scan of its clone should fail +$BTRFS_UTIL_PROG device scan $dev_bar >> $seqres.full 2>&1 +echo btrfs device scan dev_bar ...:$?| tee -a $seqres.full + +echo MNT $(check_btrfs_mount) + +#Original device scan should be successful +$BTRFS_UTIL_PROG device scan $dev_foo >> $seqres.full 2>&1 +echo btrfs device scan dev_foo ...:$?| tee -a $seqres.full + +umount $mnt > /dev/null 2>&1 +_scratch_dev_pool_put + +# success, all done +status=0 +exit diff --git a/tests/btrfs/173.out b/tests/btrfs/173.out new file mode 100644 index 000000000000..3c7e3fb4e3f7 --- /dev/null +++ b/tests/btrfs/173.out @@ -0,0 +1,6 @@ +QA output created by 173 + +MNT DEV_FOO +btrfs device scan dev_bar ...:1 +MNT DEV_FOO +btrfs device scan dev_foo ...:0 diff --git a/tests/btrfs/group b/tests/btrfs/group index 45782565c3b7..b2f1393f3e97 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -175,3 +175,4 @@ 170 auto quick snapshot 171 auto quick qgroup 172 auto quick punch +173 volume