diff mbox

overlay: add a test for multiple redirects to the same lower dir

Message ID 1511447224-2301-1-git-send-email-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amir Goldstein Nov. 23, 2017, 2:27 p.m. UTC
Multiple redirects to the same lower dir will falsely return the
same st_ino/st_dev for two different upper dirs and will cause 'diff'
to falsely report that content of directories is the same when it is not.

This is a test for a regression introduced in kernel v4.12 by
commit 72b608f08528 ("ovl: constant st_ino/st_dev across copy up"),
but also the first xfstest to require the redirect_dir feature that
was introduced as an opt-in feature in kernel v4.10.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---

Eryu,

This test is for a "bug" that has not been acknoledges by Miklos
as a kernel bug yet. It may well fall within the jurisdiction of
fsck.overlayfs.

IMO, cp -a of upper files and dirs qualifies to the statement in
Documentation/filesystems/overlayfs.txt:
"Offline changes, when the overlay is not mounted, are allowed to either
the upper or the lower trees."

So unless Miklos objects to ever fixing this "bug"?
I suggest that we include the failing test until kernel is fixed.

Incidently, I already have patches for 'verify' feature [1], which
I intend to post after the merge window closes.
With 'verify' feature enabled this test passes.

Amir.

[1] https://github.com/amir73il/linux/commits/ovl-index-all

 tests/overlay/049     | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/overlay/049.out |   2 +
 tests/overlay/group   |   1 +
 3 files changed, 107 insertions(+)
 create mode 100755 tests/overlay/049
 create mode 100644 tests/overlay/049.out

Comments

Eryu Guan Nov. 24, 2017, 5:05 a.m. UTC | #1
On Thu, Nov 23, 2017 at 04:27:04PM +0200, Amir Goldstein wrote:
> Multiple redirects to the same lower dir will falsely return the
> same st_ino/st_dev for two different upper dirs and will cause 'diff'
> to falsely report that content of directories is the same when it is not.
> 
> This is a test for a regression introduced in kernel v4.12 by
> commit 72b608f08528 ("ovl: constant st_ino/st_dev across copy up"),
> but also the first xfstest to require the redirect_dir feature that
> was introduced as an opt-in feature in kernel v4.10.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> 
> Eryu,
> 
> This test is for a "bug" that has not been acknoledges by Miklos
> as a kernel bug yet. It may well fall within the jurisdiction of
> fsck.overlayfs.
> 
> IMO, cp -a of upper files and dirs qualifies to the statement in
> Documentation/filesystems/overlayfs.txt:
> "Offline changes, when the overlay is not mounted, are allowed to either
> the upper or the lower trees."
> 
> So unless Miklos objects to ever fixing this "bug"?
> I suggest that we include the failing test until kernel is fixed.

Thanks for the info! Then I'll wait until it's been acked as a bug.

Thanks,
Eryu
--
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
Zhang Yi Nov. 24, 2017, 7:32 a.m. UTC | #2
On 2017/11/23 22:27, Amir Goldstein Wrote:
> Multiple redirects to the same lower dir will falsely return the
> same st_ino/st_dev for two different upper dirs and will cause 'diff'
> to falsely report that content of directories is the same when it is not.
> 
> This is a test for a regression introduced in kernel v4.12 by
> commit 72b608f08528 ("ovl: constant st_ino/st_dev across copy up"),
> but also the first xfstest to require the redirect_dir feature that
> was introduced as an opt-in feature in kernel v4.10.
> 
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
> 
> Eryu,
> 
> This test is for a "bug" that has not been acknoledges by Miklos
> as a kernel bug yet. It may well fall within the jurisdiction of
> fsck.overlayfs.
> 
> IMO, cp -a of upper files and dirs qualifies to the statement in
> Documentation/filesystems/overlayfs.txt:
> "Offline changes, when the overlay is not mounted, are allowed to either
> the upper or the lower trees."
> 
Hi Amir:

I have some persional opinions.

If I understand right, I think we need to change this statement and add
some limitations. I make an analogy with Ext4 filesystem:

1) Creating lower layers and upper dirs in overlayfs before first mount
   is like mkfs.ext4 to create an image in Ext4fs. Ext4 filesystem can
   guarantee consistency in this step but overlayfs cannot, so It's better
   to hint users to check the "overlay image" through fsck.overlay after
   he finish this "image".

