qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: check for NULL before using interval_tree_iter_first result
@ 2025-07-22 10:15 gerben
  2025-07-22 14:43 ` Richard Henderson
  0 siblings, 1 reply; 2+ messages in thread
From: gerben @ 2025-07-22 10:15 UTC (permalink / raw)
  To: qemu-devel, laurent; +Cc: sdl.qemu

From: Denis Rastyogin <gerben@altlinux.org>

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.

Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
---
 linux-user/syscall.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 91360a072c..d5d5912c96 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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;
-- 
2.42.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] linux-user: check for NULL before using interval_tree_iter_first result
  2025-07-22 10:15 [PATCH] linux-user: check for NULL before using interval_tree_iter_first result gerben
@ 2025-07-22 14:43 ` Richard Henderson
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2025-07-22 14:43 UTC (permalink / raw)
  To: qemu-devel

On 7/22/25 03:15, gerben@altlinux.org wrote:
> From: Denis Rastyogin <gerben@altlinux.org>
> 
> 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.
> 
> Signed-off-by: Denis Rastyogin <gerben@altlinux.org>
> ---
>   linux-user/syscall.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 91360a072c..d5d5912c96 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -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~


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-22 14:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-22 10:15 [PATCH] linux-user: check for NULL before using interval_tree_iter_first result gerben
2025-07-22 14:43 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).