Skip to contentSkip to conversation

linux-user: check for NULL before using interval_tree_iter_first result

PATCH In review [email protected] 2 participants 2 messages Jul 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: check for NULL before using interval_tree_iter_first result

From: Denis Rastyogin <[email protected]>

interval_tree_iter_first() may return NULL if the interval tree is empty or invalid. Add a check for NULL before dereferencing the pointer to avoid potential crashes due to null pointer dereference in open_self_maps_2().

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

---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/syscall.c +3 -0
index 91360a072c..d5d5912c96 100644
@@ -8172,6 +8172,9 @@ static int open_self_maps_2(void *opaque, vaddr guest_start,
     while (1) {
         IntervalTreeNode *n =
             interval_tree_iter_first(d->host_maps, host_start, host_start);
+        if (n == NULL) {
+            return -1;
+        }
         MapInfo *mi = container_of(n, MapInfo, itree);
         uintptr_t this_hlast = MIN(host_last, n->last);
         target_ulong this_gend = h2g(this_hlast) + 1;
Signature · 1 line
2.42.2
#1 lore raw
Quoted 18 lines · On 7/22/25 03:15, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

interval_tree_iter_first() may return NULL if the interval tree is empty or invalid. Add a check for NULL before dereferencing the pointer to avoid potential crashes due to null pointer dereference in open_self_maps_2().

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

---
  linux-user/syscall.c | 3 +++
  1 file changed, 3 insertions(+)
linux-user/syscall.c +0 -0
index 91360a072c..d5d5912c96 100644

linux-user/syscall.c static int open_self_maps_2(void *opaque, vaddr guest_start, · line 8180

Quoted 9 lines
linux-user/syscall.c +3 -0
@@ -8172,6 +8172,9 @@ static int open_self_maps_2(void *opaque, vaddr guest_start,
      while (1) {
          IntervalTreeNode *n =
              interval_tree_iter_first(d->host_maps, host_start, host_start);
+        if (n == NULL) {
+            return -1;
+        }
          MapInfo *mi = container_of(n, MapInfo, itree);
          uintptr_t this_hlast = MIN(host_last, n->last);
          target_ulong this_gend = h2g(this_hlast) + 1;

This will not return null. Via our caller, we have already verified that there is guest memory present for the virtual address. There *must* be host memory present to back it.

r~