2) Change lower layers or upper dirs when overlayfs is offline is like
   user modify ext4 image through tune2fs/debugfs or even modify it in
   block device directly. Ext4fs also cannot guarantee everything is right
   when user modify fs image limitless(should not crash), so fsck.ext4 is
   necessary after modifing image(except fault injection). From overlayfs's
   point of view, modify "overlay image" when it's offline is okay, but it
   should pass fsck.overlay's check before next mount.

I guess most general users don't know which one the redirect xattr points to
or even what the redirect xattr is, they maybe just want to copy whole
directory in upperdir when they call "cp -a", so I think it can handled by
fsck.overlay.

Do I understand this correctly, any thoughts ?

Thanks,
Yi.

> So unless Miklos objects to ever fixing this "bug"?
> I suggest that we include the failing test until kernel is fixed.
> 
> Incidently, I already have patches for 'verify' feature [1], which
> I intend to post after the merge window closes.
> With 'verify' feature enabled this test passes.
> 
> Amir.
> 
> [1] https://github.com/amir73il/linux/commits/ovl-index-all
> 
>  tests/overlay/049     | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/overlay/049.out |   2 +
>  tests/overlay/group   |   1 +
>  3 files changed, 107 insertions(+)
>  create mode 100755 tests/overlay/049
>  create mode 100644 tests/overlay/049.out
> 
> diff --git a/tests/overlay/049 b/tests/overlay/049
> new file mode 100755
> index 0000000..701a649
> --- /dev/null
> +++ b/tests/overlay/049
> @@ -0,0 +1,104 @@
> +#! /bin/bash
> +# FS QA Test 049
> +#
> +# Test multiple redirects to the same lower dir.
> +#
> +# Multiple redirects to the same lower dir will falsely return
> +# the same st_ino/st_dev for two different upper dirs and will
> +# cause 'diff' to falsely report that content of directories
> +# is the same when it is not.
> +#
> +#-----------------------------------------------------------------------
> +# Copyright (C) 2017 CTERA Networks. All Rights Reserved.
> +# Author: Amir Goldstein <amir73il@gmail.com>
> +#
> +# 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"
> +
> +here=`pwd`
> +tmp=/tmp/$$
> +status=1	# failure is the default!
> +trap "_cleanup; exit \$status" 0 1 2 3 15
> +
> +_cleanup()
> +{
> +	cd /
> +	rm -f $tmp.*
> +}
> +
> +# Rename lower dir to create a redirected upper dir and
> +# touch lower file to create copy up with origin xattr
> +create_redirect()
> +{
> +	local redirect=$1
> +
> +	mkdir -p $lowerdir/origin
> +	touch $lowerdir/origin/file
> +
> +	_scratch_mount -o redirect_dir=on
> +	touch $SCRATCH_MNT/origin/file
> +	mv $SCRATCH_MNT/origin $SCRATCH_MNT/$redirect
> +
> +	$UMOUNT_PROG $SCRATCH_MNT
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> +
> +rm -f $seqres.full
> +
> +# real QA test starts here
> +_supported_fs overlay
> +_supported_os Linux
> +_require_scratch
> +_require_scratch_feature redirect_dir
> +
> +# remove all files from previous runs
> +_scratch_mkfs
> +
> +upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
> +lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
> +
> +# Create redirected dir with copied up file
> +create_redirect redirect1
> +# Duplicate the redirected dir and copied up file
> +cp -a $upperdir/redirect1 $upperdir/redirect2
> +
> +# Diverge the content of the two copies of file
> +# and the content of two copies of redirected dir
> +echo right >> $upperdir/redirect1/file
> +touch $upperdir/redirect1/right
> +echo wrong >> $upperdir/redirect2/file
> +touch $upperdir/redirect2/wrong
> +
> +_scratch_mount -o redirect_dir=on
> +
> +# If both copies of file/dir use the same st_dev/st_ino in overlay
> +# diff won't detect that their content differs
> +diff -q $SCRATCH_MNT/redirect1/file $SCRATCH_MNT/redirect2/file &>/dev/null && \
> +	echo "diff on files inside duplicate redirect parent doesn't know right from wrong!"
> +
> +diff -q $SCRATCH_MNT/redirect1 $SCRATCH_MNT/redirect2 &> /dev/null && \
> +	echo "diff on duplicate redirect dirs doesn't know right from wrong!"
> +
> +# success, all done
> +echo "Silence is golden"
> +status=0
> +exit
> diff --git a/tests/overlay/049.out b/tests/overlay/049.out
> new file mode 100644
> index 0000000..c69568a
> --- /dev/null
> +++ b/tests/overlay/049.out
> @@ -0,0 +1,2 @@
> +QA output created by 049
> +Silence is golden
> diff --git a/tests/overlay/group b/tests/overlay/group
> index b32c6cd..cf21750 100644
> --- a/tests/overlay/group
> +++ b/tests/overlay/group
> @@ -47,3 +47,4 @@
>  042 auto quick copyup hardlink
>  043 auto quick copyup nonsamefs
>  044 auto quick copyup hardlink nonsamefs
> +049 auto quick copyup redirect
> 

--
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
Amir Goldstein Nov. 25, 2017, 3:45 a.m. UTC | #3
On Fri, Nov 24, 2017 at 9:32 AM, zhangyi (F) <yi.zhang@huawei.com> wrote:
> On 2017/11/23 22:27, Amir Goldstein Wrote:
>> Multiple redirects to the same lower dir will falsely return the
>> same st_ino/st_dev for two different upper dirs and will cause 'diff'
>> to falsely report that content of directories is the same when it is not.
>>
>> This is a test for a regression introduced in kernel v4.12 by
>> commit 72b608f08528 ("ovl: constant st_ino/st_dev across copy up"),
>> but also the first xfstest to require the redirect_dir feature that
>> was introduced as an opt-in feature in kernel v4.10.
>>
>> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
>> ---
>>
>> Eryu,
>>
>> This test is for a "bug" that has not been acknoledges by Miklos
>> as a kernel bug yet. It may well fall within the jurisdiction of
>> fsck.overlayfs.
>>
>> IMO, cp -a of upper files and dirs qualifies to the statement in
>> Documentation/filesystems/overlayfs.txt:
>> "Offline changes, when the overlay is not mounted, are allowed to either
>> the upper or the lower trees."
>>
> Hi Amir:
>
> I have some persional opinions.
>
> If I understand right, I think we need to change this statement and add
> some limitations.

Maybe it is a good idea to clarify this statement, but that doesn't mean
that overlayfs should ignore an inconsistency when one is detected or
that it shouldn't make an effort to detect an inconsistency.

> I make an analogy with Ext4 filesystem:

I like this analogy, so I will use it to explain why the proposed kernel
fix makes sense.

>
> 1) Creating lower layers and upper dirs in overlayfs before first mount
>    is like mkfs.ext4 to create an image in Ext4fs. Ext4 filesystem can
>    guarantee consistency in this step but overlayfs cannot, so It's better
>    to hint users to check the "overlay image" through fsck.overlay after
>    he finish this "image".
>

