qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock
@ 2024-10-14 20:34 Ilya Leoshkevich
  2024-10-15  8:45 ` Laurent Vivier
  2024-10-22  2:02 ` Richard Henderson
  0 siblings, 2 replies; 3+ messages in thread
From: Ilya Leoshkevich @ 2024-10-14 20:34 UTC (permalink / raw)
  To: Laurent Vivier, Richard Henderson
  Cc: qemu-devel, Ilya Leoshkevich, qemu-stable

If one thread modifies the mappings and another thread prints them,
a situation may occur that the printer thread sees a guest mapping
without a corresponding host mapping, leading to a crash in
open_self_maps_2().

Cc: qemu-stable@nongnu.org
Fixes: 7b7a3366e142 ("linux-user: Use walk_memory_regions for open_self_maps")
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 linux-user/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 1354e756941..dd2ec0712b8 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -8151,17 +8151,19 @@ static int open_self_maps_1(CPUArchState *env, int fd, bool smaps)
 {
     struct open_self_maps_data d = {
         .ts = get_task_state(env_cpu(env)),
-        .host_maps = read_self_maps(),
         .fd = fd,
         .smaps = smaps
     };
 
+    mmap_lock();
+    d.host_maps = read_self_maps();
     if (d.host_maps) {
         walk_memory_regions(&d, open_self_maps_2);
         free_self_maps(d.host_maps);
     } else {
         walk_memory_regions(&d, open_self_maps_3);
     }
+    mmap_unlock();
     return 0;
 }
 
-- 
2.47.0



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

* Re: [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock
  2024-10-14 20:34 [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock Ilya Leoshkevich
@ 2024-10-15  8:45 ` Laurent Vivier
  2024-10-22  2:02 ` Richard Henderson
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2024-10-15  8:45 UTC (permalink / raw)
  To: Ilya Leoshkevich, Richard Henderson; +Cc: qemu-devel, qemu-stable

Le 14/10/2024 à 22:34, Ilya Leoshkevich a écrit :
> If one thread modifies the mappings and another thread prints them,
> a situation may occur that the printer thread sees a guest mapping
> without a corresponding host mapping, leading to a crash in
> open_self_maps_2().
> 
> Cc: qemu-stable@nongnu.org
> Fixes: 7b7a3366e142 ("linux-user: Use walk_memory_regions for open_self_maps")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   linux-user/syscall.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 1354e756941..dd2ec0712b8 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -8151,17 +8151,19 @@ static int open_self_maps_1(CPUArchState *env, int fd, bool smaps)
>   {
>       struct open_self_maps_data d = {
>           .ts = get_task_state(env_cpu(env)),
> -        .host_maps = read_self_maps(),
>           .fd = fd,
>           .smaps = smaps
>       };
>   
> +    mmap_lock();
> +    d.host_maps = read_self_maps();
>       if (d.host_maps) {
>           walk_memory_regions(&d, open_self_maps_2);
>           free_self_maps(d.host_maps);
>       } else {
>           walk_memory_regions(&d, open_self_maps_3);
>       }
> +    mmap_unlock();
>       return 0;
>   }
>   

Reviewed-by: Laurent Vivier <laurent@vivier.eu>


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

* Re: [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock
  2024-10-14 20:34 [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock Ilya Leoshkevich
  2024-10-15  8:45 ` Laurent Vivier
@ 2024-10-22  2:02 ` Richard Henderson
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2024-10-22  2:02 UTC (permalink / raw)
  To: Ilya Leoshkevich, Laurent Vivier; +Cc: qemu-devel, qemu-stable

On 10/14/24 13:34, Ilya Leoshkevich wrote:
> If one thread modifies the mappings and another thread prints them,
> a situation may occur that the printer thread sees a guest mapping
> without a corresponding host mapping, leading to a crash in
> open_self_maps_2().
> 
> Cc: qemu-stable@nongnu.org
> Fixes: 7b7a3366e142 ("linux-user: Use walk_memory_regions for open_self_maps")
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   linux-user/syscall.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Thanks, queued.


r~


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

end of thread, other threads:[~2024-10-22  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 20:34 [PATCH] linux-user: Emulate /proc/self/maps under mmap_lock Ilya Leoshkevich
2024-10-15  8:45 ` Laurent Vivier
2024-10-22  2:02 ` 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).