generic: new test to verify selinux label of whiteout inode
PATCH v3 1/1 generic: new test to verify selinux label of whiteout inode
A but on XFS cause renameat2() with flags=RENAME_WHITEOUT doesn't apply an selinux label. That's quite different with other fs (e.g. ext4, tmpfs).
---
V1 -> V2:
1) Add "whiteout" group
2) Add commit ID which fix that bug
3) Rebase to latest fstests for-next branch
V2 -> V3:
Rebase to latest fstests for-next branch again
Thanks,
Zorro
tests/generic/695 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/695.out | 2 ++ 2 files changed, 66 insertions(+) create mode 100755 tests/generic/695 create mode 100644 tests/generic/695.out
tests/generic/695 new file +64 -0
@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Red Hat, Copyright. All Rights Reserved. +# +# FS QA Test No. 695 +# +# Verify selinux label can be kept after RENAME_WHITEOUT. This is +# a regression test for: +# 70b589a37e1a ("xfs: add selinux labels to whiteout inodes") +# +. ./common/preamble +_begin_fstest auto quick rename attr whiteout + +# Import common functions. +. ./common/attr +. ./common/renameat2 + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_attrs +_require_renameat2 whiteout + +_fixed_by_kernel_commit 70b589a37e1a \ + xfs: add selinux labels to whiteout inodes + +get_selinux_label() +{ + local label + + label=`_getfattr --absolute-names -n security.selinux $@ | sed -n 's/security.selinux=\"\(.*\)\"/\1/p'` + if [ ${PIPESTATUS[0]} -ne 0 -o -z "$label" ];then + _fail "Fail to get selinux label: $label" + fi + echo $label +} + +_scratch_mkfs >> $seqres.full 2>&1 +# SELINUX_MOUNT_OPTIONS will be set in common/config if selinux is enabled +if [ -z "$SELINUX_MOUNT_OPTIONS" ]; then + _notrun "Require selinux to be enabled" +fi +# This test need to verify selinux labels in objects, so unset this selinux +# mount option +export SELINUX_MOUNT_OPTIONS="" +_scratch_mount + +touch $SCRATCH_MNT/f1 +echo "Before RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +# Expect f1 and f2 have same label after RENAME_WHITEOUT +$here/src/renameat2 -w $SCRATCH_MNT/f1 $SCRATCH_MNT/f2 +echo "After RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +label1=`get_selinux_label $SCRATCH_MNT/f1` +label2=`get_selinux_label $SCRATCH_MNT/f2` +if [ "$label1" != "$label2" ];then + echo "$label1 != $label2" +fi + +echo "Silence is golden" +# success, all done +status=0 +exit
tests/generic/695.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 695 +Silence is golden
Signature · 1 line
2.31.1
Quoted 2 lines · Zorro Lang
A but on XFS cause
renameat2()with flags=RENAME_WHITEOUT doesn't
^ bug
Quoted 50 lines
apply an selinux label. That's quite different with other fs (e.g. ext4, tmpfs).
Signed-off-by Zorro Lang <[email protected]>---
V1 -> V2:
1) Add "whiteout" group
2) Add commit ID which fix that bug
3) Rebase to latest fstests for-next branchV2 -> V3:
Rebase to latest fstests for-next branch againThanks,
Zorrotests/generic/695 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/695.out | 2 ++ 2 files changed, 66 insertions(+) create mode 100755 tests/generic/695 create mode 100644 tests/generic/695.outtests/generic/695 new file +21
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Red Hat, Copyright. All Rights Reserved. +# +# FS QA Test No. 695 +# +# Verify selinux label can be kept after RENAME_WHITEOUT. This is +# a regression test for: +# 70b589a37e1a ("xfs: add selinux labels to whiteout inodes") +# +. ./common/preamble +_begin_fstest auto quick rename attr whiteout + +# Import common functions. +. ./common/attr +. ./common/renameat2 + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_attrs
tests/generic/695 line 31
Quoted 10 lines
tests/generic/695 new file +10
-0+_require_renameat2 whiteout + +_fixed_by_kernel_commit 70b589a37e1a \ + xfs: add selinux labels to whiteout inodes + +get_selinux_label() +{ + local label + + label=`_getfattr --absolute-names -n security.selinux $@ | sed -n 's/security.selinux=\"\(.*\)\"/\1/p'`
Just curious, why `` instead of $() ? I see the latter is preferred in many articles.
Regards~
Quoted 44 lines
tests/generic/695 new file +33
-0+ if [ ${PIPESTATUS[0]} -ne 0 -o -z "$label" ];then + _fail "Fail to get selinux label: $label" + fi + echo $label +} + +_scratch_mkfs >> $seqres.full 2>&1 +# SELINUX_MOUNT_OPTIONS will be set in common/config if selinux is enabled +if [ -z "$SELINUX_MOUNT_OPTIONS" ]; then + _notrun "Require selinux to be enabled" +fi +# This test need to verify selinux labels in objects, so unset this selinux +# mount option +export SELINUX_MOUNT_OPTIONS="" +_scratch_mount + +touch $SCRATCH_MNT/f1 +echo "Before RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +# Expect f1 and f2 have same label after RENAME_WHITEOUT +$here/src/renameat2 -w $SCRATCH_MNT/f1 $SCRATCH_MNT/f2 +echo "After RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +label1=`get_selinux_label $SCRATCH_MNT/f1` +label2=`get_selinux_label $SCRATCH_MNT/f2` +if [ "$label1" != "$label2" ];then + echo "$label1 != $label2" +fi + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/695.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 695 +Silence is golden --2.31.1
Quoted 4 lines · Murphy Zhou
Quoted 2 lines · Zorro Lang
A but on XFS cause
renameat2()with flags=RENAME_WHITEOUT doesn't^ bug
Sure, will fix
Quoted 55 lines
Quoted 55 lines
apply an selinux label. That's quite different with other fs (e.g. ext4, tmpfs).
Signed-off-by Zorro Lang <[email protected]>---
V1 -> V2:
1) Add "whiteout" group
2) Add commit ID which fix that bug
3) Rebase to latest fstests for-next branchV2 -> V3:
Rebase to latest fstests for-next branch againThanks,
Zorrotests/generic/695 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/695.out | 2 ++ 2 files changed, 66 insertions(+) create mode 100755 tests/generic/695 create mode 100644 tests/generic/695.outtests/generic/695 new file +26
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Red Hat, Copyright. All Rights Reserved. +# +# FS QA Test No. 695 +# +# Verify selinux label can be kept after RENAME_WHITEOUT. This is +# a regression test for: +# 70b589a37e1a ("xfs: add selinux labels to whiteout inodes") +# +. ./common/preamble +_begin_fstest auto quick rename attr whiteout + +# Import common functions. +. ./common/attr +. ./common/renameat2 + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_attrs +_require_renameat2 whiteout + +_fixed_by_kernel_commit 70b589a37e1a \ + xfs: add selinux labels to whiteout inodes +
Quoted 8 lines
tests/generic/695 line 31
Quoted 5 lines
tests/generic/695 new file +5
-0+get_selinux_label() +{ + local label + + label=`_getfattr --absolute-names -n security.selinux $@ | sed -n 's/security.selinux=\"\(.*\)\"/\1/p'`Just curious, why `` instead of $() ? I see the latter is preferred in many articles.
Haha, nothing special reason, just get used to it, without too much thinking. I'll replace `` to $() in this case.
Thanks,
Zorro
Quoted 48 lines
Regards~
Quoted 44 lines
tests/generic/695 new file +33
-0+ if [ ${PIPESTATUS[0]} -ne 0 -o -z "$label" ];then + _fail "Fail to get selinux label: $label" + fi + echo $label +} + +_scratch_mkfs >> $seqres.full 2>&1 +# SELINUX_MOUNT_OPTIONS will be set in common/config if selinux is enabled +if [ -z "$SELINUX_MOUNT_OPTIONS" ]; then + _notrun "Require selinux to be enabled" +fi +# This test need to verify selinux labels in objects, so unset this selinux +# mount option +export SELINUX_MOUNT_OPTIONS="" +_scratch_mount + +touch $SCRATCH_MNT/f1 +echo "Before RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +# Expect f1 and f2 have same label after RENAME_WHITEOUT +$here/src/renameat2 -w $SCRATCH_MNT/f1 $SCRATCH_MNT/f2 +echo "After RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +label1=`get_selinux_label $SCRATCH_MNT/f1` +label2=`get_selinux_label $SCRATCH_MNT/f2` +if [ "$label1" != "$label2" ];then + echo "$label1 != $label2" +fi + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/695.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 695 +Silence is golden --2.31.1
PATCH v4 1/1 generic: new test to verify selinux label of whiteout inode
In reply to Murphy ZhouA bug on XFS cause renameat2() with flags=RENAME_WHITEOUT doesn't apply an selinux label. That's quite different with other fs (e.g. ext4, tmpfs).
---
V3 -> V4:
1) Fix a typo
2) replace `` with $()
V2 -> V3:
Rebase to latest fstests for-next branch again
V1 -> V2:
1) Add "whiteout" group
2) Add commit ID which fix that bug
3) Rebase to latest fstests for-next branch
Thanks,
Zorro
tests/generic/695 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/695.out | 2 ++ 2 files changed, 66 insertions(+) create mode 100755 tests/generic/695 create mode 100644 tests/generic/695.out
tests/generic/695 new file +64 -0
@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Red Hat, Copyright. All Rights Reserved. +# +# FS QA Test No. 695 +# +# Verify selinux label can be kept after RENAME_WHITEOUT. This is +# a regression test for: +# 70b589a37e1a ("xfs: add selinux labels to whiteout inodes") +# +. ./common/preamble +_begin_fstest auto quick rename attr whiteout + +# Import common functions. +. ./common/attr +. ./common/renameat2 + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_attrs +_require_renameat2 whiteout + +_fixed_by_kernel_commit 70b589a37e1a \ + xfs: add selinux labels to whiteout inodes + +get_selinux_label() +{ + local label + + label=$(_getfattr --absolute-names -n security.selinux $@ | sed -n 's/security.selinux=\"\(.*\)\"/\1/p') + if [ ${PIPESTATUS[0]} -ne 0 -o -z "$label" ];then + _fail "Fail to get selinux label: $label" + fi + echo $label +} + +_scratch_mkfs >> $seqres.full 2>&1 +# SELINUX_MOUNT_OPTIONS will be set in common/config if selinux is enabled +if [ -z "$SELINUX_MOUNT_OPTIONS" ]; then + _notrun "Require selinux to be enabled" +fi +# This test need to verify selinux labels in objects, so unset this selinux +# mount option +export SELINUX_MOUNT_OPTIONS="" +_scratch_mount + +touch $SCRATCH_MNT/f1 +echo "Before RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +# Expect f1 and f2 have same label after RENAME_WHITEOUT +$here/src/renameat2 -w $SCRATCH_MNT/f1 $SCRATCH_MNT/f2 +echo "After RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +label1=$(get_selinux_label $SCRATCH_MNT/f1) +label2=$(get_selinux_label $SCRATCH_MNT/f2) +if [ "$label1" != "$label2" ];then + echo "$label1 != $label2" +fi + +echo "Silence is golden" +# success, all done +status=0 +exit
tests/generic/695.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 695 +Silence is golden
Signature · 1 line
2.31.1
Looks good to me!
Regards~
Quoted 111 lines · Zorro Lang
A bug on XFS cause
renameat2()with flags=RENAME_WHITEOUT doesn't apply an selinux label. That's quite different with other fs (e.g. ext4, tmpfs).Signed-off-by Zorro Lang <[email protected]>---
V3 -> V4:
1) Fix a typo
2) replace `` with $()V2 -> V3:
Rebase to latest fstests for-next branch againV1 -> V2:
1) Add "whiteout" group
2) Add commit ID which fix that bug
3) Rebase to latest fstests for-next branchThanks,
Zorrotests/generic/695 | 64 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/695.out | 2 ++ 2 files changed, 66 insertions(+) create mode 100755 tests/generic/695 create mode 100644 tests/generic/695.outtests/generic/695 new file +64
-0@@ -0,0 +1,64 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Red Hat, Copyright. All Rights Reserved. +# +# FS QA Test No. 695 +# +# Verify selinux label can be kept after RENAME_WHITEOUT. This is +# a regression test for: +# 70b589a37e1a ("xfs: add selinux labels to whiteout inodes") +# +. ./common/preamble +_begin_fstest auto quick rename attr whiteout + +# Import common functions. +. ./common/attr +. ./common/renameat2 + +# real QA test starts here +_supported_fs generic +_require_scratch +_require_attrs +_require_renameat2 whiteout + +_fixed_by_kernel_commit 70b589a37e1a \ + xfs: add selinux labels to whiteout inodes + +get_selinux_label() +{ + local label + + label=$(_getfattr --absolute-names -n security.selinux $@ | sed -n 's/security.selinux=\"\(.*\)\"/\1/p') + if [ ${PIPESTATUS[0]} -ne 0 -o -z "$label" ];then + _fail "Fail to get selinux label: $label" + fi + echo $label +} + +_scratch_mkfs >> $seqres.full 2>&1 +# SELINUX_MOUNT_OPTIONS will be set in common/config if selinux is enabled +if [ -z "$SELINUX_MOUNT_OPTIONS" ]; then + _notrun "Require selinux to be enabled" +fi +# This test need to verify selinux labels in objects, so unset this selinux +# mount option +export SELINUX_MOUNT_OPTIONS="" +_scratch_mount + +touch $SCRATCH_MNT/f1 +echo "Before RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +# Expect f1 and f2 have same label after RENAME_WHITEOUT +$here/src/renameat2 -w $SCRATCH_MNT/f1 $SCRATCH_MNT/f2 +echo "After RENAME_WHITEOUT" >> $seqres.full +ls -lZ $SCRATCH_MNT >> $seqres.full 2>&1 +label1=$(get_selinux_label $SCRATCH_MNT/f1) +label2=$(get_selinux_label $SCRATCH_MNT/f2) +if [ "$label1" != "$label2" ];then + echo "$label1 != $label2" +fi + +echo "Silence is golden" +# success, all done +status=0 +exittests/generic/695.out new file +2
-1@@ -0,0 +1,2 @@ +QA output created by 695 +Silence is golden --2.31.1