One problem with this analogy: there is no mkfs.overlay, so users do
manually craft overlay layers today and no documentation change is
going to stop users from doing that for decades.

Another reason why it is desired to let even unprivileged users
craft layers is because it is a long outstanding goal to allow
unprivileged users to create an fs and mount it in their own
a usrens/mountns. Allowing unprivileged users to mount an fs
is supported only for a whitelist of file systems that are marked
with flag FS_USERNS_MOUNT. Overlayfs does not qualify for
that yet, but it is a much easier goal to qualify overlayfs for userns
mount than it is to qualify ext4 for userns mount and this is
desired for some use cases.


> 2) Change lower layers or upper dirs when overlayfs is offline is like
>    user modify ext4 image through tune2fs/debugfs or even modify it in
>    block device directly. Ext4fs also cannot guarantee everything is right
>    when user modify fs image limitless(should not crash), so fsck.ext4 is
>    necessary after modifing image(except fault injection). From overlayfs's
>    point of view, modify "overlay image" when it's offline is okay, but it
>    should pass fsck.overlay's check before next mount.
>

One problem with this analogy: users do have a way to manually change
overlay layers today and no documentation change is going to stop users
from doing that for decades. Because it is easy to change layers and often
does not ever require root privileges, it is not really a valid analogy to
debugfs. A user modifying ext4 with debugfs is either very smart, very stupid
very malicious or any combination of the above, but unlike modifying layers,
it cannot be an innocent user making an innocent mistake.

