blob: 39cccc8bc0d05fd7e6245c5f02f242fb24c4e975 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2013 Oracle, Inc. All Rights Reserved.
#
# 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.
#
. ./common/preamble
_begin_fstest auto metadata quick
# Override the default cleanup function.
_cleanup()
{
cd /
_scratch_unmount >/dev/null 2>&1
}
# Import common functions.
. ./common/filter
. ./common/attr
file=$SCRATCH_MNT/file1
# real QA test starts here
_supported_fs generic
# only Linux supports user namespace
[ -x $lstat64 ] || _notrun "$lstat64 executable not found"
_require_scratch
_require_user
_require_ugid_map
_require_userns
_require_chown
_require_use_local_uidgid
qa_user_id=`id -u $qa_user`
_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"
$here/src/lstat64 $file |head -3 |_filter_output
echo "From user_ns"
# 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
}
_scratch_unmount >/dev/null 2>&1
echo "*** MKFS ***" >>$seqres.full
echo "" >>$seqres.full
_scratch_mkfs >>$seqres.full 2>&1 || _fail "mkfs failed"
_scratch_mount
chmod 777 $SCRATCH_MNT
# create $file as "root" in userns, which is $qa_user in parent namespace
$here/src/nsexec -s -U -M "0 $qa_user_id 1000" -G "0 $qa_user_id 1000" touch $file
_print_numeric_uid
echo ""
echo "*** Remounting ***"
echo ""
sync
_scratch_cycle_mount >>$seqres.full 2>&1 || _fail "remount failed"
_print_numeric_uid
_scratch_unmount >/dev/null 2>&1
status=0
exit
|