From 2726fb6338be8bb5d1b5867c3bbbc574333e9186 Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Mon, 6 May 2019 20:07:58 +0900 Subject: [PATCH] LU-12266 mdd: fix up non-dir creation in SGID dirs sgid directories have special semantics, making newly created files in the directory belong to the group of the directory, and newly created subdirectories will also become sgid. This is historically used for group-shared directories. But group directories writable by non-group members should not imply that such non-group members can magically join the group, so make sure to clear the sgid bit on non-directories for non-members (but remember that sgid without group execute means "mandatory locking", just to confuse things even more). Adapt fix from inode_init_owner() to use in mdd_create_sanity_check(). Lustre-change: https://review.whamcloud.com/34809 Lustre-commit: 534f10e45ab1f575a0a0c81964d4792ec33696fa Linux-commit: 0fa3ecd87848c9c93c2c828ef4c3a8ca36ce46c7 Signed-off-by: Sebastien Buisson Change-Id: Iae253c5cc7865fc81574760ce0ed4d93698b7314 Reviewed-by: Andreas Dilger Reviewed-by: Patrick Farrell Reviewed-on: https://review.whamcloud.com/34830 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/mdd/mdd_dir.c | 15 ++++++++++++++- lustre/tests/sanity.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/lustre/mdd/mdd_dir.c b/lustre/mdd/mdd_dir.c index 0bd6fa3..0c0d7bf 100644 --- a/lustre/mdd/mdd_dir.c +++ b/lustre/mdd/mdd_dir.c @@ -42,6 +42,7 @@ #include #include #include +#include #include "mdd_internal.h" @@ -1958,12 +1959,24 @@ static int mdd_create_sanity_check(const struct lu_env *env, if (rc != 0) RETURN(rc); - /* sgid check */ + /* sgid check */ if (pattr->la_mode & S_ISGID) { + struct lu_ucred *uc = lu_ucred(env); + cattr->la_gid = pattr->la_gid; + + /* Directories are special, and always inherit S_ISGID */ if (S_ISDIR(cattr->la_mode)) { cattr->la_mode |= S_ISGID; cattr->la_valid |= LA_MODE; + } else if ((cattr->la_mode & (S_ISGID | S_IXGRP)) + == (S_ISGID | S_IXGRP) && + !lustre_in_group_p(uc, + (cattr->la_valid & LA_GID) ? + cattr->la_gid : pattr->la_gid) && + !md_capable(uc, CFS_CAP_FSETID)) { + cattr->la_mode &= ~S_ISGID; + cattr->la_valid |= LA_MODE; } } diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index 2b8e3c0..4c0c95b 100755 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -16934,6 +16934,34 @@ test_410() } run_test 410 "Test inode number returned from kernel thread" +test_420() +{ + [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.7) ]] && + skip "Need MDS version at least 2.10.7" && return + + local SAVE_UMASK=$(umask) + local dir=$DIR/$tdir + local uname=$(getent passwd $RUNAS_ID | cut -d: -f1) + + mkdir -p $dir + umask 0000 + mkdir -m03777 $dir/testdir + ls -dn $dir/testdir + local dirperms=$(ls -dn $dir/testdir | awk '{print $1}') + [ $dirperms == "drwxrwsrwt" ] || + error "incorrect perms on $dir/testdir" + + $PDSH ${uname}@localhost "PATH=$LUSTRE/tests:\$PATH; \ + openfile -f O_RDONLY:O_CREAT -m 02755 $dir/testdir/testfile" + ls -n $dir/testdir/testfile + local fileperms=$(ls -n $dir/testdir/testfile | awk '{print $1}') + [ $fileperms == "-rwxr-xr-x" ] || + error "incorrect perms on $dir/testdir/testfile" + + umask $SAVE_UMASK +} +run_test 420 "clear SGID bit on non-directories for non-members" + prep_801() { [[ $(lustre_version_code mds1) -lt $(version_code 2.9.55) ]] || [[ $(lustre_version_code ost1) -lt $(version_code 2.9.55) ]] && -- 1.8.3.1