All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/3] Linux user for 5.1 patches
@ 2020-07-28 12:34 Laurent Vivier
  2020-07-28 12:34 ` [PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero Laurent Vivier
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Laurent Vivier @ 2020-07-28 12:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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.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(-)

-- 
2.26.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero
  2020-07-28 12:34 [PULL 0/3] Linux user for 5.1 patches Laurent Vivier
@ 2020-07-28 12:34 ` Laurent Vivier
  2020-07-28 12:34 ` [PULL 2/3] linux-user: Fix syscall rt_sigtimedwait() implementation Laurent Vivier
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2020-07-28 12:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Richard Henderson, Laurent Vivier, John Paul Adrian Glaubitz

From: Richard Henderson <richard.henderson@linaro.org>

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.

Buglink: https://bugs.launchpad.net/qemu/+bug/1888728
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Acked-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200724212314.545877-1-richard.henderson@linaro.org>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/main.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/linux-user/main.c b/linux-user/main.c
index 3597e99bb10a..75c97851579e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -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.
      */
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 2/3] linux-user: Fix syscall rt_sigtimedwait() implementation
  2020-07-28 12:34 [PULL 0/3] Linux user for 5.1 patches Laurent Vivier
  2020-07-28 12:34 ` [PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero Laurent Vivier
@ 2020-07-28 12:34 ` Laurent Vivier
  2020-07-28 12:34 ` [PULL 3/3] linux-user: Use getcwd syscall directly Laurent Vivier
  2020-07-28 17:00 ` [PULL 0/3] Linux user for 5.1 patches Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2020-07-28 12:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Laurent Vivier, Filip Bozuta

From: Filip Bozuta <Filip.Bozuta@syrmia.com>

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

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200724181651.167819-1-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f5c4f6b95db4..c1ebf7b8f384 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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;
             }
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PULL 3/3] linux-user: Use getcwd syscall directly
  2020-07-28 12:34 [PULL 0/3] Linux user for 5.1 patches Laurent Vivier
  2020-07-28 12:34 ` [PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero Laurent Vivier
  2020-07-28 12:34 ` [PULL 2/3] linux-user: Fix syscall rt_sigtimedwait() implementation Laurent Vivier
@ 2020-07-28 12:34 ` Laurent Vivier
  2020-07-28 17:00 ` [PULL 0/3] Linux user for 5.1 patches Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Laurent Vivier @ 2020-07-28 12:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Schwab, Laurent Vivier

From: Andreas Schwab <schwab@suse.de>

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.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <mvmmu3qplvi.fsf@suse.de>
[lv: updated description]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/syscall.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index c1ebf7b8f384..945fc252791c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -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)
-- 
2.26.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PULL 0/3] Linux user for 5.1 patches
  2020-07-28 12:34 [PULL 0/3] Linux user for 5.1 patches Laurent Vivier
                   ` (2 preceding siblings ...)
  2020-07-28 12:34 ` [PULL 3/3] linux-user: Use getcwd syscall directly Laurent Vivier
@ 2020-07-28 17:00 ` Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2020-07-28 17:00 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: QEMU Developers

On Tue, 28 Jul 2020 at 13:36, Laurent Vivier <laurent@vivier.eu> wrote:
>
> 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


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/5.1
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-28 17:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-28 12:34 [PULL 0/3] Linux user for 5.1 patches Laurent Vivier
2020-07-28 12:34 ` [PULL 1/3] linux-user: Ensure mmap_min_addr is non-zero Laurent Vivier
2020-07-28 12:34 ` [PULL 2/3] linux-user: Fix syscall rt_sigtimedwait() implementation Laurent Vivier
2020-07-28 12:34 ` [PULL 3/3] linux-user: Use getcwd syscall directly Laurent Vivier
2020-07-28 17:00 ` [PULL 0/3] Linux user for 5.1 patches Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.