[CRIU] [PATCH] zdtm: set additional groups along with uids and gids

Andrew Vagin avagin at parallels.com
Thu Dec 11 00:57:11 PST 2014


Acked-by: Andrew Vagin <avagin at parallels.com>

On Mon, Dec 08, 2014 at 06:13:54PM +0200, Ruslan Kuprieiev wrote:
> Currently zdtm doesn't set additional groups when running
> tests. It sets uids and gids to some non-root values, but
> additional groups remain untouched, which allows tests
> to inherit groups list, which leads to different
> behaviour depending on a way you run tests.
> 
> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
> ---
>  test/zdtm.sh         |  2 ++
>  test/zdtm/lib/test.c | 19 +++++++++++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/test/zdtm.sh b/test/zdtm.sh
> index aacdc71..7f3ef54 100755
> --- a/test/zdtm.sh
> +++ b/test/zdtm.sh
> @@ -475,10 +475,12 @@ start_test()
>  
>  	unset ZDTM_UID
>  	unset ZDTM_GID
> +	unset ZDTM_GROUPS
>  
>  	if ! echo $TEST_SUID_LIST | grep -q $tname; then
>  		export ZDTM_UID=18943
>  		export ZDTM_GID=58467
> +		export ZDTM_GROUPS="27495 48244"
>  		chmod a+w $tdir
>  	fi
>  
> diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c
> index 5d2a05d..60b67d8 100644
> --- a/test/zdtm/lib/test.c
> +++ b/test/zdtm/lib/test.c
> @@ -14,6 +14,7 @@
>  #include <sys/stat.h>
>  #include <string.h>
>  #include <sys/prctl.h>
> +#include <grp.h>
>  
>  #include "zdtmtst.h"
>  #include "lock.h"
> @@ -120,6 +121,24 @@ void test_init(int argc, char **argv)
>  		/* "3" -- run the test */
>  	}
>  
> +	val = getenv("ZDTM_GROUPS");
> +	if (val) {
> +		char *tok = NULL;
> +		unsigned int size = 0, groups[NGROUPS_MAX];
> +
> +		tok = strtok(val, " ");
> +		while (tok) {
> +			size++;
> +			groups[size - 1] = atoi(tok);
> +			tok = strtok(NULL, " ");
> +		}
> +
> +		if (setgroups(size, groups)) {
> +			fprintf(stderr, "Can't set groups: %m");
> +			exit(1);
> +		}
> +	}
> +
>  	val = getenv("ZDTM_GID");
>  	if (val && (setgid(atoi(val)) == -1)) {
>  		fprintf(stderr, "Can't set gid: %m");
> -- 
> 1.9.3
> 


More information about the CRIU mailing list