Therefore, it is very sensible for the kernel to check for inconsistencies.
Staying with the ext4 analogy: ext4 doesn't require that you run
e2fsck before mount, that was the situation 2-3 decades ago. Instead
ext4 will try to detect inconsistencies at runtime and return an error
(-EFSCORRUPTED) to user with a strong hint for user to run e2fsck.
Ext4 will also optionally panic or mount ro in such case.
Xfs will forcefully shut itself down in such case forcing repair.

> I guess most general users don't know which one the redirect xattr points to
> or even what the redirect xattr is, they maybe just want to copy whole
> directory in upperdir when they call "cp -a", so I think it can handled by
> fsck.overlay.
>
> Do I understand this correctly, any thoughts ?
>

I think you do understand this correctly and I think fsck.overlay is a very
much needed tool as overlayfs on-disk format is becoming less naiive,
but the only way to *make* users run fsck.overlay is for the kernel to hint
them or force them to do so.

>
>> So unless Miklos objects to ever fixing this "bug"?
>> I suggest that we include the failing test until kernel is fixed.
>>
>> Incidently, I already have patches for 'verify' feature [1], which
>> I intend to post after the merge window closes.
>> With 'verify' feature enabled this test passes.
>>
>>
>> [1] https://github.com/amir73il/linux/commits/ovl-index-all

I may have made it sound like I have a kernel fix which is an
alternative to running fsck.overlay, but this is very much not the case.
The test "passes" because kernel returns an error instead of
allowing diff to mistake two different dirs as the same.

[ Before the kernel fix:]
root@kvm-xfstests:~# diff -q /mnt/scratch/redirect1 /mnt/scratch/redirect2
[ Silence is not golden]

[ After the kernel fix:]
root@kvm-xfstests:~# diff -q /mnt/scratch/redirect1 /mnt/scratch/redirect2
[  226.143718] overlayfs: failed to verify origin
(ovl-upper/redirect2, ino=16777539, err=-116)
[  226.146100] overlayfs: suspected multiply redirected dir found
(ovl-lower/origin, upper=ovl-upper/redirect2,
index=index/00fb21008199b53994a1f94164ba995bab052f5e0a840000000000000030e947a6).
diff: /mnt/scratch/redirect2: Input/output error

If there was an official fsck.overlay tool, this warning is where kernel would
tell user: "...please run fsck.overlay"

Cheers,
Amir.
--
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
Zhang Yi Nov. 27, 2017, 2:16 a.m. UTC | #4
Thanks for your detailed explanation!
I think it's much more clear about overlayfs's duty is to detect
inconsistency and warn user to run fsck.overlay. :)

Cheers,
Yi.

