Skip to contentSkip to conversation

Fix build with clang 23

PATCH Applied Cédric Le Goater 4 participants 12 messages Nov 30 – Dec 2

lore
Share & tools
lore
#1 lore raw

PATCH 1/5 qemu-vmsr-helper: Actually drop privileges

In reply to Cédric Le Goater

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 <[email protected]>
---
 tools/i386/qemu-vmsr-helper.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/i386/qemu-vmsr-helper.c +10 -0
index f12fd3c3e816..7b65387f9938 100644
@@ -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
Signature · 1 line
2.56.1
#4 lore raw

PATCH 3/5 tests/qtest/migration: Drop orphaned tmpfs global

In reply to Cédric Le Goater

tmpfs has no users left since the unix migration tests derive the socket path from MigrationTestEnv (commit 718b9e4eb6bc and friends). clang 23 reports the leftover as -Wunused-but-set-global:

../tests/qtest/migration/compression-tests.c:21:14: error: variable 'tmpfs' set but not used [-Werror,-Wunused-but-set-global]
21 | static char *tmpfs;
| ^
1 error generated.

Remove the leftover global.

---
 tests/qtest/migration/compression-tests.c | 5 -----
 1 file changed, 5 deletions(-)
tests/qtest/migration/compression-tests.c +0 -5
index 848576054ff9..9aa5063871e8 100644
@@ -17,9 +17,6 @@
 #include "migration/migration-util.h"
 #include "qemu/module.h"
 
