2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2013 Oracle, Inc. All Rights Reserved.
7 # Check uid/gid to/from disk with a user namespace. A new file
8 # will be created from inside a userns. We check that the uid/gid
9 # is correct from both inside the userns and also from init_user_ns.
10 # We will then unmount and remount the file system and check the
11 # uid/gid from both inside the userns and from init_user_ns to show
12 # that the correct uid was flushed and brought back from disk.
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
20 status=1 # failure is the default!
25 _scratch_unmount >/dev/null 2>&1
27 trap "_cleanup; exit \$status" 0 1 2 3 15
29 # get standard environment, filters and checks
34 file=$SCRATCH_MNT/file1
36 # real QA test starts here
38 # only Linux supports user namespace
41 [ -x $lstat64 ] || _notrun "$lstat64 executable not found"
49 qa_user_id=`id -u $qa_user`
54 -e "s/$qa_user_id/qa_user/g" \
55 -e "s!$SCRATCH_MNT!\$SCRATCH_MNT!"
60 echo "From init_user_ns"
61 $here/src/lstat64 $file |head -3 |_filter_output
64 # don't use $here/src/lstat64, as we're running cmd(src/lstat64) in
65 # nsexec as a regular user, and $here may contain path component that
66 # a regular user doesn't have search permission
67 $here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" src/lstat64 $file |head -3 |_filter_output
70 _scratch_unmount >/dev/null 2>&1
71 echo "*** MKFS ***" >>$seqres.full
72 echo "" >>$seqres.full
73 _scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
75 chmod 777 $SCRATCH_MNT
77 # create $file as "root" in userns, which is $qa_user in parent namespace
78 $here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
83 echo "*** Remounting ***"
86 _scratch_cycle_mount >>$seqres.full 2>&1 || _fail "remount failed"
90 _scratch_unmount >/dev/null 2>&1