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 <iii@linux.ibm.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20241014203441.387560-1-iii@linux.ibm.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> (cherry picked from commit bbd5630a75e70a0f1bcf04de74c94aa94a145628) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> (Mjt: context fix in linux-user/syscall.c due to missing v9.0.0-421-g59272469bd13 "user: Use get_task_state() helper")
This commit is contained in:
parent
893e7f2b39
commit
05d635a28d
@ -8132,17 +8132,19 @@ static int open_self_maps_1(CPUArchState *env, int fd, bool smaps)
|
|||||||
{
|
{
|
||||||
struct open_self_maps_data d = {
|
struct open_self_maps_data d = {
|
||||||
.ts = env_cpu(env)->opaque,
|
.ts = env_cpu(env)->opaque,
|
||||||
.host_maps = read_self_maps(),
|
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
.smaps = smaps
|
.smaps = smaps
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mmap_lock();
|
||||||
|
d.host_maps = read_self_maps();
|
||||||
if (d.host_maps) {
|
if (d.host_maps) {
|
||||||
walk_memory_regions(&d, open_self_maps_2);
|
walk_memory_regions(&d, open_self_maps_2);
|
||||||
free_self_maps(d.host_maps);
|
free_self_maps(d.host_maps);
|
||||||
} else {
|
} else {
|
||||||
walk_memory_regions(&d, open_self_maps_3);
|
walk_memory_regions(&d, open_self_maps_3);
|
||||||
}
|
}
|
||||||
|
mmap_unlock();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user