3a9410
From c70b1a8d8a4bc34bcbf9ef4bccac678257b8c494 Mon Sep 17 00:00:00 2001
3a9410
Message-Id: <c70b1a8d8a4bc34bcbf9ef4bccac678257b8c494@dist-git>
3a9410
From: Vasiliy Ulyanov <vulyanov@suse.de>
3a9410
Date: Wed, 2 Feb 2022 17:28:17 +0100
3a9410
Subject: [PATCH] qemu: gpu: Get pid without binary validation
3a9410
3a9410
The binary validation in virPidFileReadPathIfAlive may fail with EACCES
3a9410
if the calling process does not have CAP_SYS_PTRACE capability.
3a9410
Therefore instead do only the check that the pidfile is locked by the
3a9410
correct process.
3a9410
3a9410
Fixes the same issue as with swtpm.
3a9410
3a9410
Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
3a9410
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
(cherry picked from commit e3dfa52d260da8a41a0ec35767d08e37c825824a)
3a9410
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2152188
3a9410
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3a9410
---
3a9410
 src/qemu/qemu_vhost_user_gpu.c | 9 +++------
3a9410
 1 file changed, 3 insertions(+), 6 deletions(-)
3a9410
3a9410
diff --git a/src/qemu/qemu_vhost_user_gpu.c b/src/qemu/qemu_vhost_user_gpu.c
3a9410
index ef198a4820..f7d444e851 100644
3a9410
--- a/src/qemu/qemu_vhost_user_gpu.c
3a9410
+++ b/src/qemu/qemu_vhost_user_gpu.c
3a9410
@@ -54,7 +54,6 @@ qemuVhostUserGPUCreatePidFilename(const char *stateDir,
3a9410
 
3a9410
 /*
3a9410
  * qemuVhostUserGPUGetPid:
3a9410
- * @binpath: path of executable associated with the pidfile
3a9410
  * @stateDir: the directory where vhost-user-gpu writes the pidfile into
3a9410
  * @shortName: short name of the domain
3a9410
  * @alias: video device alias
3a9410
@@ -65,8 +64,7 @@ qemuVhostUserGPUCreatePidFilename(const char *stateDir,
3a9410
  * set to -1;
3a9410
  */
3a9410
 static int
3a9410
-qemuVhostUserGPUGetPid(const char *binPath,
3a9410
-                       const char *stateDir,
3a9410
+qemuVhostUserGPUGetPid(const char *stateDir,
3a9410
                        const char *shortName,
3a9410
                        const char *alias,
3a9410
                        pid_t *pid)
3a9410
@@ -76,7 +74,7 @@ qemuVhostUserGPUGetPid(const char *binPath,
3a9410
     if (!(pidfile = qemuVhostUserGPUCreatePidFilename(stateDir, shortName, alias)))
3a9410
         return -1;
3a9410
 
3a9410
-    if (virPidFileReadPathIfAlive(pidfile, pid, binPath) < 0)
3a9410
+    if (virPidFileReadPathIfLocked(pidfile, pid) < 0)
3a9410
         return -1;
3a9410
 
3a9410
     return 0;
3a9410
@@ -253,8 +251,7 @@ qemuExtVhostUserGPUSetupCgroup(virQEMUDriver *driver,
3a9410
     if (!shortname)
3a9410
         return -1;
3a9410
 
3a9410
-    rc = qemuVhostUserGPUGetPid(video->driver->vhost_user_binary,
3a9410
-                                cfg->stateDir, shortname, video->info.alias, &pid;;
3a9410
+    rc = qemuVhostUserGPUGetPid(cfg->stateDir, shortname, video->info.alias, &pid;;
3a9410
     if (rc < 0 || (rc == 0 && pid == (pid_t)-1)) {
3a9410
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
3a9410
                        _("Could not get process id of vhost-user-gpu"));
3a9410
-- 
3a9410
2.39.0
3a9410