Patchwork [03/17] linux-user: define a couple of syscalls for non-uid16 targets

login
register
mail settings
Submitter Alexander Graf
Date April 15, 2011, 3:32 p.m.
Message ID <1302881578-5357-4-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/91397/
State New
Headers show

Comments

Alexander Graf - April 15, 2011, 3:32 p.m.
From: Ulrich Hecht <uli@suse.de>

Quite a number of syscalls are only defined on systems with USE_UID16
defined; this patch defines them on other systems as well.

Fixes a large number of uid/gid-related testcases on the s390x target
(and most likely on other targets as well)

Signed-off-by: Ulrich Hecht <uli@suse.de>

---

v3 -> v4:

  - remove linux-user host bits
---
 linux-user/syscall.c |  125 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 105 insertions(+), 20 deletions(-)
Riku Voipio - April 18, 2011, 4:32 p.m.
On Fri, Apr 15, 2011 at 05:32:44PM +0200, Alexander Graf wrote:
> From: Ulrich Hecht <uli@suse.de>
> 
> Quite a number of syscalls are only defined on systems with USE_UID16
> defined; this patch defines them on other systems as well.
> 
> Fixes a large number of uid/gid-related testcases on the s390x target
> (and most likely on other targets as well)

I'll provide cleaner patch for the same effect. This one makes the code
more ifdeffed and harder to follow.
 
