diff mbox series

[mickledore,13/27] runqemu: check permissions of available render nodes as well as their presence

Message ID 12ae43abbc4e7d6184198a912487ace3a4e66e50.1697233866.git.steve@sakoman.com
State New
Headers show
Series [mickledore,01/27] tiff: fix CVE-2023-40745 | expand

Commit Message

Steve Sakoman Oct. 13, 2023, 9:52 p.m. UTC
From: Alexander Kanavin <alex.kanavin@gmail.com>

qemu itself is not helpful when render nodes exist, but can't be opened:

qemu-system-x86_64: egl: render node init failed

To fix this, users likely need to

 * modprobe vgem (presence when physical graphic card is absent or has a driver without
support for render nodes, such as many older cards found in server machines)

 * add their user to "render" group to write to /dev/dri/renderD* (permissions)

With this change runqemu should print hints for the above as appropriate from probing the nodes.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
(cherry picked from commit acd85925cb197b7a31a25b60e8de762e2c3697ef)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
---
 scripts/runqemu | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/scripts/runqemu b/scripts/runqemu
index ef24ddc6b2..ea44600e64 100755
--- a/scripts/runqemu
+++ b/scripts/runqemu
@@ -1374,8 +1374,18 @@  to your build configuration.
         render_hint = """If /dev/dri/renderD* is absent due to lack of suitable GPU, 'modprobe vgem' will create one suitable for mesa llvmpipe software renderer."""
         try:
             content = os.listdir("/dev/dri")
-            if len([i for i in content if i.startswith('render')]) == 0:
-                raise RunQemuError("No render nodes found in /dev/dri: %s. %s" %(content, render_hint))
+            nodes = [i for i in content if i.startswith('renderD')]
+            if len(nodes) == 0:
+                raise RunQemuError("No render nodes found in /dev/dri/: %s. %s" %(content, render_hint))
+            for n in nodes:
+                try:
+                    with open(os.path.join("/dev/dri", n), "w") as f:
+                        f.close()
+                        break
+                except IOError:
+                    pass
+            else:
+                raise RunQemuError("None of the render nodes in /dev/dri/ are accessible: %s; you may need to add yourself to 'render' group or otherwise ensure you have read-write permissions on one of them." %(nodes))
         except FileNotFoundError:
             raise RunQemuError("/dev/dri directory does not exist; no render nodes available on this machine. %s" %(render_hint))