Commit 556f52f5fb for qemu.org

commit 556f52f5fb60dba3f2d133f953ef584d6c5a46bf
Author: Cédric Le Goater <clg@redhat.com>
Date:   Mon Nov 30 13:56:11 2026 +0100

    qemu-vmsr-helper: Actually drop privileges

    The uid and gid parsed from -u/--user and -g/--group are never used.
    clang 23 reports them as -Wunused-but-set-global:

    ../tools/i386/qemu-vmsr-helper.c:59:12: error: variable 'uid' set but not used [-Werror,-Wunused-but-set-global]
       59 | static int uid = -1;
          |            ^
    ../tools/i386/qemu-vmsr-helper.c:60:12: error: variable 'gid' set but not used [-Werror,-Wunused-but-set-global]
       60 | static int gid = -1;
          |            ^
    2 errors generated.

    The warning hides a real bug: drop_privileges() never calls
    capng_apply() and never switches to the requested user. Call
    capng_change_id() before capng_apply() so CAP_SYS_RAWIO survives the
    uid change.

    Fixes: 84369d762127 ("tools: build qemu-vmsr-helper")
    Cc: Anthony Harivel <aharivel@redhat.com>
    Reviewed-by: Peter Xu <peterx@redhat.com>
    Link: https://lore.kernel.org/qemu-devel/20261130125615.728947-2-clg@redhat.com
    Signed-off-by: Cédric Le Goater <clg@redhat.com>

diff --git a/tools/i386/qemu-vmsr-helper.c b/tools/i386/qemu-vmsr-helper.c
index f12fd3c3e8..7b65387f99 100644
--- a/tools/i386/qemu-vmsr-helper.c
+++ b/tools/i386/qemu-vmsr-helper.c
@@ -323,6 +323,16 @@ static int drop_privileges(void)
         return -1;
     }

+    if (uid != -1 || gid != -1) {
+        if (capng_change_id(uid, gid, CAPNG_DROP_SUPP_GRP) < 0) {
+            return -1;
+        }
+    }
+
+    if (capng_apply(CAPNG_SELECT_BOTH) != 0) {
+        return -1;
+    }
+
     return 0;
 }
 #endif