> Signed-off-by: Ulrich Hecht <uli@suse.de>
> 
> ---
> 
> v3 -> v4:
> 
>   - remove linux-user host bits
> ---
>  linux-user/syscall.c |  125 ++++++++++++++++++++++++++++++++++++++++++--------
>  1 files changed, 105 insertions(+), 20 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 504b26c..99f5935 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -326,7 +326,7 @@ static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode)
>    return (fchmodat(dirfd, pathname, mode, 0));
>  }
>  #endif
> -#if defined(TARGET_NR_fchownat) && defined(USE_UID16)
> +#if defined(TARGET_NR_fchownat)
>  static int sys_fchownat(int dirfd, const char *pathname, uid_t owner,
>      gid_t group, int flags)
>  {
> @@ -435,7 +435,7 @@ _syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)
>  #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
>  _syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)
>  #endif
> -#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
> +#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
>  _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,
>            uid_t,owner,gid_t,group,int,flags)
>  #endif
> @@ -6817,18 +6817,35 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>      case TARGET_NR_setfsgid:
>          ret = get_errno(setfsgid(arg1));
>          break;
> +#else /* USE_UID16 */
> +#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
> +    case TARGET_NR_fchownat:
> +        if (!(p = lock_user_string(arg2)))
> +            goto efault;
> +        ret = get_errno(sys_fchownat(arg1, p, arg3, arg4, arg5));
> +        unlock_user(p, arg2, 0);
> +        break;
> +#endif
>  #endif /* USE_UID16 */
>  
> -#ifdef TARGET_NR_lchown32
> +#if defined(TARGET_NR_lchown32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_lchown32)
>      case TARGET_NR_lchown32:
> +#else
> +    case TARGET_NR_lchown:
> +#endif
>          if (!(p = lock_user_string(arg1)))
>              goto efault;
>          ret = get_errno(lchown(p, arg2, arg3));
>          unlock_user(p, arg1, 0);
>          break;
>  #endif
> -#ifdef TARGET_NR_getuid32
> +#if defined(TARGET_NR_getuid32) || (defined(TARGET_NR_getuid) && !defined(USE_UID16))
> +#if defined(TARGET_NR_getuid32)
>      case TARGET_NR_getuid32:
> +#else
> +    case TARGET_NR_getuid:
> +#endif
>          ret = get_errno(getuid());
>          break;
>  #endif
> @@ -6973,33 +6990,57 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          break;
>  #endif
>  
> -#ifdef TARGET_NR_getgid32
> +#if defined(TARGET_NR_getgid32) || (defined(TARGET_NR_getgid) && !defined(USE_UID16))
> +#if defined(TARGET_NR_getgid32)
>      case TARGET_NR_getgid32:
> +#else
> +    case TARGET_NR_getgid:
> +#endif
>          ret = get_errno(getgid());
>          break;
>  #endif
> -#ifdef TARGET_NR_geteuid32
> +#if defined(TARGET_NR_geteuid32) || (defined(TARGET_NR_geteuid) && !defined(USE_UID16))
> +#if defined(TARGET_NR_geteuid32)
>      case TARGET_NR_geteuid32:
> +#else
> +    case TARGET_NR_geteuid:
> +#endif
>          ret = get_errno(geteuid());
>          break;
>  #endif
> -#ifdef TARGET_NR_getegid32
> +#if defined(TARGET_NR_getegid32) || (defined(TARGET_NR_getegid) && !defined(USE_UID16))
> +#if defined(TARGET_NR_getegid32)
>      case TARGET_NR_getegid32:
> +#else
> +    case TARGET_NR_getegid:
> +#endif
>          ret = get_errno(getegid());
>          break;
>  #endif
> -#ifdef TARGET_NR_setreuid32
> +#if defined(TARGET_NR_setreuid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setreuid32)
>      case TARGET_NR_setreuid32:
> +#else
> +    case TARGET_NR_setreuid:
> +#endif
>          ret = get_errno(setreuid(arg1, arg2));
>          break;
>  #endif
> -#ifdef TARGET_NR_setregid32
> +#if defined(TARGET_NR_setregid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setregid32)
>      case TARGET_NR_setregid32:
> +#else
> +    case TARGET_NR_setregid:
> +#endif
>          ret = get_errno(setregid(arg1, arg2));
>          break;
>  #endif
> -#ifdef TARGET_NR_getgroups32
> +#if defined(TARGET_NR_getgroups32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_getgroups32)
>      case TARGET_NR_getgroups32:
> +#else
> +    case TARGET_NR_getgroups:
> +#endif
>          {
>              int gidsetsize = arg1;
>              uint32_t *target_grouplist;
> @@ -7023,8 +7064,12 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          }
>          break;
>  #endif
> -#ifdef TARGET_NR_setgroups32
> +#if defined(TARGET_NR_setgroups32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setgroups32)
>      case TARGET_NR_setgroups32:
> +#else
> +    case TARGET_NR_setgroups:
> +#endif
>          {
>              int gidsetsize = arg1;
>              uint32_t *target_grouplist;
> @@ -7044,18 +7089,30 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          }
>          break;
>  #endif
> -#ifdef TARGET_NR_fchown32
> +#if defined(TARGET_NR_fchown32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_fchown32)
>      case TARGET_NR_fchown32:
> +#else
> +    case TARGET_NR_fchown:
> +#endif
>          ret = get_errno(fchown(arg1, arg2, arg3));
>          break;
>  #endif
> -#ifdef TARGET_NR_setresuid32
> +#if defined(TARGET_NR_setresuid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setresuid32)
>      case TARGET_NR_setresuid32:
> +#else
> +    case TARGET_NR_setresuid:
> +#endif
>          ret = get_errno(setresuid(arg1, arg2, arg3));
>          break;
>  #endif
> -#ifdef TARGET_NR_getresuid32
> +#if defined(TARGET_NR_getresuid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_getresuid32)
>      case TARGET_NR_getresuid32:
> +#else
> +    case TARGET_NR_getresuid:
> +#endif
>          {
>              uid_t ruid, euid, suid;
>              ret = get_errno(getresuid(&ruid, &euid, &suid));
> @@ -7068,13 +7125,21 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          }
>          break;
>  #endif
> -#ifdef TARGET_NR_setresgid32
> +#if defined(TARGET_NR_setresgid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setresgid32)
>      case TARGET_NR_setresgid32:
> +#else
> +    case TARGET_NR_setresgid:
> +#endif
>          ret = get_errno(setresgid(arg1, arg2, arg3));
>          break;
>  #endif
> +#if defined(TARGET_NR_getresgid32) || !defined(USE_UID16)
>  #ifdef TARGET_NR_getresgid32
>      case TARGET_NR_getresgid32:
> +#else
> +    case TARGET_NR_getresgid:
> +#endif
>          {
>              gid_t rgid, egid, sgid;
>              ret = get_errno(getresgid(&rgid, &egid, &sgid));
> @@ -7087,31 +7152,51 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
>          }
>          break;
>  #endif
> -#ifdef TARGET_NR_chown32
> +#if defined(TARGET_NR_chown32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_chown32)
>      case TARGET_NR_chown32:
> +#else
> +    case TARGET_NR_chown:
> +#endif
>          if (!(p = lock_user_string(arg1)))
>              goto efault;
>          ret = get_errno(chown(p, arg2, arg3));
>          unlock_user(p, arg1, 0);
>          break;
>  #endif
> -#ifdef TARGET_NR_setuid32
> +#if defined(TARGET_NR_setuid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setuid32)
>      case TARGET_NR_setuid32:
> +#else
> +    case TARGET_NR_setuid:
> +#endif
>          ret = get_errno(setuid(arg1));
>          break;
>  #endif
> -#ifdef TARGET_NR_setgid32
> +#if defined(TARGET_NR_setgid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setgid32)
>      case TARGET_NR_setgid32:
> +#else
> +    case TARGET_NR_setgid:
> +#endif
>          ret = get_errno(setgid(arg1));
>          break;
>  #endif
> -#ifdef TARGET_NR_setfsuid32
> +#if defined(TARGET_NR_setfsuid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setfsuid32)
>      case TARGET_NR_setfsuid32:
> +#else
> +    case TARGET_NR_setfsuid:
> +#endif
>          ret = get_errno(setfsuid(arg1));
>          break;
>  #endif
> -#ifdef TARGET_NR_setfsgid32
> +#if defined(TARGET_NR_setfsgid32) || !defined(USE_UID16)
> +#if defined(TARGET_NR_setfsgid32)
>      case TARGET_NR_setfsgid32:
> +#else
> +    case TARGET_NR_setfsgid:
> +#endif
>          ret = get_errno(setfsgid(arg1));
>          break;
>  #endif
> -- 
> 1.6.0.2
>
Alexander Graf - April 18, 2011, 9:11 p.m.
On 18.04.2011, at 18:32, Riku Voipio wrote:

> On Fri, Apr 15, 2011 at 05:32:44PM +0200, Alexander Graf wrote:
>> From: Ulrich Hecht <uli@suse.de>
>> 
>> Quite a number of syscalls are only defined on systems with USE_UID16
>> defined; this patch defines them on other systems as well.
>> 
>> Fixes a large number of uid/gid-related testcases on the s390x target
>> (and most likely on other targets as well)
> 
> I'll provide cleaner patch for the same effect. This one makes the code
> more ifdeffed and harder to follow.

You're more than welcome to. I only included the patch because it was part of Uli's original series :)


Alex

Patch

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 504b26c..99f5935 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -326,7 +326,7 @@  static int sys_fchmodat(int dirfd, const char *pathname, mode_t mode)
   return (fchmodat(dirfd, pathname, mode, 0));
 }
 #endif
-#if defined(TARGET_NR_fchownat) && defined(USE_UID16)
+#if defined(TARGET_NR_fchownat)
 static int sys_fchownat(int dirfd, const char *pathname, uid_t owner,
     gid_t group, int flags)
 {
@@ -435,7 +435,7 @@  _syscall3(int,sys_faccessat,int,dirfd,const char *,pathname,int,mode)
 #if defined(TARGET_NR_fchmodat) && defined(__NR_fchmodat)
 _syscall3(int,sys_fchmodat,int,dirfd,const char *,pathname, mode_t,mode)
 #endif
-#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat) && defined(USE_UID16)
+#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
 _syscall5(int,sys_fchownat,int,dirfd,const char *,pathname,
           uid_t,owner,gid_t,group,int,flags)
 #endif
@@ -6817,18 +6817,35 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_setfsgid:
         ret = get_errno(setfsgid(arg1));
         break;
+#else /* USE_UID16 */
+#if defined(TARGET_NR_fchownat) && defined(__NR_fchownat)
+    case TARGET_NR_fchownat:
+        if (!(p = lock_user_string(arg2)))
+            goto efault;
+        ret = get_errno(sys_fchownat(arg1, p, arg3, arg4, arg5));
+        unlock_user(p, arg2, 0);
+        break;
+#endif
 #endif /* USE_UID16 */
 
-#ifdef TARGET_NR_lchown32
+#if defined(TARGET_NR_lchown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_lchown32)
     case TARGET_NR_lchown32:
+#else
+    case TARGET_NR_lchown:
+#endif
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(lchown(p, arg2, arg3));
         unlock_user(p, arg1, 0);
         break;
 #endif
-#ifdef TARGET_NR_getuid32
+#if defined(TARGET_NR_getuid32) || (defined(TARGET_NR_getuid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getuid32)
     case TARGET_NR_getuid32:
+#else
+    case TARGET_NR_getuid:
+#endif
         ret = get_errno(getuid());
         break;
 #endif
@@ -6973,33 +6990,57 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
-#ifdef TARGET_NR_getgid32
+#if defined(TARGET_NR_getgid32) || (defined(TARGET_NR_getgid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getgid32)
     case TARGET_NR_getgid32:
+#else
+    case TARGET_NR_getgid:
+#endif
         ret = get_errno(getgid());
         break;
 #endif
-#ifdef TARGET_NR_geteuid32
+#if defined(TARGET_NR_geteuid32) || (defined(TARGET_NR_geteuid) && !defined(USE_UID16))
+#if defined(TARGET_NR_geteuid32)
     case TARGET_NR_geteuid32:
+#else
+    case TARGET_NR_geteuid:
+#endif
         ret = get_errno(geteuid());
         break;
 #endif
-#ifdef TARGET_NR_getegid32
+#if defined(TARGET_NR_getegid32) || (defined(TARGET_NR_getegid) && !defined(USE_UID16))
+#if defined(TARGET_NR_getegid32)
     case TARGET_NR_getegid32:
+#else
+    case TARGET_NR_getegid:
+#endif
         ret = get_errno(getegid());
         break;
 #endif
-#ifdef TARGET_NR_setreuid32
+#if defined(TARGET_NR_setreuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setreuid32)
     case TARGET_NR_setreuid32:
+#else
+    case TARGET_NR_setreuid:
+#endif
         ret = get_errno(setreuid(arg1, arg2));
         break;
 #endif
-#ifdef TARGET_NR_setregid32
+#if defined(TARGET_NR_setregid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setregid32)
     case TARGET_NR_setregid32:
+#else
+    case TARGET_NR_setregid:
+#endif
         ret = get_errno(setregid(arg1, arg2));
         break;
 #endif
-#ifdef TARGET_NR_getgroups32
+#if defined(TARGET_NR_getgroups32) || !defined(USE_UID16)
+#if defined(TARGET_NR_getgroups32)
     case TARGET_NR_getgroups32:
+#else
+    case TARGET_NR_getgroups:
+#endif
         {
             int gidsetsize = arg1;
             uint32_t *target_grouplist;
@@ -7023,8 +7064,12 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_setgroups32
+#if defined(TARGET_NR_setgroups32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setgroups32)
     case TARGET_NR_setgroups32:
+#else
+    case TARGET_NR_setgroups:
+#endif
         {
             int gidsetsize = arg1;
             uint32_t *target_grouplist;
@@ -7044,18 +7089,30 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_fchown32
+#if defined(TARGET_NR_fchown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_fchown32)
     case TARGET_NR_fchown32:
+#else
+    case TARGET_NR_fchown:
+#endif
         ret = get_errno(fchown(arg1, arg2, arg3));
         break;
 #endif
-#ifdef TARGET_NR_setresuid32
+#if defined(TARGET_NR_setresuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setresuid32)
     case TARGET_NR_setresuid32:
+#else
+    case TARGET_NR_setresuid:
+#endif
         ret = get_errno(setresuid(arg1, arg2, arg3));
         break;
 #endif
-#ifdef TARGET_NR_getresuid32
+#if defined(TARGET_NR_getresuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_getresuid32)
     case TARGET_NR_getresuid32:
+#else
+    case TARGET_NR_getresuid:
+#endif
         {
             uid_t ruid, euid, suid;
             ret = get_errno(getresuid(&ruid, &euid, &suid));
@@ -7068,13 +7125,21 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_setresgid32
+#if defined(TARGET_NR_setresgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setresgid32)
     case TARGET_NR_setresgid32:
+#else
+    case TARGET_NR_setresgid:
+#endif
         ret = get_errno(setresgid(arg1, arg2, arg3));
         break;
 #endif
+#if defined(TARGET_NR_getresgid32) || !defined(USE_UID16)
 #ifdef TARGET_NR_getresgid32
     case TARGET_NR_getresgid32:
+#else
+    case TARGET_NR_getresgid:
+#endif
         {
             gid_t rgid, egid, sgid;
             ret = get_errno(getresgid(&rgid, &egid, &sgid));
@@ -7087,31 +7152,51 @@  abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         }
         break;
 #endif
-#ifdef TARGET_NR_chown32
+#if defined(TARGET_NR_chown32) || !defined(USE_UID16)
+#if defined(TARGET_NR_chown32)
     case TARGET_NR_chown32:
+#else
+    case TARGET_NR_chown:
+#endif
         if (!(p = lock_user_string(arg1)))
             goto efault;
         ret = get_errno(chown(p, arg2, arg3));
         unlock_user(p, arg1, 0);
         break;
 #endif
-#ifdef TARGET_NR_setuid32
+#if defined(TARGET_NR_setuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setuid32)
     case TARGET_NR_setuid32:
+#else
+    case TARGET_NR_setuid:
+#endif
         ret = get_errno(setuid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setgid32
+#if defined(TARGET_NR_setgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setgid32)
     case TARGET_NR_setgid32:
+#else
+    case TARGET_NR_setgid:
+#endif
         ret = get_errno(setgid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setfsuid32
+#if defined(TARGET_NR_setfsuid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setfsuid32)
     case TARGET_NR_setfsuid32:
+#else
+    case TARGET_NR_setfsuid:
+#endif
         ret = get_errno(setfsuid(arg1));
         break;
 #endif
-#ifdef TARGET_NR_setfsgid32
+#if defined(TARGET_NR_setfsgid32) || !defined(USE_UID16)
+#if defined(TARGET_NR_setfsgid32)
     case TARGET_NR_setfsgid32:
+#else
+    case TARGET_NR_setfsgid:
+#endif
         ret = get_errno(setfsgid(arg1));
         break;
 #endif