Linux user for 5.1 patches
The following changes since commit 9303ecb658a0194560d1eecde165a1511223c2d8:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20200727' into staging (2020-07-27 17:25:06 +0100)
are available in the Git repository at:
git://github.com/vivier/qemu.git tags/linux-user-for-5.1-pull-request
for you to fetch changes up to 0f6bb1958f3aae0171996941df7fb7ea7536bb12:
linux-user: Use getcwd syscall directly (2020-07-27 22:05:34 +0200)
----------------------------------------------------------------
linux-user 20200728
Fix "pgb_reserved_va: Assertion `guest_base != 0' failed." error Fix rt_sigtimedwait() errno
Fix getcwd() errno
----------------------------------------------------------------
Andreas Schwab (1):
linux-user: Use getcwd syscall directly
Filip Bozuta (1):
linux-user: Fix syscall rt_sigtimedwait() implementation
Richard Henderson (1):
linux-user: Ensure mmap_min_addr is non-zero
linux-user/main.c | 16 ++++++++++++++-- linux-user/syscall.c | 13 ++++--------- 2 files changed, 18 insertions(+), 11 deletions(-)
Signature · 1 line
2.26.2
[PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero
From: Richard Henderson <[email protected]>
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.
Message-Id: <[email protected]>
--- 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.26.2
[PULL 3/3] linux-user: Use getcwd syscall directly
In reply to Laurent VivierFrom: Andreas Schwab <[email protected]>
The glibc getcwd function returns different errors than the getcwd syscall, which triggers an assertion failure in the glibc getcwd function when running under the emulation.
When the syscall returns ENAMETOOLONG, the glibc wrapper uses a fallback implementation that potentially handles an unlimited path length, and returns with ERANGE if the provided buffer is too small. The qemu emulation cannot distinguish the two cases, and thus always returns ERANGE. This is unexpected by the glibc wrapper.
Message-Id: <[email protected]>
--- linux-user/syscall.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-)
linux-user/syscall.c +1 -8
@@ -388,14 +388,7 @@ static bitmask_transtbl fcntl_flags_tbl[] = { { 0, 0, 0, 0 } }; -static int sys_getcwd1 (char *buf,size_t size) -{ -if (getcwd (buf, size) ==NULL ) { -/* getcwd() sets errno */ -return (-1 ); - } -return strlen (buf)+1 ; -} +_syscall2(int, sys_getcwd1, char *, buf, size_t, size)#ifdef TARGET_NR_utimensat#if defined(__NR_utimensat)
Signature · 1 line
2.26.2
[PULL 2/3] linux-user: Fix syscall rt_sigtimedwait() implementation
In reply to Laurent VivierFrom: Filip Bozuta <[email protected]>
Implementation of 'rt_sigtimedwait()' in 'syscall.c' uses the function 'target_to_host_timespec()' to transfer the value of 'struct timespec' from target to host. However, the implementation doesn't check whether this conversion succeeds and thus can cause an unaproppriate error instead of the 'EFAULT (Bad address)' which is supposed to be set if the conversion from target to host fails.
This was confirmed with the LTP test for rt_sigtimedwait:
"/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c" which causes an unapropriate error in test case "test_bad_adress3" which is run with a bad adress for the 'struct timespec' argument:
FAIL: test_bad_address3 (349): Unexpected failure: EAGAIN/EWOULDBLOCK (11)
The test fails with an unexptected errno 'EAGAIN/EWOULDBLOCK' instead of the expected EFAULT.
After the changes from this patch, the test case is executed successfully along with the other LTP test cases for 'rt_sigtimedwait()':
PASS: test_bad_address3 (349): Test passed
Message-Id: <[email protected]>
--- linux-user/syscall.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
linux-user/syscall.c +3 -1
@@ -8868,7 +8868,9 @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1,unlock_user (p, arg1,0 );if (arg3) { puts = &uts; -target_to_host_timespec (puts, arg3); +if (target_to_host_timespec (puts, arg3)) { +return -TARGET_EFAULT ; + } }else { puts =NULL ; }
Signature · 1 line
2.26.2
Peter Maydell
AppliedQuoted 11 lines · Laurent Vivier
The following changes since commit
9303ecb658a0194560d1eecde165a1511223c2d8:Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20200727' into staging (2020-07-27 17:25:06 +0100)
are available in the Git repository at:
git://github.com/vivier/qemu.gittags/linux-user-for-5.1-pull-requestfor you to fetch changes up to
0f6bb1958f3aae0171996941df7fb7ea7536bb12:
Quoted 8 lines
linux-user: Use getcwd syscall directly (2020-07-27 22:05:34 +0200)
----------------------------------------------------------------
linux-user 20200728Fix "
pgb_reserved_va: Assertion `guest_base != 0' failed." error Fixrt_sigtimedwait()errno
Fixgetcwd()errno
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.
-- PMM