-
-static char *tmpfs;
-
 static void set_multifd_compression(QTestState *from, QTestState *to,
                                     const char *method)
 {
@@ -174,8 +171,6 @@ static void migration_test_add_compression_smoke(MigrationTestEnv *env)
 
 void migration_test_add_compression(MigrationTestEnv *env)
 {
-    tmpfs = env->tmpfs;
-
     migration_test_add_compression_smoke(env);
 
     if (!env->full_set) {
Signature · 1 line
2.56.1
#6 lore raw

PATCH 4/5 tests/unit/test-qtree: Drop unused destroy counters

In reply to Cédric Le Goater

destroyed_key_count and destroyed_value_count have been incremented in the key and value destroy notifies since the QTree import (commit e3feb2cc224f) but never checked. clang 23 reports them as -Wunused-but-set-global:

../tests/unit/test-qtree.c:42:14: error: variable 'destroyed_key_count' set but not used [-Werror,-Wunused-but-set-global]
42 | static guint destroyed_key_count;
| ^
../tests/unit/test-qtree.c:43:14: error: variable 'destroyed_value_count' set but not used [-Werror,-Wunused-but-set-global]
43 | static guint destroyed_value_count;
| ^
2 errors generated.

---
 tests/unit/test-qtree.c | 4 ----
 1 file changed, 4 deletions(-)
tests/unit/test-qtree.c +0 -4
index 4d836d22c717..1f506ac72ef5 100644
@@ -39,19 +39,15 @@ static gint my_search(gconstpointer a, gconstpointer b)
 
 static gpointer destroyed_key;
 static gpointer destroyed_value;
-static guint destroyed_key_count;
-static guint destroyed_value_count;
 
 static void my_key_destroy(gpointer key)
 {
     destroyed_key = key;
-    destroyed_key_count++;
 }
 
 static void my_value_destroy(gpointer value)
 {
     destroyed_value = value;
-    destroyed_value_count++;
 }
 
 static gint my_traverse(gpointer key, gpointer value, gpointer data)
Signature · 1 line
2.56.1
#0 lore raw

cover Fix build with clang 23

Hello,

clang 23 extended -Wunused-but-set-variable to file scope statics (-Wunused-but-set-global), failing the build on five set-but-never- read variables. Four are dead code; qemu-vmsr-helper is a real bug, the helper never dropped privileges.

These are long standing issues, so I would say not stable candidates, but it would be nice to have them in 11.2.

Cheers,

C.

Cédric Le Goater (5):
qemu-vmsr-helper: Actually drop privileges
qemu-keymap: Drop unused ctrl modifier tests/qtest/migration: Drop orphaned tmpfs global tests/unit/test-qtree: Drop unused destroy counters tests/unit/test-rcu-list: Drop unused n_nodes/n_updates counters

 qemu-keymap.c                             |  2 --
 tests/qtest/migration/compression-tests.c |  5 -----
 tests/unit/test-qtree.c                   |  4 ----
 tests/unit/test-rcu-list.c                | 11 -----------
 tools/i386/qemu-vmsr-helper.c             | 10 ++++++++++
 5 files changed, 10 insertions(+), 22 deletions(-)
Signature · 1 line
2.56.1
#7 lore raw

PATCH 5/5 tests/unit/test-rcu-list: Drop unused n_nodes/n_updates counters

n_nodes lost its last user when commit 8a5956ad6392 ("rcu tests: fix compilation on 32-bit ppc") dropped the "val" list member; n_updates was never read. clang 23 reports them as -Wunused-but-set-global:

../tests/unit/test-rcu-list.c:34:18: error: variable 'n_updates' set but not used [-Werror,-Wunused-but-set-global]
34 | static long long n_updates = 0LL;
| ^
../tests/unit/test-rcu-list.c:37:18: error: variable 'n_nodes' set but not used [-Werror,-Wunused-but-set-global]
37 | static long long n_nodes = 0LL;
| ^
2 errors generated.

Remove both globals and the local accumulators feeding them.

---
 tests/unit/test-rcu-list.c | 11 -----------
 1 file changed, 11 deletions(-)
tests/unit/test-rcu-list.c +0 -11
index 8dde3e61a84b..e0c2778d47db 100644
@@ -31,10 +31,8 @@
 
 static QemuMutex counts_mutex;
 static long long n_reads = 0LL;
-static long long n_updates = 0LL;
 static int64_t n_reclaims;
 static int64_t n_nodes_removed;
-static long long n_nodes = 0LL;
 static int g_test_in_charge = 0;
 
 static int nthreadsrunning;
@@ -200,8 +198,6 @@ static void *rcu_q_reader(void *arg)
 static void *rcu_q_updater(void *arg)
 {
     int j, target_el;
-    long long n_nodes_local = 0;
-    long long n_updates_local = 0;
     long long n_removed_local = 0;
     struct list_element *el, *prev_el;
 
@@ -234,19 +230,15 @@ static void *rcu_q_updater(void *arg)
             j++;
             if (target_el == j) {
                 struct list_element *new_el = g_new(struct list_element, 1);
-                n_nodes_local++;
                 TEST_LIST_INSERT_AFTER_RCU(el, new_el, entry);
                 break;
             }
         }
 
-        n_updates_local += 2;
         synchronize_rcu();
     }
     synchronize_rcu();
     qemu_mutex_lock(&counts_mutex);
-    n_nodes += n_nodes_local;
-    n_updates += n_updates_local;
     qatomic_set(&n_nodes_removed, n_nodes_removed + n_removed_local);
     qemu_mutex_unlock(&counts_mutex);
     return NULL;
@@ -262,9 +254,6 @@ static void rcu_qtest_init(void)
         new_el = g_new(struct list_element, 1);
         TEST_LIST_INSERT_HEAD_RCU(&Q_list_head, new_el, entry);
     }
-    qemu_mutex_lock(&counts_mutex);
-    n_nodes += RCU_Q_LEN;
-    qemu_mutex_unlock(&counts_mutex);
 }
 
 static void rcu_qtest_run(int duration, int nreaders)
Signature · 1 line
2.56.1
#3 lore raw

PATCH 2/5 qemu-keymap: Drop unused ctrl modifier

In reply to Cédric Le Goater

The ctrl modifier mask has been set but never read since the tool was added in commit 6a021536e239 ("tools: add qemu-keymap"). This went unnoticed until clang 23 extended -Wunused-but-set-variable to file scope statics as -Wunused-but-set-global:

../qemu-keymap.c:28:23: error: variable 'ctrl' set but not used [-Werror,-Wunused-but-set-global]
28 | static xkb_mod_mask_t ctrl;
| ^
1 error generated.

Remove the dead variable.

---
 qemu-keymap.c | 2 --
 1 file changed, 2 deletions(-)
