2013-06-27 16:03:34 +00:00
|
|
|
#! /bin/bash
|
2018-06-09 11:35:42 +10:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
# Copyright (C) 2013 Oracle, Inc. All Rights Reserved.
|
|
|
|
|
#
|
2013-06-27 16:03:34 +00:00
|
|
|
# FS QA Test No. 317
|
|
|
|
|
#
|
|
|
|
|
# Check uid/gid to/from disk with a user namespace. A new file
|
|
|
|
|
# will be created from inside a userns. We check that the uid/gid
|
|
|
|
|
# is correct from both inside the userns and also from init_user_ns.
|
|
|
|
|
# We will then unmount and remount the file system and check the
|
|
|
|
|
# uid/gid from both inside the userns and from init_user_ns to show
|
|
|
|
|
# that the correct uid was flushed and brought back from disk.
|
|
|
|
|
#
|
|
|
|
|
seq=`basename $0`
|
|
|
|
|
seqres=$RESULT_DIR/$seq
|
|
|
|
|
echo "QA output created by $seq"
|
|
|
|
|
|
|
|
|
|
here=`pwd`
|
|
|
|
|
tmp=/tmp/$$
|
|
|
|
|
status=1 # failure is the default!
|
|
|
|
|
|
|
|
|
|
_cleanup()
|
|
|
|
|
{
|
|
|
|
|
cd /
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount >/dev/null 2>&1
|
2013-06-27 16:03:34 +00:00
|
|
|
}
|
|
|
|
|
trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
|
|
|
|
|
|
|
# get standard environment, filters and checks
|
|
|
|
|
. ./common/rc
|
|
|
|
|
. ./common/filter
|
|
|
|
|
. ./common/attr
|
|
|
|
|
|
|
|
|
|
file=$SCRATCH_MNT/file1
|
|
|
|
|
|
|
|
|
|
# real QA test starts here
|
|
|
|
|
_supported_fs generic
|
|
|
|
|
# only Linux supports user namespace
|
|
|
|
|
_supported_os Linux
|
|
|
|
|
|
|
|
|
|
[ -x $lstat64 ] || _notrun "$lstat64 executable not found"
|
|
|
|
|
|
|
|
|
|
rm -f $seqres.full
|
|
|
|
|
|
|
|
|
|
_require_scratch
|
|
|
|
|
_require_user
|
2013-10-29 12:17:48 +00:00
|
|
|
_require_ugid_map
|
2014-06-18 09:34:39 +10:00
|
|
|
_require_userns
|
2016-09-23 23:32:27 +08:00
|
|
|
qa_user_id=`id -u $qa_user`
|
2013-06-27 16:03:34 +00:00
|
|
|
|
|
|
|
|
_filter_output()
|
|
|
|
|
{
|
|
|
|
|
sed \
|
|
|
|
|
-e "s/$qa_user_id/qa_user/g" \
|
|
|
|
|
-e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_print_numeric_uid()
|
|
|
|
|
{
|
|
|
|
|
echo "From init_user_ns"
|
2019-10-21 21:35:46 +08:00
|
|
|
$here/src/lstat64 $file |head -3 |_filter_output
|
2013-06-27 16:03:34 +00:00
|
|
|
|
|
|
|
|
echo "From user_ns"
|
2019-10-31 17:19:17 +08:00
|
|
|
# don't use $here/src/lstat64, as we're running cmd(src/lstat64) in
|
|
|
|
|
# nsexec as a regular user, and $here may contain path component that
|
|
|
|
|
# a regular user doesn't have search permission
|
|
|
|
|
$here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" src/lstat64 $file |head -3 |_filter_output
|
2013-06-27 16:03:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount >/dev/null 2>&1
|
2013-06-27 16:03:34 +00:00
|
|
|
echo "*** MKFS ***" >>$seqres.full
|
|
|
|
|
echo "" >>$seqres.full
|
|
|
|
|
_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
|
2018-02-07 17:31:36 +08:00
|
|
|
_scratch_mount
|
2013-06-27 16:03:34 +00:00
|
|
|
chmod 777 $SCRATCH_MNT
|
|
|
|
|
|
|
|
|
|
# create $file as "root" in userns, which is $qa_user in parent namespace
|
2019-10-21 21:35:46 +08:00
|
|
|
$here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
|
2013-06-27 16:03:34 +00:00
|
|
|
|
|
|
|
|
_print_numeric_uid
|
|
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
echo "*** Remounting ***"
|
|
|
|
|
echo ""
|
|
|
|
|
sync
|
2016-02-19 10:45:35 +11:00
|
|
|
_scratch_cycle_mount >>$seqres.full 2>&1 || _fail "remount failed"
|
2013-06-27 16:03:34 +00:00
|
|
|
|
|
|
|
|
_print_numeric_uid
|
|
|
|
|
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_unmount >/dev/null 2>&1
|
2013-06-27 16:03:34 +00:00
|
|
|
status=0
|
|
|
|
|
exit
|