Whamcloud - gitweb
LU-14739 quota: nodemap squashed root cannot bypass quota
[fs/lustre-release.git] / lustre / tests / sanity-sec.sh
index 8b0900c..9744b9a 100755 (executable)
@@ -52,10 +52,17 @@ ID1=${ID1:-501}
 USER0=$(getent passwd | grep :$ID0:$ID0: | cut -d: -f1)
 USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
 
-NODEMAP_COUNT=16
-NODEMAP_RANGE_COUNT=3
-NODEMAP_IPADDR_LIST="1 10 64 128 200 250"
-NODEMAP_ID_COUNT=10
+if [ "$SLOW" == "yes" ]; then
+       NODEMAP_COUNT=16
+       NODEMAP_RANGE_COUNT=3
+       NODEMAP_IPADDR_LIST="1 10 64 128 200 250"
+       NODEMAP_ID_COUNT=10
+else
+       NODEMAP_COUNT=3
+       NODEMAP_RANGE_COUNT=2
+       NODEMAP_IPADDR_LIST="1 250"
+       NODEMAP_ID_COUNT=3
+fi
 NODEMAP_MAX_ID=$((ID0 + NODEMAP_ID_COUNT))
 
 [ -z "$USER0" ] &&
@@ -161,7 +168,7 @@ test_1() {
        [ $GSS_SUP = 0 ] && skip "without GSS support." && return
 
        rm -rf $DIR/$tdir
-       mkdir -p $DIR/$tdir
+       mkdir_on_mdt0 $DIR/$tdir
 
        chown $USER0 $DIR/$tdir || error "chown (1)"
        $RUNAS_CMD -u $ID1 -v $ID0 touch $DIR/$tdir/f0 && error "touch (2)"
@@ -468,71 +475,6 @@ squash_id() {
        fi
 }
 
-wait_nm_sync() {
-       local nodemap_name=$1
-       local key=$2
-       local value=$3
-       local opt=$4
-       local proc_param
-       local is_active=$(do_facet mgs $LCTL get_param -n nodemap.active)
-       local max_retries=20
-       local is_sync
-       local out1=""
-       local out2
-       local mgs_ip=$(host_nids_address $mgs_HOST $NETTYPE | cut -d' ' -f1)
-       local i
-
-       if [ "$nodemap_name" == "active" ]; then
-               proc_param="active"
-       elif [ -z "$key" ]; then
-               proc_param=${nodemap_name}
-       else
-               proc_param="${nodemap_name}.${key}"
-       fi
-       if [ "$opt" == "inactive" ]; then
-               # check nm sync even if nodemap is not activated
-               is_active=1
-               opt=""
-       fi
-       (( is_active == 0 )) && [ "$proc_param" != "active" ] && return
-
-       if [ -z "$value" ]; then
-               out1=$(do_facet mgs $LCTL get_param $opt \
-                       nodemap.${proc_param} 2>/dev/null)
-               echo "On MGS ${mgs_ip}, ${proc_param} = $out1"
-       else
-               out1=$value;
-       fi
-
-       # wait up to 10 seconds for other servers to sync with mgs
-       for i in $(seq 1 10); do
-               for node in $(all_server_nodes); do
-                   local node_ip=$(host_nids_address $node $NETTYPE |
-                                   cut -d' ' -f1)
-
-                   is_sync=true
-                   if [ -z "$value" ]; then
-                       [ $node_ip == $mgs_ip ] && continue
-                   fi
-
-                   out2=$(do_node $node_ip $LCTL get_param $opt \
-                                  nodemap.$proc_param 2>/dev/null)
-                   echo "On $node ${node_ip}, ${proc_param} = $out2"
-                   [ "$out1" != "$out2" ] && is_sync=false && break
-               done
-               $is_sync && break
-               sleep 1
-       done
-       if ! $is_sync; then
-               echo MGS
-               echo $out1
-               echo OTHER - IP: $node_ip
-               echo $out2
-               error "mgs and $nodemap_name ${key} mismatch, $i attempts"
-       fi
-       echo "waited $((i - 1)) seconds for sync"
-}
-
 # ensure that the squash defaults are the expected defaults
 squash_id default 99 0
 wait_nm_sync default squash_uid '' inactive
@@ -1441,18 +1383,26 @@ test_fops_chmod_dir() {
 test_fops() {
        local mapmode="$1"
        local single_client="$2"
-       local client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
-                               [1]="0 $((IDBASE+5)) $((IDBASE+6))")
+       local client_user_list=([0]="0 $((IDBASE+3))"
+                               [1]="0 $((IDBASE+5))")
+       local mds_users="-1 0"
        local mds_i
        local rc=0
-       local perm_bit_list="0 3 $((0300)) $((0303))"
+       local perm_bit_list="3 $((0300))"
        # SLOW tests 000-007, 010-070, 100-700 (octal modes)
-       [ "$SLOW" == "yes" ] &&
+       if [ "$SLOW" == "yes" ]; then
                perm_bit_list="0 $(seq 1 7) $(seq 8 8 63) $(seq 64 64 511) \
                               $((0303))"
+               client_user_list=([0]="0 $((IDBASE+3)) $((IDBASE+4))"
+                                 [1]="0 $((IDBASE+5)) $((IDBASE+6))")
+               mds_users="-1 0 1 2"
+       fi
 
+       # force single_client to speed up test
+       [ "$SLOW" == "yes" ] ||
+               single_client=1
        # step through mds users. -1 means root
-       for mds_i in -1 0 1 2; do
+       for mds_i in $mds_users; do
                local user=$((mds_i + IDBASE))
                local client
                local x
@@ -3199,6 +3149,7 @@ test_44() {
        local testfile=$DIR/$tdir/$tfile
        local tmpfile=$TMP/abc
        local resfile=$TMP/resfile
+       local pagesz=$(getconf PAGESIZE)
        local respage
 
        $LCTL get_param mdc.*.import | grep -q client_encryption ||
@@ -3215,20 +3166,20 @@ test_44() {
        setup_for_enc_tests
 
        $LFS setstripe -c1 -i0 $testfile
-       dd if=/dev/urandom of=$tmpfile bs=8192 count=1 conv=fsync
-       dd if=$tmpfile of=$testfile bs=8192 count=1 oflag=direct ||
+       dd if=/dev/urandom of=$tmpfile bs=$pagesz count=2 conv=fsync
+       dd if=$tmpfile of=$testfile bs=$pagesz count=2 oflag=direct ||
                error "could not write to file with O_DIRECT (1)"
 
-       respage=$(vmtouch $testfile | awk '/Resident\ Pages:/ {print $3}')
+       respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
        [ "$respage" == "0/2" ] ||
                error "write to enc file fell back to buffered IO"
 
        cancel_lru_locks
 
-       dd if=$testfile of=$resfile bs=8192 count=1 iflag=direct ||
+       dd if=$testfile of=$resfile bs=$pagesz count=2 iflag=direct ||
                error "could not read from file with O_DIRECT (1)"
 
-       respage=$(vmtouch $testfile | awk '/Resident\ Pages:/ {print $3}')
+       respage=$(vmtouch $testfile | awk '/Resident Pages:/ {print $3}')
        [ "$respage" == "0/2" ] ||
                error "read from enc file fell back to buffered IO"
 
@@ -3237,13 +3188,13 @@ test_44() {
 
        rm -f $resfile
 
-       $TRUNCATE $tmpfile 4096
-       dd if=$tmpfile of=$testfile bs=4096 count=1 seek=13 oflag=direct ||
+       $TRUNCATE $tmpfile $pagesz
+       dd if=$tmpfile of=$testfile bs=$pagesz count=1 seek=13 oflag=direct ||
                error "could not write to file with O_DIRECT (2)"
 
        cancel_lru_locks
 
-       dd if=$testfile of=$resfile bs=4096 count=1 skip=13 iflag=direct ||
+       dd if=$testfile of=$resfile bs=$pagesz count=1 skip=13 iflag=direct ||
                error "could not read from file with O_DIRECT (2)"
        cmp -bl $tmpfile $resfile ||
                error "file $testfile is corrupted (2)"
@@ -3251,12 +3202,12 @@ test_44() {
        rm -f $testfile $resfile
        $LFS setstripe -c1 -i0 $testfile
 
-       $TRUNCATE $tmpfile 2043
+       $TRUNCATE $tmpfile $((pagesz/2 - 5))
        cp $tmpfile $testfile
 
        cancel_lru_locks
 
-       dd if=$testfile of=$resfile bs=4096 count=1 iflag=direct ||
+       dd if=$testfile of=$resfile bs=$pagesz count=1 iflag=direct ||
                error "could not read from file with O_DIRECT (3)"
        cmp -bl $tmpfile $resfile ||
                error "file $testfile is corrupted (3)"
@@ -3388,8 +3339,16 @@ test_47() {
                error "link from encrypted to unencrypted dir should succeed"
        rm -f $tmpfile
 
-       mrename $testfile2 $tmpfile ||
-               error "rename from encrypted to unencrypted dir should succeed"
+       # check we are limited in the number of hard links
+       # we can create for encrypted files, to what can fit into LinkEA
+       for i in $(seq 1 160); do
+               ln $testfile2 ${testfile}_$i || break
+       done
+       [ $i -lt 160 ] || error "hard link $i should fail"
+
+       mrename $testfile2 $tmpfile &&
+               error "rename from encrypted to unencrypted dir should fail"
+       touch $tmpfile
 
        dd if=/dev/zero of=$testfile bs=512K count=1
        mkdir $DIR/$tdir/mydir
@@ -3574,12 +3533,13 @@ trace_cmd() {
        local cmd="$@"
        local xattr_name="security.c"
 
-       cancel_lru_locks osc ; cancel_lru_locks mdc
+       cancel_lru_locks
        $LCTL set_param debug=+info
        $LCTL clear
 
        echo $cmd
        eval $cmd
+       [ $? -eq 0 ] || error "$cmd failed"
 
        $LCTL dk | grep -E "get xattr '${xattr_name}'|get xattrs"
        [ $? -ne 0 ] || error "get xattr event was triggered"
@@ -3607,21 +3567,29 @@ test_49() {
        trace_cmd $TRUNCATE $dirname/f1 10240
        trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
        trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
-       trace_cmd $LFS setdirstripe -i 1 $dirname/d2
-       trace_cmd $LFS migrate -m 0 $dirname/d2
-
-       $LFS setdirstripe -i 1 -c 1 $dirname/d3
-       dirname=$dirname/d3/subdir
-       mkdir $dirname
 
-       trace_cmd stat $dirname
-       trace_cmd touch $dirname/f1
-       trace_cmd stat $dirname/f1
-       trace_cmd cat $dirname/f1
-       dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
-       trace_cmd $TRUNCATE $dirname/f1 10240
-       trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
-       trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
+       if [[ $MDSCOUNT -gt 1 ]]; then
+               trace_cmd $LFS setdirstripe -i 1 $dirname/d2
+               trace_cmd $LFS migrate -m 0 $dirname/d2
+               touch $dirname/d2/subf
+               # migrate a non-empty encrypted dir
+               trace_cmd $LFS migrate -m 1 $dirname/d2
+
+               $LFS setdirstripe -i 1 -c 1 $dirname/d3
+               dirname=$dirname/d3/subdir
+               mkdir $dirname
+
+               trace_cmd stat $dirname
+               trace_cmd touch $dirname/f1
+               trace_cmd stat $dirname/f1
+               trace_cmd cat $dirname/f1
+               dd if=/dev/zero of=$dirname/f1 bs=1M count=10 conv=fsync
+               trace_cmd $TRUNCATE $dirname/f1 10240
+               trace_cmd $LFS setstripe -E -1 -S 4M $dirname/f2
+               trace_cmd $LFS migrate -E -1 -S 256K $dirname/f2
+       else
+               skip_noexit "2nd part needs >= 2 MDTs"
+       fi
 }
 run_test 49 "Avoid getxattr for encryption context"
 
@@ -4081,6 +4049,9 @@ cleanup_55() {
 }
 
 test_55() {
+       (( $MDS1_VERSION > $(version_code 2.12.6.2) )) ||
+               skip "Need MDS version at least 2.12.6.3"
+
        local client_ip
        local client_nid
 
@@ -4146,6 +4117,8 @@ run_test 55 "access with seteuid"
 test_56() {
        local testfile=$DIR/$tdir/$tfile
 
+       [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
+
        $LCTL get_param mdc.*.import | grep -q client_encryption ||
                skip "client encryption not supported"
 
@@ -4157,16 +4130,51 @@ test_56() {
        stack_trap cleanup_for_enc_tests EXIT
        setup_for_enc_tests
 
-       $LFS setstripe -c2 -i0 -S 1M $testfile
+       $LFS setstripe -c1 $testfile
        dd if=/dev/urandom of=$testfile bs=1M count=3 conv=fsync
        filefrag -v $testfile || error "filefrag $testfile failed"
-       (( $(filefrag -v $testfile | grep -c encrypted) >= 2 )) ||
+       (( $(filefrag -v $testfile | grep -c encrypted) >= 1 )) ||
                error "filefrag $testfile does not show encrypted flag"
-       (( $(filefrag -v $testfile | grep -c encoded) >= 2 )) ||
+       (( $(filefrag -v $testfile | grep -c encoded) >= 1 )) ||
                error "filefrag $testfile does not show encoded flag"
 }
 run_test 56 "FIEMAP on encrypted file"
 
+test_57() {
+       local testdir=$DIR/$tdir/mytestdir
+       local testfile=$DIR/$tdir/$tfile
+
+       [[ $(facet_fstype ost1) == zfs ]] && skip "skip ZFS backend"
+
+       $LCTL get_param mdc.*.import | grep -q client_encryption ||
+               skip "client encryption not supported"
+
+       mount.lustre --help |& grep -q "test_dummy_encryption:" ||
+               skip "need dummy encryption support"
+
+       mkdir $DIR/$tdir
+       mkdir $testdir
+       setfattr -n security.c -v myval $testdir &&
+               error "setting xattr on $testdir should have failed (1)"
+       touch $testfile
+       setfattr -n security.c -v myval $testfile &&
+               error "setting xattr on $testfile should have failed (1)"
+
+       rm -rf $DIR/$tdir
+
+       stack_trap cleanup_for_enc_tests EXIT
+       setup_for_enc_tests
+
+       mkdir $testdir
+       setfattr -n security.c -v myval $testdir &&
+               error "setting xattr on $testdir should have failed (2)"
+       touch $testfile
+       setfattr -n security.c -v myval $testfile &&
+               error "setting xattr on $testfile should have failed (2)"
+       return 0
+}
+run_test 57 "security.c xattr protection"
+
 log "cleanup: ======================================================"
 
 sec_unsetup() {