qemu-keymap.c +0 -2
index d63b6be8ce32..af3519fa0529 100644
@@ -25,7 +25,6 @@ struct xkb_rule_names names = {
 };
 
 static xkb_mod_mask_t shift;
-static xkb_mod_mask_t ctrl;
 static xkb_mod_mask_t altgr;
 static xkb_mod_mask_t numlock;
 
@@ -227,7 +226,6 @@ int main(int argc, char *argv[])
     }
 
     shift = get_mod(map, "Shift");
-    ctrl = get_mod(map, "Control");
     altgr = get_mod(map, "AltGr");
     if (!altgr) {
         altgr = get_mod(map, "Mod5");
Signature · 1 line
2.56.1
#8 lore raw
In reply to Cédric Le Goater
Quoted 21 lines · Cédric Le Goater

Hello,

clang 23 extended -Wunused-but-set-variable to file scope statics (-Wunused-but-set-global), failing the build on five set-but-never- read variables. Four are dead code; qemu-vmsr-helper is a real bug, the helper never dropped privileges.

These are long standing issues, so I would say not stable candidates, but it would be nice to have them in 11.2.

Cheers,

C.

Cédric Le Goater (5):
qemu-vmsr-helper: Actually drop privileges
qemu-keymap: Drop unused ctrl modifier tests/qtest/migration: Drop orphaned tmpfs global tests/unit/test-qtree: Drop unused destroy counters tests/unit/test-rcu-list: Drop unused n_nodes/n_updates counters

Quoted 7 lines
  qemu-keymap.c                             |  2 --
  tests/qtest/migration/compression-tests.c |  5 -----
  tests/unit/test-qtree.c                   |  4 ----
  tests/unit/test-rcu-list.c                | 11 -----------
  tools/i386/qemu-vmsr-helper.c             | 10 ++++++++++
  5 files changed, 10 insertions(+), 22 deletions(-)

Drat. I thought I was done :/

../disas/mips.c:3984:12: error: variable 'mips_processor' set but not used [-Werror,-Wunused-but-set-global]
3984 | static int mips_processor;
| ^
../disas/mips.c:3985:12: error: variable 'mips_isa' set but not used [-Werror,-Wunused-but-set-global]
3985 | static int mips_isa;
| ^
../linux-user/arm/signal.c:98:16: error: variable 'sigreturn_fdpic_tramp' set but not used [-Werror,-Wunused-but-set-global]
98 | static abi_ptr sigreturn_fdpic_tramp;
| ^
../linux-user/arm/signal.c:98:16: error: variable 'sigreturn_fdpic_tramp' set but not used [-Werror,-Wunused-but-set-global]
98 | static abi_ptr sigreturn_fdpic_tramp;
| ^
../target/or1k/translate.c:80:17: error: variable 'cpu_sr' set but not used [-Werror,-Wunused-but-set-global]
80 | static TCGv_i32 cpu_sr;
| ^
../target/or1k/translate.c:90:17: error: variable 'fpcsr' set but not used [-Werror,-Wunused-but-set-global]
90 | static TCGv_i32 fpcsr;
| ^
../target/or1k/translate.c:80:17: error: variable 'cpu_sr' set but not used [-Werror,-Wunused-but-set-global]
80 | static TCGv_i32 cpu_sr;
| ^
../target/or1k/translate.c:90:17: error: variable 'fpcsr' set but not used [-Werror,-Wunused-but-set-global]
90 | static TCGv_i32 fpcsr;
| ^
../target/rx/translate.c:68:28: error: variable 'cpu_psw_pm' set but not used [-Werror,-Wunused-but-set-global]
68 | static TCGv_i32 cpu_psw_i, cpu_psw_pm, cpu_psw_u, cpu_psw_ipl;
| ^
../target/i386/kvm/kvm.c:149:12: error: variable 'lm_capable_kernel' set but not used [-Werror,-Wunused-but-set-global]
149 | static int lm_capable_kernel;
| ^
../target/hppa/translate.c:261:17: error: variable 'cpu_srH' set but not used [-Werror,-Wunused-but-set-global]
261 | static TCGv_i64 cpu_srH;
| ^
../target/tricore/translate.c:48:17: error: variable 'cpu_PCXI' set but not used [-Werror,-Wunused-but-set-global]
48 | static TCGv_i32 cpu_PCXI;
| ^
../target/tricore/translate.c:49:17: error: variable 'cpu_PSW' set but not used [-Werror,-Wunused-but-set-global]
49 | static TCGv_i32 cpu_PSW;

This needs to be fully addressed, so not for QEMU 11.2.

C.

Reviewed-by on v1 3/5
#5 lore raw

Re: [PATCH 3/5] tests/qtest/migration: Drop orphaned tmpfs global

In reply to Cédric Le Goater
Quoted 31 lines · Cédric Le Goater

tmpfs has no users left since the unix migration tests derive the socket path from MigrationTestEnv (commit 718b9e4eb6bc and friends). clang 23 reports the leftover as -Wunused-but-set-global:

../tests/qtest/migration/compression-tests.c:21:14: error: variable 'tmpfs' set but not used [-Werror,-Wunused-but-set-global]
21 | static char *tmpfs;
| ^
1 error generated.

Remove the leftover global.

---
 tests/qtest/migration/compression-tests.c | 5 -----
 1 file changed, 5 deletions(-)
tests/qtest/migration/compression-tests.c +0 -3
index 848576054ff9..9aa5063871e8 100644
@@ -17,9 +17,6 @@
 #include "migration/migration-util.h"
 #include "qemu/module.h"
 
-
-static char *tmpfs;
-
 static void set_multifd_compression(QTestState *from, QTestState *to,
                                     const char *method)
 {

tests/qtest/migration/compression-tests.c static void migration_test_add_compression_smoke(MigrationTestEnv *env) · line 176

Quoted 8 lines
tests/qtest/migration/compression-tests.c +0 -2
@@ -174,8 +171,6 @@ static void migration_test_add_compression_smoke(MigrationTestEnv *env)
 
 void migration_test_add_compression(MigrationTestEnv *env)
 {
-    tmpfs = env->tmpfs;
-
     migration_test_add_compression_smoke(env);
 
     if (!env->full_set) {
#10 lore raw
Quoted 10 lines · Peter Xu
Quoted 1 line · Cédric Le Goater

Drat. I thought I was done :/

:-(

Quoted 1 line

This needs to be fully addressed, so not for QEMU 11.2.

For the existing five, feel free to take,

ok then, I will send these with a few other VFIO patches tomorrow. It's good to take anyhow.

Thanks,

C.

author Applied
#11 lore raw
In reply to Cédric Le Goater
Quoted 21 lines · Cédric Le Goater

Hello,

clang 23 extended -Wunused-but-set-variable to file scope statics (-Wunused-but-set-global), failing the build on five set-but-never- read variables. Four are dead code; qemu-vmsr-helper is a real bug, the helper never dropped privileges.

These are long standing issues, so I would say not stable candidates, but it would be nice to have them in 11.2.

Cheers,

C.

Cédric Le Goater (5):
qemu-vmsr-helper: Actually drop privileges
qemu-keymap: Drop unused ctrl modifier tests/qtest/migration: Drop orphaned tmpfs global tests/unit/test-qtree: Drop unused destroy counters tests/unit/test-rcu-list: Drop unused n_nodes/n_updates counters

Quoted 7 lines
  qemu-keymap.c                             |  2 --
  tests/qtest/migration/compression-tests.c |  5 -----
  tests/unit/test-qtree.c                   |  4 ----
  tests/unit/test-rcu-list.c                | 11 -----------
  tools/i386/qemu-vmsr-helper.c             | 10 ++++++++++
  5 files changed, 10 insertions(+), 22 deletions(-)

Applied to vfio-next.

Thanks,

C.

#2 lore raw

Re: [PATCH 1/5] qemu-vmsr-helper: Actually drop privileges

In reply to Cédric Le Goater
Quoted 16 lines · Cédric Le Goater

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.

Quoted 6 lines
Fixes 84369d762127 ("tools: build qemu-vmsr-helper")
Cc Anthony Harivel <[email protected]>
---
  tools/i386/qemu-vmsr-helper.c | 10 ++++++++++
  1 file changed, 10 insertions(+)

This feels like a good candidate for the stable qemu series, and maybe even worth a CVE?

(I'm picking it up for the stable series).

Thanks,

/mjt