public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel@ffwll.ch>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] tests/gem_reset_stats: check non root access to reset_stats
Date: Wed, 20 Nov 2013 21:32:03 +0100	[thread overview]
Message-ID: <20131120203203.GE27344@phenom.ffwll.local> (raw)
In-Reply-To: <1384959497-25533-3-git-send-email-mika.kuoppala@intel.com>

On Wed, Nov 20, 2013 at 04:58:17PM +0200, Mika Kuoppala wrote:
> Getting global reset count needs to be tested with root and
> non root access.
> 
> Signed-off-by: Mika Kuoppala <mika.kuoppala@intel.com>

All merged to igt, thanks for the patches.
-Daniel
> ---
>  tests/gem_reset_stats.c |   70 +++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 61 insertions(+), 9 deletions(-)
> 
> diff --git a/tests/gem_reset_stats.c b/tests/gem_reset_stats.c
> index 9e52b60..5252833 100644
> --- a/tests/gem_reset_stats.c
> +++ b/tests/gem_reset_stats.c
> @@ -637,6 +637,17 @@ static void test_close_pending(void)
>  	close(fd);
>  }
>  
> +static void drop_root(void)
> +{
> +	igt_assert(getuid() == 0);
> +
> +	igt_assert(setgid(2) == 0);
> +	igt_assert(setuid(2) == 0);
> +
> +	igt_assert(getgid() == 2);
> +	igt_assert(getuid() == 2);
> +}
> +
>  static void __test_count(const bool create_ctx)
>  {
>  	int fd, h, ctx;
> @@ -661,9 +672,21 @@ static void __test_count(const bool create_ctx)
>  	assert_reset_status(fd, ctx, RS_BATCH_ACTIVE);
>  	c2 = get_reset_count(fd, ctx);
>  	igt_assert(c2 >= 0);
> -
>  	igt_assert(c2 == (c1 + 1));
>  
> +	igt_fork(child, 1) {
> +		drop_root();
> +
> +		c2 = get_reset_count(fd, ctx);
> +
> +		if (ctx == 0)
> +			igt_assert(c2 == -EPERM);
> +		else
> +			igt_assert(c2 == 0);
> +	}
> +
> +	igt_waitchildren();
> +
>  	gem_close(fd, h);
>  
>  	if (create_ctx)
> @@ -710,16 +733,50 @@ static int _test_params(int fd, int ctx, uint32_t flags, uint32_t pad)
>  	return 0;
>  }
>  
> -static void test_param_ctx(int fd, int ctx)
> +typedef enum { root = 0, user } cap_t;
> +
> +static void test_param_ctx(const int fd, const int ctx, const cap_t cap)
>  {
>  	const uint32_t bad = rand() + 1;
>  
> -	igt_assert(_test_params(fd, ctx, 0, 0) == 0);
> +	if (ctx == 0) {
> +		if (cap == root)
> +			igt_assert(_test_params(fd, ctx, 0, 0) == 0);
> +		else
> +			igt_assert(_test_params(fd, ctx, 0, 0) == -EPERM);
> +	}
> +
>  	igt_assert(_test_params(fd, ctx, 0, bad) == -EINVAL);
>  	igt_assert(_test_params(fd, ctx, bad, 0) == -EINVAL);
>  	igt_assert(_test_params(fd, ctx, bad, bad) == -EINVAL);
>  }
>  
> +static void check_params(const int fd, const int ctx, cap_t cap)
> +{
> +	igt_assert(ioctl(fd, GET_RESET_STATS_IOCTL, 0) == -1);
> +	igt_assert(_test_params(fd, 0xbadbad, 0, 0) == -ENOENT);
> +
> +	test_param_ctx(fd, 0, cap);
> +	test_param_ctx(fd, ctx, cap);
> +}
> +
> +static void _test_param(const int fd, const int ctx)
> +{
> +	check_params(fd, ctx, root);
> +
> +	igt_fork(child, 1) {
> +		check_params(fd, ctx, root);
> +
> +		drop_root();
> +
> +		check_params(fd, ctx, user);
> +	}
> +
> +	check_params(fd, ctx, root);
> +
> +	igt_waitchildren();
> +}
> +
>  static void test_params(void)
>  {
>  	int fd, ctx;
> @@ -728,12 +785,7 @@ static void test_params(void)
>  	igt_assert(fd >= 0);
>  	ctx = context_create(fd);
>  
> -	igt_assert(ioctl(fd, GET_RESET_STATS_IOCTL, 0) == -1);
> -
> -	igt_assert(_test_params(fd, 0xbadbad, 0, 0) == -ENOENT);
> -
> -	test_param_ctx(fd, 0);
> -	test_param_ctx(fd, ctx);
> +	_test_param(fd, ctx);
>  
>  	close(fd);
>  }
> -- 
> 1.7.9.5
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

      reply	other threads:[~2013-11-20 20:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 14:58 [PATCH 1/3] tests/gem_reset_stats: add support for BDW+ Mika Kuoppala
2013-11-20 14:58 ` [PATCH 2/3] tests/gem_reset_stats: stop rings after injecting hang Mika Kuoppala
2013-11-20 14:58 ` [PATCH 3/3] tests/gem_reset_stats: check non root access to reset_stats Mika Kuoppala
2013-11-20 20:32   ` Daniel Vetter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131120203203.GE27344@phenom.ffwll.local \
    --to=daniel@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=mika.kuoppala@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox