qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] linux-user: Use getcwd syscall directly
@ 2020-04-06 15:18 Andreas Schwab
  2020-04-07 10:36 ` Laurent Vivier
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2020-04-06 15:18 UTC (permalink / raw)
  To: qemu-devel

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.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 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 83c2891169..90c5433fec 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -375,14 +375,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.0


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


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

* Re: [PATCH] linux-user: Use getcwd syscall directly
  2020-04-06 15:18 Andreas Schwab
@ 2020-04-07 10:36 ` Laurent Vivier
  2020-04-07 10:57   ` Peter Maydell
  0 siblings, 1 reply; 7+ messages in thread
From: Laurent Vivier @ 2020-04-07 10:36 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel

Le 06/04/2020 à 17:18, Andreas Schwab a écrit :
> 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.
> 
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  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 83c2891169..90c5433fec 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -375,14 +375,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)
> 

According to the commit introducing the function, it could break fakeroot:

commit 3b3f24add09f8ab720860d4840f9755c102121b5
Author: Aurelien Jarno <aurelien@aurel32.net>
Date:   Wed Apr 15 16:12:13 2009 +0000

    linux-user: prefer glibc over direct syscalls

    The openat/*at syscalls are incredibly common with modern coreutils,
    calling them directly via syscalls breaks for example fakeroot. Use
    glibc stubs whenever directly available and provide old syscall
    calling for people still using older libc.

    Patch originally from Mika Westerberg, Adapted to
    apply to current trunk and cleaned up by Riku Voipio.

    Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
    Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>

Thanks,
Laurent


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

* Re: [PATCH] linux-user: Use getcwd syscall directly
  2020-04-07 10:36 ` Laurent Vivier
@ 2020-04-07 10:57   ` Peter Maydell
  2020-04-07 11:55     ` Andreas Schwab
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2020-04-07 10:57 UTC (permalink / raw)
  To: Laurent Vivier; +Cc: Andreas Schwab, QEMU Developers

On Tue, 7 Apr 2020 at 11:37, Laurent Vivier <laurent@vivier.eu> wrote:
>
> Le 06/04/2020 à 17:18, Andreas Schwab a écrit :
> > 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.

What exactly are the differences in errors ?

> > ---

> According to the commit introducing the function, it could break fakeroot:
>
> commit 3b3f24add09f8ab720860d4840f9755c102121b5
> Author: Aurelien Jarno <aurelien@aurel32.net>
> Date:   Wed Apr 15 16:12:13 2009 +0000
>
>     linux-user: prefer glibc over direct syscalls
>
>     The openat/*at syscalls are incredibly common with modern coreutils,
>     calling them directly via syscalls breaks for example fakeroot. Use
>     glibc stubs whenever directly available and provide old syscall
>     calling for people still using older libc.

I don't think (based on a quick grep of the fakeroot sources) that
fakeroot intercepts 'getcwd', so this patch is probably ok on this
front. It looks like the syscalls that fakeroot cares about that
that patch was trying to improve our handling for are the
ones like fstatat which return the kind of permission/ownership
info fakeroot wants to alter (not including 'openat', despite
that being the only function named in full in the commit message...)

More generally, we rely on making direct syscalls for at least
some syscalls for signal-handling related correctness, so if
that ever comes into conflict with QEMU continuing to work under
'fakeroot' then fakeroot-compatilibity is going to lose...
('fakeroot-ng' would still work, as it intercepts syscalls
via ptrace.)

thanks
-- PMM


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

* Re: [PATCH] linux-user: Use getcwd syscall directly
  2020-04-07 10:57   ` Peter Maydell
@ 2020-04-07 11:55     ` Andreas Schwab
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2020-04-07 11:55 UTC (permalink / raw)
  To: Peter Maydell; +Cc: Laurent Vivier, QEMU Developers

On Apr 07 2020, Peter Maydell wrote:

> On Tue, 7 Apr 2020 at 11:37, Laurent Vivier <laurent@vivier.eu> wrote:
>>
>> Le 06/04/2020 à 17:18, Andreas Schwab a écrit :
>> > 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.
>
> What exactly are the differences in errors ?

It's ENAMETOOLONG vs. ERANGE.  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.

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


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

* [PATCH] linux-user: Use getcwd syscall directly
@ 2020-07-23 10:27 Andreas Schwab
  2020-07-24 13:52 ` Laurent Vivier
  2020-07-27 20:07 ` Laurent Vivier
  0 siblings, 2 replies; 7+ messages in thread
From: Andreas Schwab @ 2020-07-23 10:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: laurent

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.

Signed-off-by: Andreas Schwab <schwab@suse.de>
---
 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 b9144b18fc..e4e46867e8 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


-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


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

* Re: [PATCH] linux-user: Use getcwd syscall directly
  2020-07-23 10:27 [PATCH] linux-user: Use getcwd syscall directly Andreas Schwab
@ 2020-07-24 13:52 ` Laurent Vivier
  2020-07-27 20:07 ` Laurent Vivier
  1 sibling, 0 replies; 7+ messages in thread
From: Laurent Vivier @ 2020-07-24 13:52 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel; +Cc: Peter Maydell

Le 23/07/2020 à 12:27, Andreas Schwab a écrit :
> 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.
> 
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  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 b9144b18fc..e4e46867e8 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)
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>

I'll add in the commit message the explanation you did on your previous
attempt:

"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."

Thanks,
Laurent


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

* Re: [PATCH] linux-user: Use getcwd syscall directly
  2020-07-23 10:27 [PATCH] linux-user: Use getcwd syscall directly Andreas Schwab
  2020-07-24 13:52 ` Laurent Vivier
@ 2020-07-27 20:07 ` Laurent Vivier
  1 sibling, 0 replies; 7+ messages in thread
From: Laurent Vivier @ 2020-07-27 20:07 UTC (permalink / raw)
  To: Andreas Schwab, qemu-devel

Le 23/07/2020 à 12:27, Andreas Schwab a écrit :
> 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.
> 
> Signed-off-by: Andreas Schwab <schwab@suse.de>
> ---
>  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 b9144b18fc..e4e46867e8 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)
> 

Applied to my linux-user-for-5.1 branch.

Thanks,
Laurent


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

end of thread, other threads:[~2020-07-27 20:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-23 10:27 [PATCH] linux-user: Use getcwd syscall directly Andreas Schwab
2020-07-24 13:52 ` Laurent Vivier
2020-07-27 20:07 ` Laurent Vivier
  -- strict thread matches above, loose matches on Subject: below --
2020-04-06 15:18 Andreas Schwab
2020-04-07 10:36 ` Laurent Vivier
2020-04-07 10:57   ` Peter Maydell
2020-04-07 11:55     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).