Skip to contentSkip to conversation

util/qht: fix possible NULL pointer dereference in qht_bucket_remove_entry()

PATCH In review [email protected] 2 participants 2 messages Aug 14, 2025 – Aug 15, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 util/qht: fix possible NULL pointer dereference in qht_bucket_remove_entry()

From: Denis Rastyogin <[email protected]>

If b->pointers[i] is NULL on the first iteration and prev has not yet been assigned (i.e., is still NULL), calling qht_entry_move(orig, pos, prev, QHT_BUCKET_ENTRIES - 1) can lead to a NULL pointer dereference.

The qht_debug_assert(prev) check does not prevent this issue because QHT_DEBUG is currently disabled (the #define is commented out).

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 util/qht.c | 3 +++
 1 file changed, 3 insertions(+)
util/qht.c +3 -0
index 92c6b78759..cb7e367ebb 100644
@@ -768,6 +768,9 @@ static inline void qht_bucket_remove_entry(struct qht_bucket *orig, int pos)
                 return qht_entry_move(orig, pos, b, i - 1);
             }
             qht_debug_assert(prev);
+            if (!prev) {
+                continue;
+            }
             return qht_entry_move(orig, pos, prev, QHT_BUCKET_ENTRIES - 1);
         }
         prev = b;
Signature · 1 line
2.42.2
#1 lore raw
Quoted 10 lines · [email protected] writes:

From: Denis Rastyogin <[email protected]>

If b->pointers[i] is NULL on the first iteration and prev has not yet been assigned (i.e., is still NULL), calling qht_entry_move(orig, pos, prev, QHT_BUCKET_ENTRIES - 1) can lead to a NULL pointer dereference.

The qht_debug_assert(prev) check does not prevent this issue because QHT_DEBUG is currently disabled (the #define is commented out).

The assert is saying you should never see prev as NULL so that would indicate a bug so we shouldn't be just skipping.

I agree we should probably enable QHT debugging when --enable-debug-tcg is true.

Quoted 23 lines

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 util/qht.c | 3 +++
 1 file changed, 3 insertions(+)
util/qht.c +3 -0
index 92c6b78759..cb7e367ebb 100644
@@ -768,6 +768,9 @@ static inline void qht_bucket_remove_entry(struct qht_bucket *orig, int pos)
                 return qht_entry_move(orig, pos, b, i - 1);
             }
             qht_debug_assert(prev);
+            if (!prev) {
+                continue;
+            }
             return qht_entry_move(orig, pos, prev, QHT_BUCKET_ENTRIES - 1);
         }
         prev = b;
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro