Skip to contentSkip to conversation

vl: defuse PID file path resolve error

PATCH Applied Fiona Ebner 3 participants 5 messages Oct 31, 2022 – Mar 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vl: defuse PID file path resolve error

Commit 85c4bf8aa6 ("vl: Unlink absolute PID file path") introduced a critical error when the PID file path cannot be resolved. Before this commit, it was possible to invoke QEMU when the PID file was a file created with mkstemp that was already unlinked at the time of the invocation. There might be other similar scenarios.

It should not be a critical error when the PID file unlink notifier can't be registered, because the path can't be resolved. If the file is already gone from QEMU's perspective, silently ignore the error. Otherwise, only print a warning.

Fixes 85c4bf8aa6 ("vl: Unlink absolute PID file path")

---

v1 -> v2:
* Ignore error if errno == ENOENT.

 softmmu/vl.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
softmmu/vl.c +5 -4
index b464da25bc..cf2c591ba5 100644
@@ -2432,10 +2432,11 @@ static void qemu_maybe_daemonize(const char *pid_file)
 
         pid_file_realpath = g_malloc0(PATH_MAX);
         if (!realpath(pid_file, pid_file_realpath)) {
-            error_report("cannot resolve PID file path: %s: %s",
-                         pid_file, strerror(errno));
-            unlink(pid_file);
-            exit(1);
+            if (errno != ENOENT) {
+                warn_report("not removing PID file on exit: cannot resolve PID "
+                            "file path: %s: %s", pid_file, strerror(errno));
+            }
+            return;
         }
 
         qemu_unlink_pidfile_notifier = (struct UnlinkPidfileNotifier) {
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Fiona Ebner

Commit 85c4bf8aa6 ("vl: Unlink absolute PID file path") introduced a critical error when the PID file path cannot be resolved. Before this commit, it was possible to invoke QEMU when the PID file was a file created with mkstemp that was already unlinked at the time of the invocation. There might be other similar scenarios.

It should not be a critical error when the PID file unlink notifier can't be registered, because the path can't be resolved. If the file is already gone from QEMU's perspective, silently ignore the error. Otherwise, only print a warning.

Fixes 85c4bf8aa6 ("vl: Unlink absolute PID file path")
Quoted 7 lines

---

v1 -> v2:
* Ignore error if errno == ENOENT.

  softmmu/vl.c | 9 +++++----
  1 file changed, 5 insertions(+), 4 deletions(-)
#2 lore raw
In reply to Fiona Ebner

Am 31.10.22 um 10:47 schrieb Fiona Ebner:

Quoted 33 lines

Commit 85c4bf8aa6 ("vl: Unlink absolute PID file path") introduced a critical error when the PID file path cannot be resolved. Before this commit, it was possible to invoke QEMU when the PID file was a file created with mkstemp that was already unlinked at the time of the invocation. There might be other similar scenarios.

It should not be a critical error when the PID file unlink notifier can't be registered, because the path can't be resolved. If the file is already gone from QEMU's perspective, silently ignore the error. Otherwise, only print a warning.

Fixes 85c4bf8aa6 ("vl: Unlink absolute PID file path")

---

v1 -> v2:
* Ignore error if errno == ENOENT.

 softmmu/vl.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
softmmu/vl.c +0 -2
index b464da25bc..cf2c591ba5 100644
@@ -2432,10 +2432,11 @@ static void qemu_maybe_daemonize(const char *pid_file)
 
         pid_file_realpath = g_malloc0(PATH_MAX);
         if (!realpath(pid_file, pid_file_realpath)) {
-            error_report("cannot resolve PID file path: %s: %s",
-                         pid_file, strerror(errno));

softmmu/vl.c static void qemu_maybe_daemonize(const char *pid_file) · line 2442

Quoted 10 lines
softmmu/vl.c +5 -2
-            unlink(pid_file);
-            exit(1);
+            if (errno != ENOENT) {
+                warn_report("not removing PID file on exit: cannot resolve PID "
+                            "file path: %s: %s", pid_file, strerror(errno));
+            }
+            return;
         }
 
         qemu_unlink_pidfile_notifier = (struct UnlinkPidfileNotifier) {

Ping

#3 lore raw

Am 24.01.23 um 14:55 schrieb Fiona Ebner:

Quoted 43 lines

Am 31.10.22 um 10:47 schrieb Fiona Ebner:

Quoted 42 lines

Commit 85c4bf8aa6 ("vl: Unlink absolute PID file path") introduced a critical error when the PID file path cannot be resolved. Before this commit, it was possible to invoke QEMU when the PID file was a file created with mkstemp that was already unlinked at the time of the invocation. There might be other similar scenarios.

It should not be a critical error when the PID file unlink notifier can't be registered, because the path can't be resolved. If the file is already gone from QEMU's perspective, silently ignore the error. Otherwise, only print a warning.

Fixes 85c4bf8aa6 ("vl: Unlink absolute PID file path")

---

v1 -> v2:
* Ignore error if errno == ENOENT.

 softmmu/vl.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
softmmu/vl.c +5 -4
index b464da25bc..cf2c591ba5 100644
@@ -2432,10 +2432,11 @@ static void qemu_maybe_daemonize(const char *pid_file)
 
         pid_file_realpath = g_malloc0(PATH_MAX);
         if (!realpath(pid_file, pid_file_realpath)) {
-            error_report("cannot resolve PID file path: %s: %s",
-                         pid_file, strerror(errno));
-            unlink(pid_file);
-            exit(1);
+            if (errno != ENOENT) {
+                warn_report("not removing PID file on exit: cannot resolve PID "
+                            "file path: %s: %s", pid_file, strerror(errno));
+            }
+            return;
         }
 
Quoted 4 lines

softmmu/vl.c static void qemu_maybe_daemonize(const char *pid_file) · line 2442

Quoted 1 line
softmmu/vl.c +0 -0
         qemu_unlink_pidfile_notifier = (struct UnlinkPidfileNotifier) {

Ping

Ping again. While it's not a critical patch, it's also not a big one :)

Best Regards,
Fiona