public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: IGT development <igt-dev@lists.freedesktop.org>
Cc: Daniel Vetter <daniel.vetter@intel.com>,
	Emil Velikov <emil.velikov@collabora.com>
Subject: [igt-dev] [PATCH i-g-t 6/6] lib/core_auth: mount namespace magic to make the test work everywhere
Date: Fri, 15 Feb 2019 10:54:48 +0100	[thread overview]
Message-ID: <20190215095448.13196-6-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <20190215095448.13196-1-daniel.vetter@ffwll.ch>

We're creating our own namespace and then create a copy of the chardev
that anyone can access before dropping root. Should hopefully work on
any system.

This way we're also guaranteed to open the right device again.

v2: mount(2) instead of mount(3).

Cc: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
---
 tests/core_auth.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/tests/core_auth.c b/tests/core_auth.c
index 0b9073cb0fce..bc2754ec30af 100644
--- a/tests/core_auth.c
+++ b/tests/core_auth.c
@@ -36,6 +36,8 @@
 #include <fcntl.h>
 #include <inttypes.h>
 #include <errno.h>
+#include <sched.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
@@ -243,17 +245,24 @@ static void test_unauth_vs_render(int master)
 {
 	int slave;
 	uint32_t handle;
+	struct stat statbuf;
+	bool has_render;
 
-	/*
-	 * FIXME: when drm_open_driver() fails to open() a node (insufficient
-	 * permissions or otherwise, it will igt_skip.
-	 * As of today, igt_skip and igt_fork do not work together.
-	 */
-	slave = __drm_open_driver(DRIVER_ANY);
-	/*
-	 * FIXME: relate to the master fd passed with the above open and fix
-	 * all of IGT.
-	 */
+	/* need to check for render nodes before we wreak the filesystem */
+	has_render = has_render_node(master);
+
+	/* create a card node matching master which (only) we can access as
+	 * non-root */
+	do_or_die(fstat(master, &statbuf));
+	do_or_die(unshare(CLONE_NEWNS));
+	do_or_die(mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL));
+	do_or_die(mount("none", "/dev/dri", "tmpfs", 0, NULL));
+	umask(0);
+	do_or_die(mknod("/dev/dri/card", S_IFCHR | 0777, statbuf.st_rdev));
+
+	igt_drop_root();
+
+	slave = open("/dev/dri/card", O_RDWR);
 
 	igt_assert(slave >= 0);
 
@@ -276,7 +285,7 @@ static void test_unauth_vs_render(int master)
 	 * Note: We are _not_ interested in the FD2HANDLE specific errno,
 	 * yet the EBADF check is added on the explicit request by danvet.
 	 */
-	if (has_render_node(slave))
+	if (has_render)
 		igt_assert(errno == EBADF);
 	else
 		igt_assert(errno == EACCES);
@@ -330,10 +339,8 @@ igt_main
 		igt_subtest("unauth-vs-render") {
 			check_auth_sanity(master);
 
-			igt_fork(child, 1) {
-				igt_drop_root();
+			igt_fork(child, 1)
 				test_unauth_vs_render(master);
-			}
 			igt_waitchildren();
 		}
 	}
-- 
2.20.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-02-15  9:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15  9:54 [igt-dev] [PATCH i-g-t 1/6] lib/tests: Add header for common helpers Daniel Vetter
2019-02-15  9:54 ` [igt-dev] [PATCH i-g-t 2/6] lib/tests: add internal_assert_wexited/wsignaled Daniel Vetter
2019-02-15  9:54 ` [igt-dev] [PATCH i-g-t 3/6] tests: drop invalid name build checks Daniel Vetter
2019-02-15  9:54 ` [igt-dev] [PATCH i-g-t 4/6] lib/tests: Convert no_exit tests into positive tests Daniel Vetter
2019-02-15  9:54 ` [igt-dev] [PATCH i-g-t 5/6] lib/tests: Add testcase for nonexisting subtest name Daniel Vetter
2019-02-15  9:54 ` Daniel Vetter [this message]
2019-02-15 15:48 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [i-g-t,1/6] lib/tests: Add header for common helpers Patchwork

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=20190215095448.13196-6-daniel.vetter@ffwll.ch \
    --to=daniel.vetter@ffwll.ch \
    --cc=daniel.vetter@intel.com \
    --cc=emil.velikov@collabora.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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