On 2017/11/25 11:45, Amir Goldstein Wrote:
> On Fri, Nov 24, 2017 at 9:32 AM, zhangyi (F) <yi.zhang@huawei.com> wrote:
>> On 2017/11/23 22:27, Amir Goldstein Wrote:
>>> Multiple redirects to the same lower dir will falsely return the
>>> same st_ino/st_dev for two different upper dirs and will cause 'diff'
>>> to falsely report that content of directories is the same when it is not.
>>>
>>> This is a test for a regression introduced in kernel v4.12 by
>>> commit 72b608f08528 ("ovl: constant st_ino/st_dev across copy up"),
>>> but also the first xfstest to require the redirect_dir feature that
>>> was introduced as an opt-in feature in kernel v4.10.
>>>
>>> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
>>> ---
>>>
>>> Eryu,
>>>
>>> This test is for a "bug" that has not been acknoledges by Miklos
>>> as a kernel bug yet. It may well fall within the jurisdiction of
>>> fsck.overlayfs.
>>>
>>> IMO, cp -a of upper files and dirs qualifies to the statement in
>>> Documentation/filesystems/overlayfs.txt:
>>> "Offline changes, when the overlay is not mounted, are allowed to either
>>> the upper or the lower trees."
>>>
>> Hi Amir:
>>
>> I have some persional opinions.
>>
>> If I understand right, I think we need to change this statement and add
>> some limitations.
> 
> Maybe it is a good idea to clarify this statement, but that doesn't mean
> that overlayfs should ignore an inconsistency when one is detected or
> that it shouldn't make an effort to detect an inconsistency.
> 
>> I make an analogy with Ext4 filesystem:
> 
> I like this analogy, so I will use it to explain why the proposed kernel
> fix makes sense.
> 
>>
>> 1) Creating lower layers and upper dirs in overlayfs before first mount
>>    is like mkfs.ext4 to create an image in Ext4fs. Ext4 filesystem can
>>    guarantee consistency in this step but overlayfs cannot, so It's better
>>    to hint users to check the "overlay image" through fsck.overlay after
>>    he finish this "image".
>>
> 
> One problem with this analogy: there is no mkfs.overlay, so users do
> manually craft overlay layers today and no documentation change is
> going to stop users from doing that for decades.
> 
> Another reason why it is desired to let even unprivileged users
> craft layers is because it is a long outstanding goal to allow
> unprivileged users to create an fs and mount it in their own
> a usrens/mountns. Allowing unprivileged users to mount an fs
> is supported only for a whitelist of file systems that are marked
> with flag FS_USERNS_MOUNT. Overlayfs does not qualify for
> that yet, but it is a much easier goal to qualify overlayfs for userns
> mount than it is to qualify ext4 for userns mount and this is
> desired for some use cases.
> 
> 
>> 2) Change lower layers or upper dirs when overlayfs is offline is like
>>    user modify ext4 image through tune2fs/debugfs or even modify it in
>>    block device directly. Ext4fs also cannot guarantee everything is right
>>    when user modify fs image limitless(should not crash), so fsck.ext4 is
>>    necessary after modifing image(except fault injection). From overlayfs's
>>    point of view, modify "overlay image" when it's offline is okay, but it
>>    should pass fsck.overlay's check before next mount.
>>
> 
> One problem with this analogy: users do have a way to manually change
> overlay layers today and no documentation change is going to stop users
> from doing that for decades. Because it is easy to change layers and often
> does not ever require root privileges, it is not really a valid analogy to
> debugfs. A user modifying ext4 with debugfs is either very smart, very stupid
> very malicious or any combination of the above, but unlike modifying layers,
> it cannot be an innocent user making an innocent mistake.
> 
> Therefore, it is very sensible for the kernel to check for inconsistencies.
> Staying with the ext4 analogy: ext4 doesn't require that you run
> e2fsck before mount, that was the situation 2-3 decades ago. Instead
> ext4 will try to detect inconsistencies at runtime and return an error
> (-EFSCORRUPTED) to user with a strong hint for user to run e2fsck.
> Ext4 will also optionally panic or mount ro in such case.
> Xfs will forcefully shut itself down in such case forcing repair.
> 
>> I guess most general users don't know which one the redirect xattr points to
>> or even what the redirect xattr is, they maybe just want to copy whole
>> directory in upperdir when they call "cp -a", so I think it can handled by
>> fsck.overlay.
>>
>> Do I understand this correctly, any thoughts ?
>>
> 
> I think you do understand this correctly and I think fsck.overlay is a very
> much needed tool as overlayfs on-disk format is becoming less naiive,
> but the only way to *make* users run fsck.overlay is for the kernel to hint
> them or force them to do so.
> 
>>
>>> So unless Miklos objects to ever fixing this "bug"?
>>> I suggest that we include the failing test until kernel is fixed.
>>>
>>> Incidently, I already have patches for 'verify' feature [1], which
>>> I intend to post after the merge window closes.
>>> With 'verify' feature enabled this test passes.
>>>
>>>
>>> [1] https://github.com/amir73il/linux/commits/ovl-index-all
> 
> I may have made it sound like I have a kernel fix which is an
> alternative to running fsck.overlay, but this is very much not the case.
> The test "passes" because kernel returns an error instead of
> allowing diff to mistake two different dirs as the same.
> 
> [ Before the kernel fix:]
> root@kvm-xfstests:~# diff -q /mnt/scratch/redirect1 /mnt/scratch/redirect2
> [ Silence is not golden]
> 
> [ After the kernel fix:]
> root@kvm-xfstests:~# diff -q /mnt/scratch/redirect1 /mnt/scratch/redirect2
> [  226.143718] overlayfs: failed to verify origin
> (ovl-upper/redirect2, ino=16777539, err=-116)
> [  226.146100] overlayfs: suspected multiply redirected dir found
> (ovl-lower/origin, upper=ovl-upper/redirect2,
> index=index/00fb21008199b53994a1f94164ba995bab052f5e0a840000000000000030e947a6).
> diff: /mnt/scratch/redirect2: Input/output error
> 
> If there was an official fsck.overlay tool, this warning is where kernel would
> tell user: "...please run fsck.overlay"
> 
> Cheers,
> Amir.
> 
> .
> 

