s3: Test for CVE-2017-2619 regression with "follow symlinks = no".
authorJeremy Allison <jra@samba.org>
Mon, 27 Mar 2017 18:48:25 +0000 (11:48 -0700)
committerUri Simchoni <uri@samba.org>
Tue, 28 Mar 2017 05:00:46 +0000 (07:00 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12721

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
Autobuild-User(master): Uri Simchoni <uri@samba.org>
Autobuild-Date(master): Tue Mar 28 07:00:46 CEST 2017 on sn-devel-144

selftest/target/Samba3.pm
source3/script/tests/test_smbclient_s3.sh

index d754b5f9ac18d762fac06a02a73021316bf3bef7..354f1527a705ff7822608776f159bd58a86614c8 100755 (executable)
@@ -1245,6 +1245,9 @@ sub provision($$$$$$$$)
        my $shadow_shrdir="$shadow_basedir/share";
        push(@dirs,$shadow_shrdir);
 
+       my $nosymlinks_shrdir="$shrdir/nosymlinks";
+       push(@dirs,$nosymlinks_shrdir);
+
        # this gets autocreated by winbindd
        my $wbsockdir="$prefix_abs/winbindd";
 
@@ -1861,6 +1864,11 @@ sub provision($$$$$$$$)
        copy = tmp
         mangled names = illegal
 
+[nosymlinks]
+       copy = tmp
+       path = $nosymlinks_shrdir
+       follow symlinks = no
+
 [kernel_oplocks]
        copy = tmp
        kernel oplocks = yes
index 22849bd503181c11155da2b10268d06e92361176..7d86a6134ae863ca458864ec20cfc743b0db91de 100755 (executable)
@@ -1096,6 +1096,75 @@ EOF
     fi
 }
 
+# Test follow symlinks can't access symlinks
+test_nosymlinks()
+{
+# Setup test dirs.
+    slink_name="$LOCAL_PATH/nosymlinks/source"
+    slink_target="$LOCAL_PATH/nosymlinks/target"
+    mkdir_target="$LOCAL_PATH/nosymlinks/a"
+
+    rm -f $slink_target
+    rm -f $slink_name
+    rm -rf $mkdir_target
+
+    touch $slink_target
+    ln -s $slink_target $slink_name
+
+# Getting a file through a symlink name should fail.
+    tmpfile=$PREFIX/smbclient_interactive_prompt_commands
+    cat > $tmpfile <<EOF
+get source
+quit
+EOF
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+       echo "$out"
+       echo "failed accessing nosymlinks with error $ret"
+       false
+       return
+    fi
+
+    echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
+    ret=$?
+    if [ $ret != 0 ] ; then
+       echo "$out"
+       echo "failed - should get NT_STATUS_ACCESS_DENIED getting \\nosymlinks\\source"
+       false
+    fi
+
+# But we should be able to create and delete directories.
+    cat > $tmpfile <<EOF
+mkdir a
+mkdir a\\b
+quit
+EOF
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret != 0 ] ; then
+       echo "$out"
+       echo "failed accessing nosymlinks with error $ret"
+       false
+       return
+    fi
+
+    echo "$out" | grep 'NT_STATUS'
+    ret=$?
+    if [ $ret == 0 ] ; then
+       echo "$out"
+       echo "failed - NT_STATUS_XXXX doing mkdir a; mkdir a\\b on \\nosymlinks"
+       false
+    fi
+}
 
 LOGDIR_PREFIX=test_smbclient_s3
 
@@ -1196,6 +1265,10 @@ testit "streams_depot can delete correctly" \
     test_streams_depot_delete || \
     failed=`expr $failed + 1`
 
+testit "follow symlinks = no" \
+    test_nosymlinks || \
+    failed=`expr $failed + 1`
+
 testit "rm -rf $LOGDIR" \
     rm -rf $LOGDIR || \
     failed=`expr $failed + 1`