fstests.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] fstests: test restricted file access sysctls
@ 2020-05-05 20:16 Eric Sandeen
  2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-05 20:16 UTC (permalink / raw)
  To: fstests

This is a series of tests which test sysctls which restrict file
access under certain conditions:

fs.restricted_symlinks
fs.restricted_hardlinks

and

fs.restricted_fifos
fs.restricted_regular


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 1/3] fstests: add _require_sysctl helper
  2020-05-05 20:16 [PATCH 0/3] fstests: test restricted file access sysctls Eric Sandeen
@ 2020-05-05 20:17 ` Eric Sandeen
  2020-05-06 18:35   ` Bill O'Donnell
  2020-05-17 15:50   ` Eryu Guan
  2020-05-05 20:20 ` [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls Eric Sandeen
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
  2 siblings, 2 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-05 20:17 UTC (permalink / raw)
  To: fstests

New _require_sysctl test to ensure that the sysctl we wish to test is
available on the system.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/common/rc b/common/rc
index 2000bd9d..2734dbf6 100644
--- a/common/rc
+++ b/common/rc
@@ -4208,6 +4208,12 @@ _require_bsd_process_accounting()
 	$ACCTON_PROG off >> $seqres.full
 }
 
+_require_sysctl()
+{
+	name=$1
+	sysctl $name &>/dev/null || _notrun "$name sysctl unavailable"
+}
+
 init_rc
 
 ################################################################################


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-05 20:16 [PATCH 0/3] fstests: test restricted file access sysctls Eric Sandeen
  2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
