From patchwork Mon Apr 11 22:54:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12809747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1806C433FE for ; Mon, 11 Apr 2022 22:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348185AbiDKW4z (ORCPT ); Mon, 11 Apr 2022 18:56:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350471AbiDKW4y (ORCPT ); Mon, 11 Apr 2022 18:56:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C1C6A195; Mon, 11 Apr 2022 15:54:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0559961745; Mon, 11 Apr 2022 22:54:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 600C7C385A3; Mon, 11 Apr 2022 22:54:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649717677; bh=aeUFknBcWBelMSTUFf2w3tHyo65gOicRWbiyY82fQJ8=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=Tv0vawjW/qGFgYu5PlIaUEBQKAPLJrz2l+es7dN+4fKuyVzg7BMJiYp9oY6LQPqO3 T8JXnCrakekIPzMO8L8CeBKSBfp3I/OFUkR0RRjDrj8j3C1nh0FtQH+ssc2xVWE9Hb zjaDFTasiBRAqYAdxcZyjzCcFYpnWlz2NtQE3QBbm8E4sjpQ4XjtvARnXanzjLyyw3 YmiDPLjsOJzQ2OG8gWMzUdjlqlzdy/K+BVW3+UMm0581skls1rvZBD0h1JdXyZl5Jn AmKO17dS985kz8GoCb4l7eG/SEEmcU/JKW4Ln+sfwgPKXPHJCcQh23QOVffKn0b9Bv 3IZ4d8CLwP4zA== Subject: [PATCH 1/4] xfs: make sure syncfs(2) passes back super_operations.sync_fs errors From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com, zlang@redhat.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 11 Apr 2022 15:54:37 -0700 Message-ID: <164971767699.169983.772317637668809854.stgit@magnolia> In-Reply-To: <164971767143.169983.12905331894414458027.stgit@magnolia> References: <164971767143.169983.12905331894414458027.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong This is a regression test to make sure that nonzero error returns from a filesystem's ->sync_fs implementation are actually passed back to userspace when the call stack involves syncfs(2). Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang --- tests/xfs/839 | 42 ++++++++++++++++++++++++++++++++++++++++++ tests/xfs/839.out | 2 ++ 2 files changed, 44 insertions(+) create mode 100755 tests/xfs/839 create mode 100644 tests/xfs/839.out diff --git a/tests/xfs/839 b/tests/xfs/839 new file mode 100755 index 00000000..9bfe93ef --- /dev/null +++ b/tests/xfs/839 @@ -0,0 +1,42 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 839 +# +# Regression test for kernel commits: +# +# 5679897eb104 ("vfs: make sync_filesystem return errors from ->sync_fs") +# 2d86293c7075 ("xfs: return errors in xfs_fs_sync_fs") +# +# During a code inspection, I noticed that sync_filesystem ignores the return +# value of the ->sync_fs calls that it makes. sync_filesystem, in turn is used +# by the syncfs(2) syscall to persist filesystem changes to disk. This means +# that syncfs(2) does not capture internal filesystem errors that are neither +# visible from the block device (e.g. media error) nor recorded in s_wb_err. +# XFS historically returned 0 from ->sync_fs even if there were log failures, +# so that had to be corrected as well. +# +# The kernel commits above fix this problem, so this test tries to trigger the +# bug by using the shutdown ioctl on a clean, freshly mounted filesystem in the +# hope that the EIO generated as a result of the filesystem being shut down is +# only visible via ->sync_fs. +# +. ./common/preamble +_begin_fstest auto quick shutdown + +# real QA test starts here + +# Modify as appropriate. +_require_xfs_io_command syncfs +_require_scratch_nocheck +_require_scratch_shutdown + +# Reuse the fs formatted when we checked for the shutdown ioctl, and don't +# bother checking the filesystem afterwards since we never wrote anything. +_scratch_mount +$XFS_IO_PROG -x -c 'shutdown -f ' -c syncfs $SCRATCH_MNT + +# success, all done +status=0 +exit diff --git a/tests/xfs/839.out b/tests/xfs/839.out new file mode 100644 index 00000000..f275cdcc --- /dev/null +++ b/tests/xfs/839.out @@ -0,0 +1,2 @@ +QA output created by 839 +syncfs: Input/output error From patchwork Mon Apr 11 22:54:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12809748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAF85C433F5 for ; Mon, 11 Apr 2022 22:54:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350196AbiDKW5B (ORCPT ); Mon, 11 Apr 2022 18:57:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350471AbiDKW5A (ORCPT ); Mon, 11 Apr 2022 18:57:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 345E2B873; Mon, 11 Apr 2022 15:54:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B545961773; Mon, 11 Apr 2022 22:54:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2DECC385A3; Mon, 11 Apr 2022 22:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649717683; bh=1OiR8bgNFfnx3MScPV5QH55Wm2L5VuEOgXNDNf2D8BU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=MfHBNyZ5kAQ8TeLJanv+mHgr0LRP0hQabESPsZz4gZUbVwRyqgyhBR6HR83IJsgMz k1G6IyjTc69D2MwKRouABnbL8SfiDstXocy1+fYKqkD1TugX4sOwNnjjvGDwpciQgI vxVx3/0hxfmU5aq1KkKVQ/v63zx6sWlxddjsI4jBEwed1k+lwexRYGjoXiNbdoOhOn EWiWbzwC8LBaxM6O1Ffh+19A3+uTBewuJqLX2YAOz82Z55AlWg95zXJcMhBooG6mED /GsXAbTl/hsq6sgoCdK+4TbLeFqT/RQrbybuaOoQqYPOWJaeXLDdBXOON9hDlyfCw+ p2jUK9me5YCew== Subject: [PATCH 2/4] generic: ensure we drop suid after fallocate From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com, zlang@redhat.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 11 Apr 2022 15:54:42 -0700 Message-ID: <164971768254.169983.13280225265874038241.stgit@magnolia> In-Reply-To: <164971767143.169983.12905331894414458027.stgit@magnolia> References: <164971767143.169983.12905331894414458027.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong fallocate changes file contents, so make sure that we drop privileges and file capabilities after each fallocate operation. Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang --- tests/generic/834 | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/834.out | 33 +++++++++++++ tests/generic/835 | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/835.out | 33 +++++++++++++ tests/generic/836 | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/836.out | 33 +++++++++++++ tests/generic/837 | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/837.out | 33 +++++++++++++ tests/generic/838 | 127 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/838.out | 33 +++++++++++++ tests/generic/839 | 77 ++++++++++++++++++++++++++++++ tests/generic/839.out | 13 +++++ 12 files changed, 890 insertions(+) create mode 100755 tests/generic/834 create mode 100644 tests/generic/834.out create mode 100755 tests/generic/835 create mode 100644 tests/generic/835.out create mode 100755 tests/generic/836 create mode 100644 tests/generic/836.out create mode 100755 tests/generic/837 create mode 100644 tests/generic/837.out create mode 100755 tests/generic/838 create mode 100644 tests/generic/838.out create mode 100755 tests/generic/839 create mode 100755 tests/generic/839.out diff --git a/tests/generic/834 b/tests/generic/834 new file mode 100755 index 00000000..9302137b --- /dev/null +++ b/tests/generic/834 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 834 +# +# Functional test for dropping suid and sgid bits as part of a fallocate. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_test +verb=falloc +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/834.out b/tests/generic/834.out new file mode 100644 index 00000000..2226eea6 --- /dev/null +++ b/tests/generic/834.out @@ -0,0 +1,33 @@ +QA output created by 834 +Test 1 - qa_user, non-exec file falloc +6666 -rwSrwSrw- TEST_DIR/834/a +666 -rw-rw-rw- TEST_DIR/834/a + +Test 2 - qa_user, group-exec file falloc +6676 -rwSrwsrw- TEST_DIR/834/a +676 -rw-rwxrw- TEST_DIR/834/a + +Test 3 - qa_user, user-exec file falloc +6766 -rwsrwSrw- TEST_DIR/834/a +766 -rwxrw-rw- TEST_DIR/834/a + +Test 4 - qa_user, all-exec file falloc +6777 -rwsrwsrwx TEST_DIR/834/a +777 -rwxrwxrwx TEST_DIR/834/a + +Test 5 - root, non-exec file falloc +6666 -rwSrwSrw- TEST_DIR/834/a +6666 -rwSrwSrw- TEST_DIR/834/a + +Test 6 - root, group-exec file falloc +6676 -rwSrwsrw- TEST_DIR/834/a +6676 -rwSrwsrw- TEST_DIR/834/a + +Test 7 - root, user-exec file falloc +6766 -rwsrwSrw- TEST_DIR/834/a +6766 -rwsrwSrw- TEST_DIR/834/a + +Test 8 - root, all-exec file falloc +6777 -rwsrwsrwx TEST_DIR/834/a +6777 -rwsrwsrwx TEST_DIR/834/a + diff --git a/tests/generic/835 b/tests/generic/835 new file mode 100755 index 00000000..b0dc9cc3 --- /dev/null +++ b/tests/generic/835 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 835 +# +# Functional test for dropping suid and sgid bits as part of a fpunch. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_test +verb=fpunch +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/835.out b/tests/generic/835.out new file mode 100644 index 00000000..186d7da4 --- /dev/null +++ b/tests/generic/835.out @@ -0,0 +1,33 @@ +QA output created by 835 +Test 1 - qa_user, non-exec file fpunch +6666 -rwSrwSrw- TEST_DIR/835/a +666 -rw-rw-rw- TEST_DIR/835/a + +Test 2 - qa_user, group-exec file fpunch +6676 -rwSrwsrw- TEST_DIR/835/a +676 -rw-rwxrw- TEST_DIR/835/a + +Test 3 - qa_user, user-exec file fpunch +6766 -rwsrwSrw- TEST_DIR/835/a +766 -rwxrw-rw- TEST_DIR/835/a + +Test 4 - qa_user, all-exec file fpunch +6777 -rwsrwsrwx TEST_DIR/835/a +777 -rwxrwxrwx TEST_DIR/835/a + +Test 5 - root, non-exec file fpunch +6666 -rwSrwSrw- TEST_DIR/835/a +6666 -rwSrwSrw- TEST_DIR/835/a + +Test 6 - root, group-exec file fpunch +6676 -rwSrwsrw- TEST_DIR/835/a +6676 -rwSrwsrw- TEST_DIR/835/a + +Test 7 - root, user-exec file fpunch +6766 -rwsrwSrw- TEST_DIR/835/a +6766 -rwsrwSrw- TEST_DIR/835/a + +Test 8 - root, all-exec file fpunch +6777 -rwsrwsrwx TEST_DIR/835/a +6777 -rwsrwsrwx TEST_DIR/835/a + diff --git a/tests/generic/836 b/tests/generic/836 new file mode 100755 index 00000000..ff0cf092 --- /dev/null +++ b/tests/generic/836 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 836 +# +# Functional test for dropping suid and sgid bits as part of a fzero. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_test +verb=fzero +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/836.out b/tests/generic/836.out new file mode 100644 index 00000000..9f9f5f12 --- /dev/null +++ b/tests/generic/836.out @@ -0,0 +1,33 @@ +QA output created by 836 +Test 1 - qa_user, non-exec file fzero +6666 -rwSrwSrw- TEST_DIR/836/a +666 -rw-rw-rw- TEST_DIR/836/a + +Test 2 - qa_user, group-exec file fzero +6676 -rwSrwsrw- TEST_DIR/836/a +676 -rw-rwxrw- TEST_DIR/836/a + +Test 3 - qa_user, user-exec file fzero +6766 -rwsrwSrw- TEST_DIR/836/a +766 -rwxrw-rw- TEST_DIR/836/a + +Test 4 - qa_user, all-exec file fzero +6777 -rwsrwsrwx TEST_DIR/836/a +777 -rwxrwxrwx TEST_DIR/836/a + +Test 5 - root, non-exec file fzero +6666 -rwSrwSrw- TEST_DIR/836/a +6666 -rwSrwSrw- TEST_DIR/836/a + +Test 6 - root, group-exec file fzero +6676 -rwSrwsrw- TEST_DIR/836/a +6676 -rwSrwsrw- TEST_DIR/836/a + +Test 7 - root, user-exec file fzero +6766 -rwsrwSrw- TEST_DIR/836/a +6766 -rwsrwSrw- TEST_DIR/836/a + +Test 8 - root, all-exec file fzero +6777 -rwsrwsrwx TEST_DIR/836/a +6777 -rwsrwsrwx TEST_DIR/836/a + diff --git a/tests/generic/837 b/tests/generic/837 new file mode 100755 index 00000000..477b8f21 --- /dev/null +++ b/tests/generic/837 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 837 +# +# Functional test for dropping suid and sgid bits as part of a finsert. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_test +verb=finsert +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/837.out b/tests/generic/837.out new file mode 100644 index 00000000..686b806e --- /dev/null +++ b/tests/generic/837.out @@ -0,0 +1,33 @@ +QA output created by 837 +Test 1 - qa_user, non-exec file finsert +6666 -rwSrwSrw- TEST_DIR/837/a +666 -rw-rw-rw- TEST_DIR/837/a + +Test 2 - qa_user, group-exec file finsert +6676 -rwSrwsrw- TEST_DIR/837/a +676 -rw-rwxrw- TEST_DIR/837/a + +Test 3 - qa_user, user-exec file finsert +6766 -rwsrwSrw- TEST_DIR/837/a +766 -rwxrw-rw- TEST_DIR/837/a + +Test 4 - qa_user, all-exec file finsert +6777 -rwsrwsrwx TEST_DIR/837/a +777 -rwxrwxrwx TEST_DIR/837/a + +Test 5 - root, non-exec file finsert +6666 -rwSrwSrw- TEST_DIR/837/a +6666 -rwSrwSrw- TEST_DIR/837/a + +Test 6 - root, group-exec file finsert +6676 -rwSrwsrw- TEST_DIR/837/a +6676 -rwSrwsrw- TEST_DIR/837/a + +Test 7 - root, user-exec file finsert +6766 -rwsrwSrw- TEST_DIR/837/a +6766 -rwsrwSrw- TEST_DIR/837/a + +Test 8 - root, all-exec file finsert +6777 -rwsrwsrwx TEST_DIR/837/a +6777 -rwsrwsrwx TEST_DIR/837/a + diff --git a/tests/generic/838 b/tests/generic/838 new file mode 100755 index 00000000..d7c7e5a8 --- /dev/null +++ b/tests/generic/838 @@ -0,0 +1,127 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 838 +# +# Functional test for dropping suid and sgid bits as part of a fcollapse. +# +. ./common/preamble +_begin_fstest auto clone quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter +. ./common/reflink + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_test +verb=fcollapse +_require_xfs_io_command $verb + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + _pwrite_byte 0x58 0 192k $junk_file >> $seqres.full + sync +} + +commit_and_check() { + local user="$1" + local command="$2" + local start="$3" + local end="$4" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c '$command $start $end' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +nr=0 +# Commit to a non-exec file by an unprivileged user clears suid but +# leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a group-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a user-exec file by an unprivileged user clears suid but +# not sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a all-exec file by an unprivileged user clears suid and +# sgid. +nr=$((nr + 1)) +echo "Test $nr - qa_user, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "$qa_user" "$verb" 64k 64k + +# Commit to a non-exec file by root clears suid but leaves sgid. +nr=$((nr + 1)) +echo "Test $nr - root, non-exec file $verb" +setup_testfile +chmod a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a group-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, group-exec file $verb" +setup_testfile +chmod g+x,a+rws $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a user-exec file by root clears suid but not sgid. +nr=$((nr + 1)) +echo "Test $nr - root, user-exec file $verb" +setup_testfile +chmod u+x,a+rws,g-x $junk_file +commit_and_check "" "$verb" 64k 64k + +# Commit to a all-exec file by root clears suid and sgid. +nr=$((nr + 1)) +echo "Test $nr - root, all-exec file $verb" +setup_testfile +chmod a+rwxs $junk_file +commit_and_check "" "$verb" 64k 64k + +# success, all done +status=0 +exit diff --git a/tests/generic/838.out b/tests/generic/838.out new file mode 100644 index 00000000..cdc29f4b --- /dev/null +++ b/tests/generic/838.out @@ -0,0 +1,33 @@ +QA output created by 838 +Test 1 - qa_user, non-exec file fcollapse +6666 -rwSrwSrw- TEST_DIR/838/a +666 -rw-rw-rw- TEST_DIR/838/a + +Test 2 - qa_user, group-exec file fcollapse +6676 -rwSrwsrw- TEST_DIR/838/a +676 -rw-rwxrw- TEST_DIR/838/a + +Test 3 - qa_user, user-exec file fcollapse +6766 -rwsrwSrw- TEST_DIR/838/a +766 -rwxrw-rw- TEST_DIR/838/a + +Test 4 - qa_user, all-exec file fcollapse +6777 -rwsrwsrwx TEST_DIR/838/a +777 -rwxrwxrwx TEST_DIR/838/a + +Test 5 - root, non-exec file fcollapse +6666 -rwSrwSrw- TEST_DIR/838/a +6666 -rwSrwSrw- TEST_DIR/838/a + +Test 6 - root, group-exec file fcollapse +6676 -rwSrwsrw- TEST_DIR/838/a +6676 -rwSrwsrw- TEST_DIR/838/a + +Test 7 - root, user-exec file fcollapse +6766 -rwsrwSrw- TEST_DIR/838/a +6766 -rwsrwSrw- TEST_DIR/838/a + +Test 8 - root, all-exec file fcollapse +6777 -rwsrwsrwx TEST_DIR/838/a +6777 -rwsrwsrwx TEST_DIR/838/a + diff --git a/tests/generic/839 b/tests/generic/839 new file mode 100755 index 00000000..70bef5fc --- /dev/null +++ b/tests/generic/839 @@ -0,0 +1,77 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 839 +# +# Functional test for dropping capability bits as part of an fallocate. +# +. ./common/preamble +_begin_fstest auto prealloc quick + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -r -f $tmp.* $junk_dir +} + +# Import common functions. +. ./common/filter + +# real QA test starts here + +# Modify as appropriate. +_supported_fs xfs btrfs ext4 +_require_user +_require_command "$GETCAP_PROG" getcap +_require_command "$SETCAP_PROG" setcap +_require_xfs_io_command falloc +_require_test + +junk_dir=$TEST_DIR/$seq +junk_file=$junk_dir/a +mkdir -p $junk_dir/ +chmod a+rw $junk_dir/ + +setup_testfile() { + rm -f $junk_file + touch $junk_file + chmod a+rwx $junk_file + $SETCAP_PROG cap_setgid,cap_setuid+ep $junk_file + sync +} + +commit_and_check() { + local user="$1" + + stat -c '%a %A %n' $junk_file | _filter_test_dir + _getcap -v $junk_file | _filter_test_dir + + local cmd="$XFS_IO_PROG -c 'falloc 0 64k' $junk_file" + if [ -n "$user" ]; then + su - "$user" -c "$cmd" >> $seqres.full + else + $SHELL -c "$cmd" >> $seqres.full + fi + + stat -c '%a %A %n' $junk_file | _filter_test_dir + _getcap -v $junk_file | _filter_test_dir + + # Blank line in output + echo +} + +# Commit by an unprivileged user clears capability bits. +echo "Test 1 - qa_user" +setup_testfile +commit_and_check "$qa_user" + +# Commit by root leaves capability bits. +echo "Test 2 - root" +setup_testfile +commit_and_check + +# success, all done +status=0 +exit diff --git a/tests/generic/839.out b/tests/generic/839.out new file mode 100755 index 00000000..f571cd26 --- /dev/null +++ b/tests/generic/839.out @@ -0,0 +1,13 @@ +QA output created by 839 +Test 1 - qa_user +777 -rwxrwxrwx TEST_DIR/839/a +TEST_DIR/839/a cap_setgid,cap_setuid=ep +777 -rwxrwxrwx TEST_DIR/839/a +TEST_DIR/839/a + +Test 2 - root +777 -rwxrwxrwx TEST_DIR/839/a +TEST_DIR/839/a cap_setgid,cap_setuid=ep +777 -rwxrwxrwx TEST_DIR/839/a +TEST_DIR/839/a + From patchwork Mon Apr 11 22:54:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12809749 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3334FC433EF for ; Mon, 11 Apr 2022 22:54:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346412AbiDKW5H (ORCPT ); Mon, 11 Apr 2022 18:57:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350475AbiDKW5H (ORCPT ); Mon, 11 Apr 2022 18:57:07 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A0A7DF28; Mon, 11 Apr 2022 15:54:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 14FBBB8199A; Mon, 11 Apr 2022 22:54:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7B7DC385A9; Mon, 11 Apr 2022 22:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649717688; bh=IFRfpBkkmOLxiQESIeeEuh7UioZXxo4ZwgO+aWayNUQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=I7ccXA/DxEHi/dliFWG7wrUkcrRf1KhfxXfV3WxJ4SXaXp0LDSat1Mck+xIzsETw4 C0k9vPJbB8QizhdIkonrEhAl5FkJeiSntGec7+n6DKyNo2Ag7EDtO2KEdMXlx5eO00 8dm3Al74U/DKL/5azlhQU4SYGXY+wfWONZST5lUNhnUklDALgxp6sUkaTbdCS7Jl95 DPl/CP1vzAUmFzF2wmeut/z/0GZC4AN9DiqDjV909K1xYKrUYO3RNEqBMc44/IfoKn IHVCs2hNSnrTOcBkZBxSR9NZXj4Lu+kuyx4xRqSHwzdGvxypIwx/GlBzSD7LwBybtk N0w80HuPlkRwg== Subject: [PATCH 3/4] generic: test that linking into a directory fails with EDQUOT From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com, zlang@redhat.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 11 Apr 2022 15:54:48 -0700 Message-ID: <164971768834.169983.11537125892654404197.stgit@magnolia> In-Reply-To: <164971767143.169983.12905331894414458027.stgit@magnolia> References: <164971767143.169983.12905331894414458027.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Add a regression test to make sure that unprivileged userspace linking into a directory fails with EDQUOT when the directory quota limits have been exceeded. Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang --- tests/generic/832 | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/832.out | 3 ++ 2 files changed, 70 insertions(+) create mode 100755 tests/generic/832 create mode 100644 tests/generic/832.out diff --git a/tests/generic/832 b/tests/generic/832 new file mode 100755 index 00000000..1190b795 --- /dev/null +++ b/tests/generic/832 @@ -0,0 +1,67 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 832 +# +# Ensure that unprivileged userspace hits EDQUOT while linking files into a +# directory when the directory's quota limits have been exceeded. +# +# Regression test for commit: +# +# 871b9316e7a7 ("xfs: reserve quota for dir expansion when linking/unlinking files") +# +. ./common/preamble +_begin_fstest auto quick quota + +# Import common functions. +. ./common/filter +. ./common/quota + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_quota +_require_user +_require_scratch + +_scratch_mkfs > "$seqres.full" 2>&1 +_qmount_option usrquota +_qmount + +blocksize=$(_get_block_size $SCRATCH_MNT) +scratchdir=$SCRATCH_MNT/dir +scratchfile=$SCRATCH_MNT/file +mkdir $scratchdir +touch $scratchfile + +# Create a 2-block directory for our 1-block quota limit +total_size=$((blocksize * 2)) +dirents=$((total_size / 255)) + +for ((i = 0; i < dirents; i++)); do + name=$(printf "x%0254d" $i) + ln $scratchfile $scratchdir/$name +done + +# Set a low quota hardlimit for an unprivileged uid and chown the files to it +echo "set up quota" >> $seqres.full +setquota -u $qa_user 0 "$((blocksize / 1024))" 0 0 $SCRATCH_MNT +chown $qa_user $scratchdir $scratchfile +repquota -upn $SCRATCH_MNT >> $seqres.full + +# Fail at appending the directory as qa_user to ensure quota enforcement works +echo "fail quota" >> $seqres.full +for ((i = 0; i < dirents; i++)); do + name=$(printf "y%0254d" $i) + su - "$qa_user" -c "ln $scratchfile $scratchdir/$name" 2>&1 | \ + _filter_scratch | sed -e 's/y[0-9]*/yXXX/g' + test "${PIPESTATUS[0]}" -ne 0 && break +done +repquota -upn $SCRATCH_MNT >> $seqres.full + +# success, all done +echo Silence is golden +status=0 +exit diff --git a/tests/generic/832.out b/tests/generic/832.out new file mode 100644 index 00000000..593afe8b --- /dev/null +++ b/tests/generic/832.out @@ -0,0 +1,3 @@ +QA output created by 832 +ln: failed to create hard link 'SCRATCH_MNT/dir/yXXX': Disk quota exceeded +Silence is golden From patchwork Mon Apr 11 22:54:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12809750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 875DBC433F5 for ; Mon, 11 Apr 2022 22:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350477AbiDKW5L (ORCPT ); Mon, 11 Apr 2022 18:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350475AbiDKW5L (ORCPT ); Mon, 11 Apr 2022 18:57:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6421BE013; Mon, 11 Apr 2022 15:54:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F3FDE61777; Mon, 11 Apr 2022 22:54:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AE99C385A4; Mon, 11 Apr 2022 22:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649717694; bh=MVAzYufKDJ7M/w3FluUtjlrHb4+oED2PRGEOkqEGXuk=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=kgpRfuu41MjI0UGpUiPrWFqsIuhu+6wIzw2v09OMf5nJbV4h8Ly157yYpjH6xOltw RAVBeCYO+hZOX3L7c8vVAEzdet/Xy8s2enuu1EXYcRKLpx9q46876IslFAI3yTFt+u 8sKztoEIWJhcEplUEM7kCZ3l4pTAB9lHgiJCgR/KB/EaYqAXLEYT/YW5JYFQDOeSIz wtK5EfsyXczWBClelEpLUSx2Jlx2jNo70vZxVgqG+lQahOmz8dvoMZyT51Z+d1S+O5 i4kV5wBnjfAJI3w6wNSqOu/WpZSrMtKcLmHYHMLciaM7AAzLrUVUScpoSLVh9hQ2yV HYBF8/j3DpRFg== Subject: [PATCH 4/4] generic: test that renaming into a directory fails with EDQUOT From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com, zlang@redhat.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me Date: Mon, 11 Apr 2022 15:54:54 -0700 Message-ID: <164971769398.169983.1284630275364529313.stgit@magnolia> In-Reply-To: <164971767143.169983.12905331894414458027.stgit@magnolia> References: <164971767143.169983.12905331894414458027.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Add a regression test to make sure that unprivileged userspace renaming within a directory fails with EDQUOT when the directory quota limits have been exceeded. Signed-off-by: Darrick J. Wong Reviewed-by: Zorro Lang --- tests/generic/833 | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/833.out | 3 ++ 2 files changed, 74 insertions(+) create mode 100755 tests/generic/833 create mode 100644 tests/generic/833.out diff --git a/tests/generic/833 b/tests/generic/833 new file mode 100755 index 00000000..a1b3cbc0 --- /dev/null +++ b/tests/generic/833 @@ -0,0 +1,71 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2022 Oracle. All Rights Reserved. +# +# FS QA Test No. 833 +# +# Ensure that unprivileged userspace hits EDQUOT while moving files into a +# directory when the directory's quota limits have been exceeded. +# +# Regression test for commit: +# +# 41667260bc84 ("xfs: reserve quota for target dir expansion when renaming files") +# +. ./common/preamble +_begin_fstest auto quick quota + +# Import common functions. +. ./common/filter +. ./common/quota + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_require_quota +_require_user +_require_scratch + +_scratch_mkfs > "$seqres.full" 2>&1 +_qmount_option usrquota +_qmount + +blocksize=$(_get_block_size $SCRATCH_MNT) +scratchdir=$SCRATCH_MNT/dir +scratchfile=$SCRATCH_MNT/file +stagedir=$SCRATCH_MNT/staging +mkdir $scratchdir $stagedir +touch $scratchfile + +# Create a 2-block directory for our 1-block quota limit +total_size=$((blocksize * 2)) +dirents=$((total_size / 255)) + +for ((i = 0; i < dirents; i++)); do + name=$(printf "x%0254d" $i) + ln $scratchfile $scratchdir/$name +done + +# Set a low quota hardlimit for an unprivileged uid and chown the files to it +echo "set up quota" >> $seqres.full +setquota -u $qa_user 0 "$((blocksize / 1024))" 0 0 $SCRATCH_MNT +chown $qa_user $scratchdir $scratchfile +repquota -upn $SCRATCH_MNT >> $seqres.full + +# Fail at renaming into the directory as qa_user to ensure quota enforcement +# works +chmod a+rwx $stagedir +echo "fail quota" >> $seqres.full +for ((i = 0; i < dirents; i++)); do + name=$(printf "y%0254d" $i) + ln $scratchfile $stagedir/$name + su - "$qa_user" -c "mv $stagedir/$name $scratchdir/$name" 2>&1 | \ + _filter_scratch | sed -e 's/y[0-9]*/yXXX/g' + test "${PIPESTATUS[0]}" -ne 0 && break +done +repquota -upn $SCRATCH_MNT >> $seqres.full + +# success, all done +echo Silence is golden +status=0 +exit diff --git a/tests/generic/833.out b/tests/generic/833.out new file mode 100644 index 00000000..d100fa07 --- /dev/null +++ b/tests/generic/833.out @@ -0,0 +1,3 @@ +QA output created by 833 +mv: cannot move 'SCRATCH_MNT/staging/yXXX' to 'SCRATCH_MNT/dir/yXXX': Disk quota exceeded +Silence is golden