From: Ilya Leoshkevich Date: Mon, 14 Oct 2024 20:34:21 +0000 (+0200) Subject: linux-user: Emulate /proc/self/maps under mmap_lock X-Git-Tag: v9.2.0-rc0~36^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bbd5630a75e70a0f1bcf04de74c94aa94a145628;p=thirdparty%2Fqemu.git linux-user: Emulate /proc/self/maps under mmap_lock 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 Reviewed-by: Laurent Vivier Reviewed-by: Richard Henderson Message-ID: <20241014203441.387560-1-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- 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; }