qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

linux-user: Don't assert if guest tries shmdt(0)

Our implementation of shmat() and shmdt() for linux-user was
using "zero guest address" as its marker for "entry in the
shm_regions[] array is not in use". This meant that if the
guest did a shmdt(0) we would match on an unused array entry
and call page_set_flags() with both start and end addresses zero,
which causes an assertion failure.

Use an explicit in_use flag to manage the shm_regions[] array,
so that we avoid this problem.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reported-by: Pavel Shamis <pasharesearch@gmail.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>

authored by

Peter Maydell and committed by
Riku Voipio
b6e17875 de3f1b98

+7 -5
+7 -5
linux-user/syscall.c
··· 2598 2598 #define N_SHM_REGIONS 32 2599 2599 2600 2600 static struct shm_region { 2601 - abi_ulong start; 2602 - abi_ulong size; 2601 + abi_ulong start; 2602 + abi_ulong size; 2603 + bool in_use; 2603 2604 } shm_regions[N_SHM_REGIONS]; 2604 2605 2605 2606 struct target_semid_ds ··· 3291 3292 ((shmflg & SHM_RDONLY)? 0 : PAGE_WRITE)); 3292 3293 3293 3294 for (i = 0; i < N_SHM_REGIONS; i++) { 3294 - if (shm_regions[i].start == 0) { 3295 + if (!shm_regions[i].in_use) { 3296 + shm_regions[i].in_use = true; 3295 3297 shm_regions[i].start = raddr; 3296 3298 shm_regions[i].size = shm_info.shm_segsz; 3297 3299 break; ··· 3308 3310 int i; 3309 3311 3310 3312 for (i = 0; i < N_SHM_REGIONS; ++i) { 3311 - if (shm_regions[i].start == shmaddr) { 3312 - shm_regions[i].start = 0; 3313 + if (shm_regions[i].in_use && shm_regions[i].start == shmaddr) { 3314 + shm_regions[i].in_use = false; 3313 3315 page_set_flags(shmaddr, shmaddr + shm_regions[i].size, 0); 3314 3316 break; 3315 3317 }