--
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 mbox

Patch

diff --git a/tests/overlay/049 b/tests/overlay/049
new file mode 100755
index 0000000..701a649
--- /dev/null
+++ b/tests/overlay/049
@@ -0,0 +1,104 @@ 
+#! /bin/bash
+# FS QA Test 049
+#
+# Test multiple redirects to the same lower dir.
+#
+# Multiple redirects to the same lower dir will falsely return
+# the same st_ino/st_dev for two different upper dirs and will
+# cause 'diff' to falsely report that content of directories
+# is the same when it is not.
+#
+#-----------------------------------------------------------------------
+# Copyright (C) 2017 CTERA Networks. All Rights Reserved.
+# Author: Amir Goldstein <amir73il@gmail.com>
+#
+# 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"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# Rename lower dir to create a redirected upper dir and
+# touch lower file to create copy up with origin xattr
+create_redirect()
+{
+	local redirect=$1
+
+	mkdir -p $lowerdir/origin
+	touch $lowerdir/origin/file
+
+	_scratch_mount -o redirect_dir=on
+	touch $SCRATCH_MNT/origin/file
+	mv $SCRATCH_MNT/origin $SCRATCH_MNT/$redirect
+
+	$UMOUNT_PROG $SCRATCH_MNT
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs overlay
+_supported_os Linux
+_require_scratch
+_require_scratch_feature redirect_dir
+
+# remove all files from previous runs
+_scratch_mkfs
+
+upperdir=$OVL_BASE_SCRATCH_MNT/$OVL_UPPER
+lowerdir=$OVL_BASE_SCRATCH_MNT/$OVL_LOWER
+
+# Create redirected dir with copied up file
+create_redirect redirect1
+# Duplicate the redirected dir and copied up file
+cp -a $upperdir/redirect1 $upperdir/redirect2
+
+# Diverge the content of the two copies of file
+# and the content of two copies of redirected dir
+echo right >> $upperdir/redirect1/file
+touch $upperdir/redirect1/right
+echo wrong >> $upperdir/redirect2/file
+touch $upperdir/redirect2/wrong
+
+_scratch_mount -o redirect_dir=on
+
+# If both copies of file/dir use the same st_dev/st_ino in overlay
+# diff won't detect that their content differs
+diff -q $SCRATCH_MNT/redirect1/file $SCRATCH_MNT/redirect2/file &>/dev/null && \
+	echo "diff on files inside duplicate redirect parent doesn't know right from wrong!"
+
+diff -q $SCRATCH_MNT/redirect1 $SCRATCH_MNT/redirect2 &> /dev/null && \
+	echo "diff on duplicate redirect dirs doesn't know right from wrong!"
+
+# success, all done
+echo "Silence is golden"
+status=0
+exit
diff --git a/tests/overlay/049.out b/tests/overlay/049.out
new file mode 100644
index 0000000..c69568a
--- /dev/null
+++ b/tests/overlay/049.out
@@ -0,0 +1,2 @@ 
+QA output created by 049
+Silence is golden
diff --git a/tests/overlay/group b/tests/overlay/group
index b32c6cd..cf21750 100644
--- a/tests/overlay/group
+++ b/tests/overlay/group
@@ -47,3 +47,4 @@ 
 042 auto quick copyup hardlink
 043 auto quick copyup nonsamefs
 044 auto quick copyup hardlink nonsamefs
+049 auto quick copyup redirect