From patchwork Wed Nov 20 14:58:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mika Kuoppala X-Patchwork-Id: 3213381 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 164369F26C for ; Wed, 20 Nov 2013 14:58:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 66B9F20767 for ; Wed, 20 Nov 2013 14:58:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 25F272076B for ; Wed, 20 Nov 2013 14:58:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B7B1105F41; Wed, 20 Nov 2013 06:58:36 -0800 (PST) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B09D106950 for ; Wed, 20 Nov 2013 06:58:33 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 20 Nov 2013 06:58:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.93,737,1378882800"; d="scan'208";a="436679293" Received: from rosetta.fi.intel.com (HELO rosetta) ([10.237.72.60]) by fmsmga002.fm.intel.com with ESMTP; 20 Nov 2013 06:58:30 -0800 Received: by rosetta (Postfix, from userid 1000) id 8E59F8006F; Wed, 20 Nov 2013 16:58:34 +0200 (EET) From: Mika Kuoppala To: intel-gfx@lists.freedesktop.org Date: Wed, 20 Nov 2013 16:58:17 +0200 Message-Id: <1384959497-25533-3-git-send-email-mika.kuoppala@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1384959497-25533-1-git-send-email-mika.kuoppala@intel.com> References: <1384959497-25533-1-git-send-email-mika.kuoppala@intel.com> Subject: [Intel-gfx] [PATCH 3/3] tests/gem_reset_stats: check non root access to reset_stats X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: intel-gfx-bounces@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Getting global reset count needs to be tested with root and non root access. Signed-off-by: Mika Kuoppala --- 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); }