linux-user: Ensure mmap_min_addr is non-zero
PATCH 1/1 linux-user: Ensure mmap_min_addr is non-zero
When the chroot does not have /proc mounted, we can read neither /proc/sys/vm/mmap_min_addr nor /proc/sys/maps.
The enforcement of mmap_min_addr in the host kernel is done by the security module, and so does not apply to processes owned by root. Which leads pgd_find_hole_fallback to succeed in probing a reservation at address 0. Which confuses pgb_reserved_va to believe that guest_base has not actually been initialized.
We don't actually want NULL addresses to become accessible, so make sure that mmap_min_addr is initialized with a non-zero value.
--- linux-user/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
linux-user/main.c +14 -2
@@ -758,14 +758,26 @@ int main(int argc, char **argv, char **envp)if ((fp =fopen ("/proc/sys/vm/mmap_min_addr" ,"r" )) !=NULL ) {unsigned long tmp; -if (fscanf (fp,"%lu" , &tmp) ==1 ) { +if (fscanf (fp,"%lu" , &tmp) ==1 && tmp !=0 ) { mmap_min_addr = tmp; -qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , mmap_min_addr); +qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , + mmap_min_addr); }fclose (fp); } } +/* +* We prefer to not make NULL pointers accessible to QEMU. +* If we're in a chroot with no /proc, fall back to 1 page. +*/ +if (mmap_min_addr ==0 ) { + mmap_min_addr = qemu_host_page_size; +qemu_log_mask (CPU_LOG_PAGE , +"host mmap_min_addr=0x%lx (fallback)\n" , + mmap_min_addr); + } +/* * Prepare copy of argv vector for target. */
Signature · 1 line
2.25.1
Hi!
Quoted 43 lines · Richard Henderson
When the chroot does not have /proc mounted, we can read neither
/proc/sys/vm/mmap_min_addrnor/proc/sys/maps.The enforcement of
mmap_min_addrin the host kernel is done by the security module, and so does not apply to processes owned by root. Which leadspgd_find_hole_fallbackto succeed in probing a reservation at address 0. Which confusespgb_reserved_vato believe thatguest_basehas not actually been initialized.We don't actually want NULL addresses to become accessible, so make sure that
mmap_min_addris initialized with a non-zero value.Reported-by John Paul Adrian Glaubitz <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- linux-user/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)linux-user/main.c +7
-2@@ -758,14 +758,26 @@ int main(int argc, char **argv, char **envp)if ((fp =fopen ("/proc/sys/vm/mmap_min_addr" ,"r" )) !=NULL ) {unsigned long tmp; -if (fscanf (fp,"%lu" , &tmp) ==1 ) { +if (fscanf (fp,"%lu" , &tmp) ==1 && tmp !=0 ) { mmap_min_addr = tmp; -qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , mmap_min_addr); +qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , + mmap_min_addr); }fclose (fp); } } +/* +* We prefer to not make NULL pointers accessible to QEMU. +* If we're in a chroot with no /proc, fall back to 1 page. +*/
linux-user/main.c int main(int argc, char **argv, char **envp) · line 783
Quoted 10 lines
linux-user/main.c +7
-0+if (mmap_min_addr ==0 ) { + mmap_min_addr = qemu_host_page_size; +qemu_log_mask (CPU_LOG_PAGE , +"host mmap_min_addr=0x%lx (fallback)\n" , + mmap_min_addr); + } +/* * Prepare copy of argv vector for target. */
This fixes the problem for me, therefore:
Adrian
Signature · 4 lines
.''`. John Paul Adrian Glaubitz : :' : Debian Developer - [email protected] `. `' Freie Universitaet Berlin - [email protected] `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Le 24/07/2020 à 23:23, Richard Henderson a écrit :
Quoted 12 lines
When the chroot does not have /proc mounted, we can read neither
/proc/sys/vm/mmap_min_addrnor/proc/sys/maps.The enforcement of
mmap_min_addrin the host kernel is done by the security module, and so does not apply to processes owned by root. Which leadspgd_find_hole_fallbackto succeed in probing a reservation at address 0. Which confusespgb_reserved_vato believe thatguest_basehas not actually been initialized.We don't actually want NULL addresses to become accessible, so make sure that
mmap_min_addris initialized with a non-zero value.
Quoted 7 lines
Reported-by John Paul Adrian Glaubitz <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- linux-user/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Richard, do you want to add this fix in one of your branches PR?
In this case:
Otherwise I can prepare a small one for linux-user, adding one or two fixes...
Thanks,
Laurent
Quoted 21 lines · Laurent Vivier
Le 24/07/2020 à 23:23, Richard Henderson a écrit :
Quoted 12 lines
When the chroot does not have /proc mounted, we can read neither
/proc/sys/vm/mmap_min_addrnor/proc/sys/maps.The enforcement of
mmap_min_addrin the host kernel is done by the security module, and so does not apply to processes owned by root. Which leadspgd_find_hole_fallbackto succeed in probing a reservation at address 0. Which confusespgb_reserved_vato believe thatguest_basehas not actually been initialized.We don't actually want NULL addresses to become accessible, so make sure that
mmap_min_addris initialized with a non-zero value.Quoted 7 lines
Reported-by John Paul Adrian Glaubitz <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- linux-user/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Quoted 1 line
Richard, do you want to add this fix in one of your branches PR?
I don't have anything queued at the moment. I thought I would be able to convince Alex to add it to his misc queue, but he sent that this morning.
Quoted 5 lines
In this case:
Acked-by Laurent Vivier <[email protected]>Otherwise I can prepare a small one for linux-user, adding one or two fixes...
Please go ahead.
r~
Laurent Vivier
AppliedLe 24/07/2020 à 23:23, Richard Henderson a écrit :
Quoted 43 lines
When the chroot does not have /proc mounted, we can read neither
/proc/sys/vm/mmap_min_addrnor/proc/sys/maps.The enforcement of
mmap_min_addrin the host kernel is done by the security module, and so does not apply to processes owned by root. Which leadspgd_find_hole_fallbackto succeed in probing a reservation at address 0. Which confusespgb_reserved_vato believe thatguest_basehas not actually been initialized.We don't actually want NULL addresses to become accessible, so make sure that
mmap_min_addris initialized with a non-zero value.Reported-by John Paul Adrian Glaubitz <[email protected]>Signed-off-by Richard Henderson <[email protected]>--- linux-user/main.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)linux-user/main.c +7
-2@@ -758,14 +758,26 @@ int main(int argc, char **argv, char **envp)if ((fp =fopen ("/proc/sys/vm/mmap_min_addr" ,"r" )) !=NULL ) {unsigned long tmp; -if (fscanf (fp,"%lu" , &tmp) ==1 ) { +if (fscanf (fp,"%lu" , &tmp) ==1 && tmp !=0 ) { mmap_min_addr = tmp; -qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , mmap_min_addr); +qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , + mmap_min_addr); }fclose (fp); } } +/* +* We prefer to not make NULL pointers accessible to QEMU. +* If we're in a chroot with no /proc, fall back to 1 page. +*/
linux-user/main.c int main(int argc, char **argv, char **envp) · line 783
Quoted 10 lines
linux-user/main.c +7
-0+if (mmap_min_addr ==0 ) { + mmap_min_addr = qemu_host_page_size; +qemu_log_mask (CPU_LOG_PAGE , +"host mmap_min_addr=0x%lx (fallback)\n" , + mmap_min_addr); + } +/* * Prepare copy of argv vector for target. */
Applied to my linux-user-for-5.1 branch.
Thanks,
Laurent