@ 2020-05-05 20:20 ` Eric Sandeen
  2020-05-06 18:44   ` Bill O'Donnell
  2020-05-17 15:55   ` Eryu Guan
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
  2 siblings, 2 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-05 20:20 UTC (permalink / raw)
  To: fstests

This tests the fs.protected_symlinks and fs.protected_hardlinks
sysctls which restrict links behavior in sticky world-writable
directories as documented in the kernel at 
Documentation/admin-guide/sysctl/fs.rst

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/tests/generic/900 b/tests/generic/900
new file mode 100755
index 00000000..f0ac46ef
--- /dev/null
+++ b/tests/generic/900
@@ -0,0 +1,114 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test 900
+#
+# Test protected_symlink and protected_hardlink ioctls
+#
+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()
+{
+	rm -rf $TEST_DIR/$seq
+	sysctl -qw fs.protected_symlinks=$SYMLINK_PROTECTION
+	sysctl -qw fs.protected_hardlinks=$HARDLINK_PROTECTION
+	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 generic
+_supported_os Linux
+_require_test
+_require_sysctl fs.protected_symlinks
+_require_sysctl fs.protected_hardlinks
+_require_user fsgqa
+_require_user fsgqa2
+
+OWNER=fsgqa
+OTHER=fsgqa2
+
+# Save current system state to reset when done
+SYMLINK_PROTECTION=`sysctl -n fs.protected_symlinks`
+HARDLINK_PROTECTION=`sysctl -n fs.protected_hardlinks`
+
+test_symlink()
+{
+	ln -s $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/symlink
+	chown $OTHER.$OTHER $TEST_DIR/$seq/sticky_dir
+	chown $OWNER.$OWNER $TEST_DIR/$seq/sticky_dir/symlink
+	# If we can read the target, we followed the link
+	sudo -u $OTHER cat $TEST_DIR/$seq/sticky_dir/symlink 2>&1 \
+		 | _filter_test_dir
+	rm -f $TEST_DIR/$seq/sticky_dir/symlink
+}
+
+test_hardlink()
+{
+	chown $OWNER.$OWNER $TEST_DIR/$seq/target
+	chmod go-rw $TEST_DIR/$seq/target
+	sudo -u $OTHER \
+	    ln $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/hardlink 2>&1 \
+		| _filter_test_dir
+	test -f $TEST_DIR/$seq/sticky_dir/hardlink \
+		&& echo "successfully created hardlink"
+	rm -f $TEST_DIR/$seq/sticky_dir/hardlink
+}
+
+setup_tree()
+{
+	# Create world-writable sticky dir
+	mkdir -p $TEST_DIR/$seq/sticky_dir
+	chmod 1777 $TEST_DIR/$seq/sticky_dir
+	# And a file elsewhere that will be linked to from that sticky dir
+	mkdir -p $TEST_DIR/$seq
+	# If we can read it, we followed the link.
+	echo "successfully followed symlink" > $TEST_DIR/$seq/target
+}
+
+setup_tree
+
+# First test fs.protected_symlinks
+# With protection on, symlink follows should fail if the
+# link owner != the sticky directory owner, and the process
+# is not the link owner.
+echo "== Test symlink follow protection when"
+echo "== process != link owner and dir owner != link owner"
+sysctl -w fs.protected_symlinks=0
+test_symlink
+sysctl -w fs.protected_symlinks=1
+test_symlink
+
+echo
+
+# Now test fs.protected_hardlinks
+# With protection on, hardlink creation should fail if the
+# process does not own the target file, and the process does not have
+# read-write access to the target
+echo "== Test hardlink create protection when"
+echo "== process != target owner and process cannot read target"
+sysctl -w fs.protected_hardlinks=0
+test_hardlink
+sysctl -w fs.protected_hardlinks=1
+test_hardlink
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/900.out b/tests/generic/900.out
new file mode 100644
index 00000000..c9b26dbd
--- /dev/null
+++ b/tests/generic/900.out
@@ -0,0 +1,14 @@
+QA output created by 900
+== Test symlink follow protection when
+== process != link owner and dir owner != link owner
+fs.protected_symlinks = 0
+successfully followed symlink
+fs.protected_symlinks = 1
+cat: TEST_DIR/900/sticky_dir/symlink: Permission denied
+
+== Test hardlink create protection when
+== process != target owner and process cannot read target
+fs.protected_hardlinks = 0
+successfully created hardlink
+fs.protected_hardlinks = 1
+ln: failed to create hard link 'TEST_DIR/900/sticky_dir/hardlink' => 'TEST_DIR/900/target': Operation not permitted
diff --git a/tests/generic/group b/tests/generic/group
index 718575ba..782b0cc3 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -598,3 +598,4 @@
 594 auto quick quota
 595 auto quick encrypt
 596 auto quick
+900 auto quick perms



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH 3/3] fstests: test restricted file access sysctls
  2020-05-05 20:16 [PATCH 0/3] fstests: test restricted file access sysctls Eric Sandeen
  2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
  2020-05-05 20:20 ` [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls Eric Sandeen
@ 2020-05-05 20:21 ` Eric Sandeen
  2020-05-06 18:47   ` Bill O'Donnell
                     ` (3 more replies)
  2 siblings, 4 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-05 20:21 UTC (permalink / raw)
  To: fstests

This tests the fs.protected_regular and fs.protected_fifos
sysctls which restrict access behavior in sticky world-writable
directories as documented in the kernel at 
Documentation/admin-guide/sysctl/fs.rst

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/tests/generic/901 b/tests/generic/901
new file mode 100755
index 00000000..5906b53c
--- /dev/null
+++ b/tests/generic/901
@@ -0,0 +1,127 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
+#
+# FS QA Test 900
+#
+# Test protected_regular and protected_fifos sysctls
+#
+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()
+{
+	rm -rf $TEST_DIR/$seq
+	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
+	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION
+	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 generic
+_supported_os Linux
+_require_test
+_require_sysctl fs.protected_regular
+_require_sysctl fs.protected_fifos
+_require_user fsgqa
+_require_user fsgqa2
+
+USER1=fsgqa
+USER2=fsgqa2
+
+# Save current system state to reset when done
+REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
+FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
+
+test_access()
+{
+	FILENAME=$1
+
+	# sticky dir is world & group writable:
+	echo "= group & world writable dir"
+	chmod og+w $TEST_DIR/$seq/sticky_dir
+	# "open -f" opens O_CREAT
+	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
+		&& echo "successfully opened $FILENAME" \
+		|| echo $result | _filter_test_dir
+	# sticky dir is only group writable:
+	echo "= only group writable dir"
+	chmod o-w $TEST_DIR/$seq/sticky_dir
+	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
+		&& echo "successfully opened $FILENAME" \
+		|| echo $result | _filter_test_dir
+}
+
+setup_tree()
+{
+	# Create sticky dir owned by $USER2
+	mkdir -p $TEST_DIR/$seq
+	mkdir -p $TEST_DIR/$seq/sticky_dir
+	chmod 1777 $TEST_DIR/$seq/sticky_dir
+	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
+
+	# Create file & fifo in that dir owned by $USER1, and open
+	# normal read/write privs for world & group
+	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
+	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
+	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
+
+	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
+	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
+	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
+}
+
+setup_tree
+
+# First test fs.protected_regular
+# With protection set to 1, O_CREAT opens in a world-writable sticky
+# directory should fail if the file exists, is owned by another, and
+# file owner != dir owner
+#
+# With protection set to 2, the same goes for group-writable
+# sticky directories
+
+echo "== Test file open when owned by another and file owner != dir owner"
+sysctl -w fs.protected_regular=0
+test_access file
+sysctl -w fs.protected_regular=1
+test_access file
+sysctl -w fs.protected_regular=2
+test_access file
+
+echo
+
+# Now test fs.protected_fifos
+# With protection set to 1, O_CREAT opens in a world-writable sticky
+# directory should fail if the fifo exists, is owned by another, and
+# file owner != dir owner
+#
+# With protection set to 2, the same goes for group-writable
+# sticky directories
+echo "== Test fifo open when owned by another and fifo owner != dir owner"
+sysctl -w fs.protected_fifos=0
+test_access fifo
+sysctl -w fs.protected_fifos=1
+test_access fifo
+sysctl -w fs.protected_fifos=2
+test_access fifo
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/901.out b/tests/generic/901.out
new file mode 100644
index 00000000..af774ca5
--- /dev/null
+++ b/tests/generic/901.out
@@ -0,0 +1,34 @@
+QA output created by 901
+== Test file open when owned by another and file owner != dir owner
+fs.protected_regular = 0
+= group & world writable dir
+successfully opened file
+= only group writable dir
+successfully opened file
+fs.protected_regular = 1
+= group & world writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+= only group writable dir
+successfully opened file
+fs.protected_regular = 2
+= group & world writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+= only group writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+
+== Test fifo open when owned by another and fifo owner != dir owner
+fs.protected_fifos = 0
+= group & world writable dir
+successfully opened fifo
+= only group writable dir
+successfully opened fifo
+fs.protected_fifos = 1
+= group & world writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
+= only group writable dir
+successfully opened fifo
+fs.protected_fifos = 2
+= group & world writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
+= only group writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
diff --git a/tests/generic/group b/tests/generic/group
index 782b0cc3..d1e529d5 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -599,3 +599,4 @@
 595 auto quick encrypt
 596 auto quick
 900 auto quick perms
+901 auto quick perms



^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/3] fstests: add _require_sysctl helper
  2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
@ 2020-05-06 18:35   ` Bill O'Donnell
  2020-05-17 15:50   ` Eryu Guan
  1 sibling, 0 replies; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 18:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:17:38PM -0500, Eric Sandeen wrote:
> New _require_sysctl test to ensure that the sysctl we wish to test is
> available on the system.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---

Reviewed-by: Bill O'Donnell <billodo@redhat.com>

> 
> diff --git a/common/rc b/common/rc
> index 2000bd9d..2734dbf6 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4208,6 +4208,12 @@ _require_bsd_process_accounting()
>  	$ACCTON_PROG off >> $seqres.full
>  }
>  
> +_require_sysctl()
> +{
> +	name=$1
> +	sysctl $name &>/dev/null || _notrun "$name sysctl unavailable"
> +}
> +
>  init_rc
>  
>  ################################################################################
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-05 20:20 ` [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls Eric Sandeen
@ 2020-05-06 18:44   ` Bill O'Donnell
  2020-05-06 18:48     ` Eric Sandeen
  2020-05-17 15:55   ` Eryu Guan
  1 sibling, 1 reply; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 18:44 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:20:10PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_symlinks and fs.protected_hardlinks
> sysctls which restrict links behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/tests/generic/900 b/tests/generic/900
> new file mode 100755
> index 00000000..f0ac46ef
> --- /dev/null
> +++ b/tests/generic/900
> @@ -0,0 +1,114 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
> +#
> +# FS QA Test 900
> +#
> +# Test protected_symlink and protected_hardlink ioctls
> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_symlinks=$SYMLINK_PROTECTION
> +	sysctl -qw fs.protected_hardlinks=$HARDLINK_PROTECTION
> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_symlinks
> +_require_sysctl fs.protected_hardlinks
> +_require_user fsgqa
> +_require_user fsgqa2
> +
> +OWNER=fsgqa
> +OTHER=fsgqa2

Why fsgqa2 instead of 123456-fsgqa?
Thanks-
Bill


> +
> +# Save current system state to reset when done
> +SYMLINK_PROTECTION=`sysctl -n fs.protected_symlinks`
> +HARDLINK_PROTECTION=`sysctl -n fs.protected_hardlinks`
> +
> +test_symlink()
> +{
> +	ln -s $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/symlink
> +	chown $OTHER.$OTHER $TEST_DIR/$seq/sticky_dir
> +	chown $OWNER.$OWNER $TEST_DIR/$seq/sticky_dir/symlink
> +	# If we can read the target, we followed the link
> +	sudo -u $OTHER cat $TEST_DIR/$seq/sticky_dir/symlink 2>&1 \
> +		 | _filter_test_dir
> +	rm -f $TEST_DIR/$seq/sticky_dir/symlink
> +}
> +
> +test_hardlink()
> +{
> +	chown $OWNER.$OWNER $TEST_DIR/$seq/target
> +	chmod go-rw $TEST_DIR/$seq/target
> +	sudo -u $OTHER \
> +	    ln $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/hardlink 2>&1 \
> +		| _filter_test_dir
> +	test -f $TEST_DIR/$seq/sticky_dir/hardlink \
> +		&& echo "successfully created hardlink"
> +	rm -f $TEST_DIR/$seq/sticky_dir/hardlink
> +}
> +
> +setup_tree()
> +{
> +	# Create world-writable sticky dir
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	# And a file elsewhere that will be linked to from that sticky dir
> +	mkdir -p $TEST_DIR/$seq
> +	# If we can read it, we followed the link.
> +	echo "successfully followed symlink" > $TEST_DIR/$seq/target
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_symlinks
> +# With protection on, symlink follows should fail if the
> +# link owner != the sticky directory owner, and the process
> +# is not the link owner.
> +echo "== Test symlink follow protection when"
> +echo "== process != link owner and dir owner != link owner"
> +sysctl -w fs.protected_symlinks=0
> +test_symlink
> +sysctl -w fs.protected_symlinks=1
> +test_symlink
> +
> +echo
> +
> +# Now test fs.protected_hardlinks
> +# With protection on, hardlink creation should fail if the
> +# process does not own the target file, and the process does not have
> +# read-write access to the target
> +echo "== Test hardlink create protection when"
> +echo "== process != target owner and process cannot read target"
> +sysctl -w fs.protected_hardlinks=0
> +test_hardlink
> +sysctl -w fs.protected_hardlinks=1
> +test_hardlink
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/900.out b/tests/generic/900.out
> new file mode 100644
> index 00000000..c9b26dbd
> --- /dev/null
> +++ b/tests/generic/900.out
> @@ -0,0 +1,14 @@
> +QA output created by 900
> +== Test symlink follow protection when
> +== process != link owner and dir owner != link owner
> +fs.protected_symlinks = 0
> +successfully followed symlink
> +fs.protected_symlinks = 1
> +cat: TEST_DIR/900/sticky_dir/symlink: Permission denied
> +
> +== Test hardlink create protection when
> +== process != target owner and process cannot read target
> +fs.protected_hardlinks = 0
> +successfully created hardlink
> +fs.protected_hardlinks = 1
> +ln: failed to create hard link 'TEST_DIR/900/sticky_dir/hardlink' => 'TEST_DIR/900/target': Operation not permitted
> diff --git a/tests/generic/group b/tests/generic/group
> index 718575ba..782b0cc3 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -598,3 +598,4 @@
>  594 auto quick quota
>  595 auto quick encrypt
>  596 auto quick
> +900 auto quick perms
> 
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/3] fstests: test restricted file access sysctls
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
@ 2020-05-06 18:47   ` Bill O'Donnell
  2020-05-06 18:53   ` Bill O'Donnell
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 18:47 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:21:54PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_regular and fs.protected_fifos
> sysctls which restrict access behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/tests/generic/901 b/tests/generic/901
> new file mode 100755
> index 00000000..5906b53c
> --- /dev/null
> +++ b/tests/generic/901
> @@ -0,0 +1,127 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
> +#
> +# FS QA Test 900
> +#
> +# Test protected_regular and protected_fifos sysctls
> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
> +	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION
> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_regular
> +_require_sysctl fs.protected_fifos
> +_require_user fsgqa
> +_require_user fsgqa2
> +
> +USER1=fsgqa
> +USER2=fsgqa2

See my fsgqa2 question in previous patch. ;)
-Bill

> +
> +# Save current system state to reset when done
> +REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
> +FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
> +
> +test_access()
> +{
> +	FILENAME=$1
> +
> +	# sticky dir is world & group writable:
> +	echo "= group & world writable dir"
> +	chmod og+w $TEST_DIR/$seq/sticky_dir
> +	# "open -f" opens O_CREAT
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
> +		&& echo "successfully opened $FILENAME" \
> +		|| echo $result | _filter_test_dir
> +	# sticky dir is only group writable:
> +	echo "= only group writable dir"
> +	chmod o-w $TEST_DIR/$seq/sticky_dir
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
> +		&& echo "successfully opened $FILENAME" \
> +		|| echo $result | _filter_test_dir
> +}
> +
> +setup_tree()
> +{
> +	# Create sticky dir owned by $USER2
> +	mkdir -p $TEST_DIR/$seq
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
> +
> +	# Create file & fifo in that dir owned by $USER1, and open
> +	# normal read/write privs for world & group
> +	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
> +
> +	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_regular
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the file exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +
> +echo "== Test file open when owned by another and file owner != dir owner"
> +sysctl -w fs.protected_regular=0
> +test_access file
> +sysctl -w fs.protected_regular=1
> +test_access file
> +sysctl -w fs.protected_regular=2
> +test_access file
> +
> +echo
> +
> +# Now test fs.protected_fifos
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the fifo exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +echo "== Test fifo open when owned by another and fifo owner != dir owner"
> +sysctl -w fs.protected_fifos=0
> +test_access fifo
> +sysctl -w fs.protected_fifos=1
> +test_access fifo
> +sysctl -w fs.protected_fifos=2
> +test_access fifo
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/901.out b/tests/generic/901.out
> new file mode 100644
> index 00000000..af774ca5
> --- /dev/null
> +++ b/tests/generic/901.out
> @@ -0,0 +1,34 @@
> +QA output created by 901
> +== Test file open when owned by another and file owner != dir owner
> +fs.protected_regular = 0
> += group & world writable dir
> +successfully opened file
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> +
> +== Test fifo open when owned by another and fifo owner != dir owner
> +fs.protected_fifos = 0
> += group & world writable dir
> +successfully opened fifo
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> diff --git a/tests/generic/group b/tests/generic/group
> index 782b0cc3..d1e529d5 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -599,3 +599,4 @@
>  595 auto quick encrypt
>  596 auto quick
>  900 auto quick perms
> +901 auto quick perms
> 
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-06 18:44   ` Bill O'Donnell
@ 2020-05-06 18:48     ` Eric Sandeen
  2020-05-06 18:52       ` Bill O'Donnell
  0 siblings, 1 reply; 18+ messages in thread
From: Eric Sandeen @ 2020-05-06 18:48 UTC (permalink / raw)
  To: Bill O'Donnell; +Cc: fstests

On 5/6/20 1:44 PM, Bill O'Donnell wrote:
> On Tue, May 05, 2020 at 03:20:10PM -0500, Eric Sandeen wrote:

...

>> +OWNER=fsgqa
>> +OTHER=fsgqa2
> 
> Why fsgqa2 instead of 123456-fsgqa?
> Thanks-
> Bill

Yeah, not quite sure what to do about that.  That username is somewhat specific
to test generic/381 because it wants to test usernames starting with digits.
I hate to proliferate required users, though, so not sure what the best way
to go might be.

I could maybe/probably use root as one of the users, but didn't want to
over-complicate it with matching admin privs vs. normal user privs.

-Eric


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-06 18:48     ` Eric Sandeen
@ 2020-05-06 18:52       ` Bill O'Donnell
  0 siblings, 0 replies; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 18:52 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Wed, May 06, 2020 at 01:48:19PM -0500, Eric Sandeen wrote:
> On 5/6/20 1:44 PM, Bill O'Donnell wrote:
> > On Tue, May 05, 2020 at 03:20:10PM -0500, Eric Sandeen wrote:
> 
> ...
> 
> >> +OWNER=fsgqa
> >> +OTHER=fsgqa2
> > 
> > Why fsgqa2 instead of 123456-fsgqa?
> > Thanks-
> > Bill
> 
> Yeah, not quite sure what to do about that.  That username is somewhat specific
> to test generic/381 because it wants to test usernames starting with digits.
> I hate to proliferate required users, though, so not sure what the best way
> to go might be.
> 
> I could maybe/probably use root as one of the users, but didn't want to
> over-complicate it with matching admin privs vs. normal user privs.

Fair enough. THanks!

Reviewed-by: Bill O'Donnell <billodo@redhat.com>

> 
> -Eric
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/3] fstests: test restricted file access sysctls
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
  2020-05-06 18:47   ` Bill O'Donnell
@ 2020-05-06 18:53   ` Bill O'Donnell
  2020-05-06 19:23   ` Eric Sandeen
  2020-05-06 19:29   ` [PATCH 3/3 V2] " Eric Sandeen
  3 siblings, 0 replies; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 18:53 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:21:54PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_regular and fs.protected_fifos
> sysctls which restrict access behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---

looks good.
Reviewed-by: Bill O'Donnell <billodo@redhat.com>

> 
> diff --git a/tests/generic/901 b/tests/generic/901
> new file mode 100755
> index 00000000..5906b53c
> --- /dev/null
> +++ b/tests/generic/901
> @@ -0,0 +1,127 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
> +#
> +# FS QA Test 900
> +#
> +# Test protected_regular and protected_fifos sysctls
> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
> +	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION
> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_regular
> +_require_sysctl fs.protected_fifos
> +_require_user fsgqa
> +_require_user fsgqa2
> +
> +USER1=fsgqa
> +USER2=fsgqa2
> +
> +# Save current system state to reset when done
> +REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
> +FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
> +
> +test_access()
> +{
> +	FILENAME=$1
> +
> +	# sticky dir is world & group writable:
> +	echo "= group & world writable dir"
> +	chmod og+w $TEST_DIR/$seq/sticky_dir
> +	# "open -f" opens O_CREAT
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
> +		&& echo "successfully opened $FILENAME" \
> +		|| echo $result | _filter_test_dir
> +	# sticky dir is only group writable:
> +	echo "= only group writable dir"
> +	chmod o-w $TEST_DIR/$seq/sticky_dir
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
> +		&& echo "successfully opened $FILENAME" \
> +		|| echo $result | _filter_test_dir
> +}
> +
> +setup_tree()
> +{
> +	# Create sticky dir owned by $USER2
> +	mkdir -p $TEST_DIR/$seq
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
> +
> +	# Create file & fifo in that dir owned by $USER1, and open
> +	# normal read/write privs for world & group
> +	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
> +
> +	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_regular
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the file exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +
> +echo "== Test file open when owned by another and file owner != dir owner"
> +sysctl -w fs.protected_regular=0
> +test_access file
> +sysctl -w fs.protected_regular=1
> +test_access file
> +sysctl -w fs.protected_regular=2
> +test_access file
> +
> +echo
> +
> +# Now test fs.protected_fifos
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the fifo exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +echo "== Test fifo open when owned by another and fifo owner != dir owner"
> +sysctl -w fs.protected_fifos=0
> +test_access fifo
> +sysctl -w fs.protected_fifos=1
> +test_access fifo
> +sysctl -w fs.protected_fifos=2
> +test_access fifo
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/901.out b/tests/generic/901.out
> new file mode 100644
> index 00000000..af774ca5
> --- /dev/null
> +++ b/tests/generic/901.out
> @@ -0,0 +1,34 @@
> +QA output created by 901
> +== Test file open when owned by another and file owner != dir owner
> +fs.protected_regular = 0
> += group & world writable dir
> +successfully opened file
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> +
> +== Test fifo open when owned by another and fifo owner != dir owner
> +fs.protected_fifos = 0
> += group & world writable dir
> +successfully opened fifo
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> diff --git a/tests/generic/group b/tests/generic/group
> index 782b0cc3..d1e529d5 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -599,3 +599,4 @@
>  595 auto quick encrypt
>  596 auto quick
>  900 auto quick perms
> +901 auto quick perms
> 
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/3] fstests: test restricted file access sysctls
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
  2020-05-06 18:47   ` Bill O'Donnell
  2020-05-06 18:53   ` Bill O'Donnell
@ 2020-05-06 19:23   ` Eric Sandeen
  2020-05-06 19:29   ` [PATCH 3/3 V2] " Eric Sandeen
  3 siblings, 0 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-06 19:23 UTC (permalink / raw)
  To: fstests

On 5/5/20 3:21 PM, Eric Sandeen wrote:
> This tests the fs.protected_regular and fs.protected_fifos
> sysctls which restrict access behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Actually, I'm going to self-nak this one, sorry; this bit -

> +	# "open -f" opens O_CREAT
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1` \
> +		&& echo "successfully opened $FILENAME" \
> +		|| echo $result | _filter_test_dir

depends on xfs_io exiting nonzero on a failure and that was only recently
fixed; I'll come up with a test that's more robust and send a V2.

-Eric


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH 3/3 V2] fstests: test restricted file access sysctls
  2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
                     ` (2 preceding siblings ...)
  2020-05-06 19:23   ` Eric Sandeen
@ 2020-05-06 19:29   ` Eric Sandeen
  2020-05-06 19:42     ` Bill O'Donnell
  2020-05-17 15:57     ` Eryu Guan
  3 siblings, 2 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-06 19:29 UTC (permalink / raw)
  To: fstests; +Cc: Bill O'Donnell

This tests the fs.protected_regular and fs.protected_fifos
sysctls which restrict access behavior in sticky world-writable
directories as documented in the kernel at 
Documentation/admin-guide/sysctl/fs.rst

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2: Don't count on nonzero exit from xfs_io since that is almost
always broken and was only recently fixed and may end up broken
again... collect & check any emitted error messages instead.

diff --git a/tests/generic/901 b/tests/generic/901
new file mode 100755
index 00000000..9bb658e0
--- /dev/null
+++ b/tests/generic/901
@@ -0,0 +1,133 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.
+#
+# FS QA Test 900
+#
+# Test protected_symlink and protected_hardlink ioctls
+#
+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()
+{
+	rm -rf $TEST_DIR/$seq
+	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
+	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION
+	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 generic
+_supported_os Linux
+_require_test
+_require_sysctl fs.protected_regular
+_require_sysctl fs.protected_fifos
+_require_user fsgqa
+_require_user fsgqa2
+
+USER1=fsgqa
+USER2=fsgqa2
+
+# Save current system state to reset when done
+REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
+FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
+
+test_access()
+{
+	FILENAME=$1
+
+	# sticky dir is world & group writable:
+	echo "= group & world writable dir"
+	chmod og+w $TEST_DIR/$seq/sticky_dir
+	# "open -f" opens O_CREAT
+	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
+	if [ -z "$result" ]; then
+		echo "successfully opened $FILENAME"
+	else
+		echo $result | _filter_test_dir
+	fi
+	# sticky dir is only group writable:
+	echo "= only group writable dir"
+	chmod o-w $TEST_DIR/$seq/sticky_dir
+	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
+	if [ -z "$result" ]; then
+		echo "successfully opened $FILENAME"
+	else
+		echo $result | _filter_test_dir
+	fi
+}
+
+setup_tree()
+{
+	# Create sticky dir owned by $USER2
+	mkdir -p $TEST_DIR/$seq
+	mkdir -p $TEST_DIR/$seq/sticky_dir
+	chmod 1777 $TEST_DIR/$seq/sticky_dir
+	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
+
+	# Create file & fifo in that dir owned by $USER1, and open
+	# normal read/write privs for world & group
+	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
+	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
+	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
+
+	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
+	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
+	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
+}
+
+setup_tree
+
+# First test fs.protected_regular
+# With protection set to 1, O_CREAT opens in a world-writable sticky
+# directory should fail if the file exists, is owned by another, and
+# file owner != dir owner
+#
+# With protection set to 2, the same goes for group-writable
+# sticky directories
+
+echo "== Test file open when owned by another and file owner != dir owner"
+sysctl -w fs.protected_regular=0
+test_access file
+sysctl -w fs.protected_regular=1
+test_access file
+sysctl -w fs.protected_regular=2
+test_access file
+
+echo
+
+# Now test fs.protected_fifos
+# With protection set to 1, O_CREAT opens in a world-writable sticky
+# directory should fail if the fifo exists, is owned by another, and
+# file owner != dir owner
+#
+# With protection set to 2, the same goes for group-writable
+# sticky directories
+echo "== Test fifo open when owned by another and fifo owner != dir owner"
+sysctl -w fs.protected_fifos=0
+test_access fifo
+sysctl -w fs.protected_fifos=1
+test_access fifo
+sysctl -w fs.protected_fifos=2
+test_access fifo
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/901.out b/tests/generic/901.out
new file mode 100644
index 00000000..af774ca5
--- /dev/null
+++ b/tests/generic/901.out
@@ -0,0 +1,34 @@
+QA output created by 901
+== Test file open when owned by another and file owner != dir owner
+fs.protected_regular = 0
+= group & world writable dir
+successfully opened file
+= only group writable dir
+successfully opened file
+fs.protected_regular = 1
+= group & world writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+= only group writable dir
+successfully opened file
+fs.protected_regular = 2
+= group & world writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+= only group writable dir
+TEST_DIR/901/sticky_dir/file: Permission denied
+
+== Test fifo open when owned by another and fifo owner != dir owner
+fs.protected_fifos = 0
+= group & world writable dir
+successfully opened fifo
+= only group writable dir
+successfully opened fifo
+fs.protected_fifos = 1
+= group & world writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
+= only group writable dir
+successfully opened fifo
+fs.protected_fifos = 2
+= group & world writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
+= only group writable dir
+TEST_DIR/901/sticky_dir/fifo: Permission denied
diff --git a/tests/generic/group b/tests/generic/group
index 782b0cc3..d1e529d5 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -599,3 +599,4 @@
 595 auto quick encrypt
 596 auto quick
 900 auto quick perms
+901 auto quick perms


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/3 V2] fstests: test restricted file access sysctls
  2020-05-06 19:29   ` [PATCH 3/3 V2] " Eric Sandeen
@ 2020-05-06 19:42     ` Bill O'Donnell
  2020-05-17 15:57     ` Eryu Guan
  1 sibling, 0 replies; 18+ messages in thread
From: Bill O'Donnell @ 2020-05-06 19:42 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Wed, May 06, 2020 at 02:29:42PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_regular and fs.protected_fifos
> sysctls which restrict access behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> V2: Don't count on nonzero exit from xfs_io since that is almost
> always broken and was only recently fixed and may end up broken
> again... collect & check any emitted error messages instead.
> 
> diff --git a/tests/generic/901 b/tests/generic/901
> new file mode 100755
> index 00000000..9bb658e0
> --- /dev/null
> +++ b/tests/generic/901
> @@ -0,0 +1,133 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.
> +#
> +# FS QA Test 900
> +#
> +# Test protected_symlink and protected_hardlink ioctls
> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
> +	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION
> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_regular
> +_require_sysctl fs.protected_fifos
> +_require_user fsgqa
> +_require_user fsgqa2
> +
> +USER1=fsgqa
> +USER2=fsgqa2
> +
> +# Save current system state to reset when done
> +REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
> +FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
> +
> +test_access()
> +{
> +	FILENAME=$1
> +
> +	# sticky dir is world & group writable:
> +	echo "= group & world writable dir"
> +	chmod og+w $TEST_DIR/$seq/sticky_dir
> +	# "open -f" opens O_CREAT
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
> +	if [ -z "$result" ]; then
> +		echo "successfully opened $FILENAME"
> +	else
> +		echo $result | _filter_test_dir
> +	fi

Makes sense, thanks.
Reviewed-by: Bill O'Donnell <billodo@redhat.com>


> +	# sticky dir is only group writable:
> +	echo "= only group writable dir"
> +	chmod o-w $TEST_DIR/$seq/sticky_dir
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
> +	if [ -z "$result" ]; then
> +		echo "successfully opened $FILENAME"
> +	else
> +		echo $result | _filter_test_dir
> +	fi
> +}
> +
> +setup_tree()
> +{
> +	# Create sticky dir owned by $USER2
> +	mkdir -p $TEST_DIR/$seq
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
> +
> +	# Create file & fifo in that dir owned by $USER1, and open
> +	# normal read/write privs for world & group
> +	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
> +
> +	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_regular
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the file exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +
> +echo "== Test file open when owned by another and file owner != dir owner"
> +sysctl -w fs.protected_regular=0
> +test_access file
> +sysctl -w fs.protected_regular=1
> +test_access file
> +sysctl -w fs.protected_regular=2
> +test_access file
> +
> +echo
> +
> +# Now test fs.protected_fifos
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the fifo exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +echo "== Test fifo open when owned by another and fifo owner != dir owner"
> +sysctl -w fs.protected_fifos=0
> +test_access fifo
> +sysctl -w fs.protected_fifos=1
> +test_access fifo
> +sysctl -w fs.protected_fifos=2
> +test_access fifo
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/901.out b/tests/generic/901.out
> new file mode 100644
> index 00000000..af774ca5
> --- /dev/null
> +++ b/tests/generic/901.out
> @@ -0,0 +1,34 @@
> +QA output created by 901
> +== Test file open when owned by another and file owner != dir owner
> +fs.protected_regular = 0
> += group & world writable dir
> +successfully opened file
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> +
> +== Test fifo open when owned by another and fifo owner != dir owner
> +fs.protected_fifos = 0
> += group & world writable dir
> +successfully opened fifo
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> diff --git a/tests/generic/group b/tests/generic/group
> index 782b0cc3..d1e529d5 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -599,3 +599,4 @@
>  595 auto quick encrypt
>  596 auto quick
>  900 auto quick perms
> +901 auto quick perms
> 


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 1/3] fstests: add _require_sysctl helper
  2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
  2020-05-06 18:35   ` Bill O'Donnell
@ 2020-05-17 15:50   ` Eryu Guan
  1 sibling, 0 replies; 18+ messages in thread
From: Eryu Guan @ 2020-05-17 15:50 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:17:38PM -0500, Eric Sandeen wrote:
> New _require_sysctl test to ensure that the sysctl we wish to test is
> available on the system.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/common/rc b/common/rc
> index 2000bd9d..2734dbf6 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4208,6 +4208,12 @@ _require_bsd_process_accounting()
>  	$ACCTON_PROG off >> $seqres.full
>  }
>  
> +_require_sysctl()

IMHO, this name seems a bit confusing, it looks like it requires the
sysctl command itself. How about _require_sysctl_entry ?

> +{
> +	name=$1

Declare local var with 'local'.

> +	sysctl $name &>/dev/null || _notrun "$name sysctl unavailable"
> +}

And I think this patch could be folded into the first test that takes
use of it, i.e. patch 2.

Thanks,
Eryu

> +
>  init_rc
>  
>  ################################################################################

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-05 20:20 ` [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls Eric Sandeen
  2020-05-06 18:44   ` Bill O'Donnell
@ 2020-05-17 15:55   ` Eryu Guan
  2020-05-18 14:42     ` Eric Sandeen
  1 sibling, 1 reply; 18+ messages in thread
From: Eryu Guan @ 2020-05-17 15:55 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests

On Tue, May 05, 2020 at 03:20:10PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_symlinks and fs.protected_hardlinks
> sysctls which restrict links behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/tests/generic/900 b/tests/generic/900
> new file mode 100755
> index 00000000..f0ac46ef
> --- /dev/null
> +++ b/tests/generic/900
> @@ -0,0 +1,114 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
> +#
> +# FS QA Test 900
> +#
> +# Test protected_symlink and protected_hardlink ioctls
> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_symlinks=$SYMLINK_PROTECTION
> +	sysctl -qw fs.protected_hardlinks=$HARDLINK_PROTECTION

Restore the sysctl only if "SYMLINK_PROTECTION" and
"HARDLINK_PROTECTION" are set.

> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_symlinks
> +_require_sysctl fs.protected_hardlinks
> +_require_user fsgqa
> +_require_user fsgqa2

New user :) update README as well?

> +
> +OWNER=fsgqa
> +OTHER=fsgqa2
> +
> +# Save current system state to reset when done
> +SYMLINK_PROTECTION=`sysctl -n fs.protected_symlinks`
> +HARDLINK_PROTECTION=`sysctl -n fs.protected_hardlinks`
> +
> +test_symlink()
> +{
> +	ln -s $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/symlink
> +	chown $OTHER.$OTHER $TEST_DIR/$seq/sticky_dir
> +	chown $OWNER.$OWNER $TEST_DIR/$seq/sticky_dir/symlink
> +	# If we can read the target, we followed the link
> +	sudo -u $OTHER cat $TEST_DIR/$seq/sticky_dir/symlink 2>&1 \

Use _user_do instead of sudo?

> +		 | _filter_test_dir
> +	rm -f $TEST_DIR/$seq/sticky_dir/symlink
> +}
> +
> +test_hardlink()
> +{
> +	chown $OWNER.$OWNER $TEST_DIR/$seq/target
> +	chmod go-rw $TEST_DIR/$seq/target
> +	sudo -u $OTHER \
> +	    ln $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/hardlink 2>&1 \
> +		| _filter_test_dir

Same here.

Thanks,
Eryu

> +	test -f $TEST_DIR/$seq/sticky_dir/hardlink \
> +		&& echo "successfully created hardlink"
> +	rm -f $TEST_DIR/$seq/sticky_dir/hardlink
> +}
> +
> +setup_tree()
> +{
> +	# Create world-writable sticky dir
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	# And a file elsewhere that will be linked to from that sticky dir
> +	mkdir -p $TEST_DIR/$seq
> +	# If we can read it, we followed the link.
> +	echo "successfully followed symlink" > $TEST_DIR/$seq/target
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_symlinks
> +# With protection on, symlink follows should fail if the
> +# link owner != the sticky directory owner, and the process
> +# is not the link owner.
> +echo "== Test symlink follow protection when"
> +echo "== process != link owner and dir owner != link owner"
> +sysctl -w fs.protected_symlinks=0
> +test_symlink
> +sysctl -w fs.protected_symlinks=1
> +test_symlink
> +
> +echo
> +
> +# Now test fs.protected_hardlinks
> +# With protection on, hardlink creation should fail if the
> +# process does not own the target file, and the process does not have
> +# read-write access to the target
> +echo "== Test hardlink create protection when"
> +echo "== process != target owner and process cannot read target"
> +sysctl -w fs.protected_hardlinks=0
> +test_hardlink
> +sysctl -w fs.protected_hardlinks=1
> +test_hardlink
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/900.out b/tests/generic/900.out
> new file mode 100644
> index 00000000..c9b26dbd
> --- /dev/null
> +++ b/tests/generic/900.out
> @@ -0,0 +1,14 @@
> +QA output created by 900
> +== Test symlink follow protection when
> +== process != link owner and dir owner != link owner
> +fs.protected_symlinks = 0
> +successfully followed symlink
> +fs.protected_symlinks = 1
> +cat: TEST_DIR/900/sticky_dir/symlink: Permission denied
> +
> +== Test hardlink create protection when
> +== process != target owner and process cannot read target
> +fs.protected_hardlinks = 0
> +successfully created hardlink
> +fs.protected_hardlinks = 1
> +ln: failed to create hard link 'TEST_DIR/900/sticky_dir/hardlink' => 'TEST_DIR/900/target': Operation not permitted
> diff --git a/tests/generic/group b/tests/generic/group
> index 718575ba..782b0cc3 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -598,3 +598,4 @@
>  594 auto quick quota
>  595 auto quick encrypt
>  596 auto quick
> +900 auto quick perms
> 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 3/3 V2] fstests: test restricted file access sysctls
  2020-05-06 19:29   ` [PATCH 3/3 V2] " Eric Sandeen
  2020-05-06 19:42     ` Bill O'Donnell
@ 2020-05-17 15:57     ` Eryu Guan
  1 sibling, 0 replies; 18+ messages in thread
From: Eryu Guan @ 2020-05-17 15:57 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: fstests, Bill O'Donnell

On Wed, May 06, 2020 at 02:29:42PM -0500, Eric Sandeen wrote:
> This tests the fs.protected_regular and fs.protected_fifos
> sysctls which restrict access behavior in sticky world-writable
> directories as documented in the kernel at 
> Documentation/admin-guide/sysctl/fs.rst
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> V2: Don't count on nonzero exit from xfs_io since that is almost
> always broken and was only recently fixed and may end up broken
> again... collect & check any emitted error messages instead.
> 
> diff --git a/tests/generic/901 b/tests/generic/901
> new file mode 100755
> index 00000000..9bb658e0
> --- /dev/null
> +++ b/tests/generic/901
> @@ -0,0 +1,133 @@
> +#! /bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (c) 2020 YOUR NAME HERE.  All Rights Reserved.

Copyright info is not correct :)

> +#
> +# FS QA Test 900
> +#
> +# Test protected_symlink and protected_hardlink ioctls

Stale test description?

> +#
> +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()
> +{
> +	rm -rf $TEST_DIR/$seq
> +	sysctl -qw fs.protected_regular=$REGULAR_PROTECTION
> +	sysctl -qw fs.protected_fifos=$FIFO_PROTECTION

Only restore them only if the variables are set.

Thanks,
Eryu

> +	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 generic
> +_supported_os Linux
> +_require_test
> +_require_sysctl fs.protected_regular
> +_require_sysctl fs.protected_fifos
> +_require_user fsgqa
> +_require_user fsgqa2
> +
> +USER1=fsgqa
> +USER2=fsgqa2
> +
> +# Save current system state to reset when done
> +REGULAR_PROTECTION=`sysctl -n fs.protected_regular`
> +FIFO_PROTECTION=`sysctl -n fs.protected_fifos`
> +
> +test_access()
> +{
> +	FILENAME=$1
> +
> +	# sticky dir is world & group writable:
> +	echo "= group & world writable dir"
> +	chmod og+w $TEST_DIR/$seq/sticky_dir
> +	# "open -f" opens O_CREAT
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
> +	if [ -z "$result" ]; then
> +		echo "successfully opened $FILENAME"
> +	else
> +		echo $result | _filter_test_dir
> +	fi
> +	# sticky dir is only group writable:
> +	echo "= only group writable dir"
> +	chmod o-w $TEST_DIR/$seq/sticky_dir
> +	result=`sudo -u $USER2 $XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/$FILENAME" 2>&1`
> +	if [ -z "$result" ]; then
> +		echo "successfully opened $FILENAME"
> +	else
> +		echo $result | _filter_test_dir
> +	fi
> +}
> +
> +setup_tree()
> +{
> +	# Create sticky dir owned by $USER2
> +	mkdir -p $TEST_DIR/$seq
> +	mkdir -p $TEST_DIR/$seq/sticky_dir
> +	chmod 1777 $TEST_DIR/$seq/sticky_dir
> +	chown $USER2.$USER2 $TEST_DIR/$seq/sticky_dir
> +
> +	# Create file & fifo in that dir owned by $USER1, and open
> +	# normal read/write privs for world & group
> +	$XFS_IO_PROG -c "open -f $TEST_DIR/$seq/sticky_dir/file"
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/file
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/file
> +
> +	mkfifo $TEST_DIR/$seq/sticky_dir/fifo
> +	chown $USER1.$USER1 $TEST_DIR/$seq/sticky_dir/fifo
> +	chmod o+rw $TEST_DIR/$seq/sticky_dir/fifo
> +}
> +
> +setup_tree
> +
> +# First test fs.protected_regular
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the file exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +
> +echo "== Test file open when owned by another and file owner != dir owner"
> +sysctl -w fs.protected_regular=0
> +test_access file
> +sysctl -w fs.protected_regular=1
> +test_access file
> +sysctl -w fs.protected_regular=2
> +test_access file
> +
> +echo
> +
> +# Now test fs.protected_fifos
> +# With protection set to 1, O_CREAT opens in a world-writable sticky
> +# directory should fail if the fifo exists, is owned by another, and
> +# file owner != dir owner
> +#
> +# With protection set to 2, the same goes for group-writable
> +# sticky directories
> +echo "== Test fifo open when owned by another and fifo owner != dir owner"
> +sysctl -w fs.protected_fifos=0
> +test_access fifo
> +sysctl -w fs.protected_fifos=1
> +test_access fifo
> +sysctl -w fs.protected_fifos=2
> +test_access fifo
> +
> +# success, all done
> +status=0
> +exit
> diff --git a/tests/generic/901.out b/tests/generic/901.out
> new file mode 100644
> index 00000000..af774ca5
> --- /dev/null
> +++ b/tests/generic/901.out
> @@ -0,0 +1,34 @@
> +QA output created by 901
> +== Test file open when owned by another and file owner != dir owner
> +fs.protected_regular = 0
> += group & world writable dir
> +successfully opened file
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +successfully opened file
> +fs.protected_regular = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/file: Permission denied
> +
> +== Test fifo open when owned by another and fifo owner != dir owner
> +fs.protected_fifos = 0
> += group & world writable dir
> +successfully opened fifo
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 1
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +successfully opened fifo
> +fs.protected_fifos = 2
> += group & world writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> += only group writable dir
> +TEST_DIR/901/sticky_dir/fifo: Permission denied
> diff --git a/tests/generic/group b/tests/generic/group
> index 782b0cc3..d1e529d5 100644
> --- a/tests/generic/group
> +++ b/tests/generic/group
> @@ -599,3 +599,4 @@
>  595 auto quick encrypt
>  596 auto quick
>  900 auto quick perms
> +901 auto quick perms

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-17 15:55   ` Eryu Guan
@ 2020-05-18 14:42     ` Eric Sandeen
  2020-05-18 14:45       ` Eric Sandeen
  0 siblings, 1 reply; 18+ messages in thread
From: Eric Sandeen @ 2020-05-18 14:42 UTC (permalink / raw)
  To: Eryu Guan, Eric Sandeen; +Cc: fstests


On 5/17/20 10:55 AM, Eryu Guan wrote:
> On Tue, May 05, 2020 at 03:20:10PM -0500, Eric Sandeen wrote:
>> This tests the fs.protected_symlinks and fs.protected_hardlinks
>> sysctls which restrict links behavior in sticky world-writable
>> directories as documented in the kernel at 
>> Documentation/admin-guide/sysctl/fs.rst
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
>> ---
>>
>> diff --git a/tests/generic/900 b/tests/generic/900
>> new file mode 100755
>> index 00000000..f0ac46ef
>> --- /dev/null
>> +++ b/tests/generic/900
>> @@ -0,0 +1,114 @@
>> +#! /bin/bash
>> +# SPDX-License-Identifier: GPL-2.0
>> +# Copyright (c) 2020 Red Hat, Inc.  All Rights Reserved.
>> +#
>> +# FS QA Test 900
>> +#
>> +# Test protected_symlink and protected_hardlink ioctls
>> +#
>> +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()
>> +{
>> +	rm -rf $TEST_DIR/$seq
>> +	sysctl -qw fs.protected_symlinks=$SYMLINK_PROTECTION
>> +	sysctl -qw fs.protected_hardlinks=$HARDLINK_PROTECTION
> 
> Restore the sysctl only if "SYMLINK_PROTECTION" and
> "HARDLINK_PROTECTION" are set.

thankss

>> +	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 generic
>> +_supported_os Linux
>> +_require_test
>> +_require_sysctl fs.protected_symlinks
>> +_require_sysctl fs.protected_hardlinks
>> +_require_user fsgqa
>> +_require_user fsgqa2
> 
> New user :) update README as well?

Hm, yep.

>> +
>> +OWNER=fsgqa
>> +OTHER=fsgqa2
>> +
>> +# Save current system state to reset when done
>> +SYMLINK_PROTECTION=`sysctl -n fs.protected_symlinks`
>> +HARDLINK_PROTECTION=`sysctl -n fs.protected_hardlinks`
>> +
>> +test_symlink()
>> +{
>> +	ln -s $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/symlink
>> +	chown $OTHER.$OTHER $TEST_DIR/$seq/sticky_dir
>> +	chown $OWNER.$OWNER $TEST_DIR/$seq/sticky_dir/symlink
>> +	# If we can read the target, we followed the link
>> +	sudo -u $OTHER cat $TEST_DIR/$seq/sticky_dir/symlink 2>&1 \
> 
> Use _user_do instead of sudo?

but OTHER is "fsgqa2;" _user_do uses "fsgqa" .... hrm.  I suppose I could
update _user_do to take a username, but is it worth it?
 
Maybe I should just make one of the users root, I'm just worried about accidentally
running into admin capabilities...

-Eric

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls
  2020-05-18 14:42     ` Eric Sandeen
@ 2020-05-18 14:45       ` Eric Sandeen
  0 siblings, 0 replies; 18+ messages in thread
From: Eric Sandeen @ 2020-05-18 14:45 UTC (permalink / raw)
  To: Eryu Guan, Eric Sandeen; +Cc: fstests

On 5/18/20 9:42 AM, Eric Sandeen wrote:
>>> +test_symlink()
>>> +{
>>> +	ln -s $TEST_DIR/$seq/target $TEST_DIR/$seq/sticky_dir/symlink
>>> +	chown $OTHER.$OTHER $TEST_DIR/$seq/sticky_dir
>>> +	chown $OWNER.$OWNER $TEST_DIR/$seq/sticky_dir/symlink
>>> +	# If we can read the target, we followed the link
>>> +	sudo -u $OTHER cat $TEST_DIR/$seq/sticky_dir/symlink 2>&1 \
>> Use _user_do instead of sudo?
> but OTHER is "fsgqa2;" _user_do uses "fsgqa" .... hrm.  I suppose I could
> update _user_do to take a username, but is it worth it?
>  
> Maybe I should just make one of the users root, I'm just worried about accidentally
> running into admin capabilities...

Actually I'll just re-use 123456-fsgq for OWNER, then OTHER can be fsgqa, and
I'll use _user_do.

Thanks,
-Eric

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-05-18 14:46 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-05 20:16 [PATCH 0/3] fstests: test restricted file access sysctls Eric Sandeen
2020-05-05 20:17 ` [PATCH 1/3] fstests: add _require_sysctl helper Eric Sandeen
2020-05-06 18:35   ` Bill O'Donnell
2020-05-17 15:50   ` Eryu Guan
2020-05-05 20:20 ` [PATCH 2/3] fstests: test restricted symlinks & hardlinks sysctls Eric Sandeen
2020-05-06 18:44   ` Bill O'Donnell
2020-05-06 18:48     ` Eric Sandeen
2020-05-06 18:52       ` Bill O'Donnell
2020-05-17 15:55   ` Eryu Guan
2020-05-18 14:42     ` Eric Sandeen
2020-05-18 14:45       ` Eric Sandeen
2020-05-05 20:21 ` [PATCH 3/3] fstests: test restricted file access sysctls Eric Sandeen
2020-05-06 18:47   ` Bill O'Donnell
2020-05-06 18:53   ` Bill O'Donnell
2020-05-06 19:23   ` Eric Sandeen
2020-05-06 19:29   ` [PATCH 3/3 V2] " Eric Sandeen
2020-05-06 19:42     ` Bill O'Donnell
2020-05-17 15:57     ` Eryu Guan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).