V3 [PATCH 1/2] Add SYSCALL_ULONG_ARG_[12] to pass long to syscall [BZ #25810]

H.J. Lu hjl.tools@gmail.com
Wed Apr 29 13:15:31 GMT 2020


On Wed, Apr 29, 2020 at 5:14 AM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > diff --git a/sysdeps/unix/make-syscalls.sh b/sysdeps/unix/make-syscalls.sh
> > index c07626677f..4f6c3490a2 100644
> > --- a/sysdeps/unix/make-syscalls.sh
> > +++ b/sysdeps/unix/make-syscalls.sh
> > @@ -30,6 +30,7 @@
> >  # P: optionally-NULL pointer to typed object (e.g., 3rd argument to sigaction)
> >  # s: non-NULL string (e.g., 1st arg to open)
> >  # S: optionally-NULL string (e.g., 1st arg to acct)
> > +# U: unsigned long int (32-bit types are zero-extended to 64-bit types)
> >  # v: vararg scalar (e.g., optional 3rd arg to open)
> >  # V: byte-per-page vector (3rd arg to mincore)
> >  # W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)
> > @@ -184,6 +185,27 @@ while read file srcfile caller syscall args strong weak; do
> >    ?:?????????) nargs=9;;
> >    esac
> >
> > +  # Derive the unsigned long int arguments from the argument signature
> > +  ulong_arg_1=0
> > +  ulong_arg_2=0
> > +  ulong_count=0
> > +  for U in $(echo $args | sed -e "s/.*:/:/" | grep -ob U)
> > +  do
> > +    ulong_count=$(expr $ulong_count + 1)
> > +    ulong_arg=$(echo $U | sed -e "s/:U//")
> > +    case $ulong_count in
> > +    1)
> > +      ulong_arg_1=$ulong_arg
> > +      ;;
> > +    2)
> > +      ulong_arg_2=$ulong_arg
> > +      ;;
> > +    *)
> > +      echo >&2 "$0: Too many unsigned long int arguments for syscall ($strong $weak)"
> > +      exit 2
> > +    esac
> > +  done
>
> This version is much better.  -ob isn't specific to GNU grep
> (FreeBSD's base system grep has it as well), so maybe we don't need to
> update INSTALL.
>
> > diff --git a/sysdeps/unix/syscalls.list b/sysdeps/unix/syscalls.list
> > index 01c4a0e6b1..0cf290076d 100644
> > --- a/sysdeps/unix/syscalls.list
> > +++ b/sysdeps/unix/syscalls.list
> > @@ -37,16 +37,16 @@ kill              -       kill            i:ii    __kill          kill
> >  link         -       link            i:ss    __link          link
> >  listen               -       listen          i:ii    __listen        listen
> >  lseek                -       lseek           i:iii   __libc_lseek    __lseek lseek
> > -madvise              -       madvise         i:pii   __madvise       madvise
> > +madvise              -       madvise         i:pUi   __madvise       madvise
> >  mkdir                -       mkdir           i:si    __mkdir         mkdir
> >  mmap         -       mmap            b:aniiii __mmap         mmap
> > -mprotect     -       mprotect        i:aii   __mprotect      mprotect
> > -munmap               -       munmap          i:ai    __munmap        munmap
> > +mprotect     -       mprotect        i:aUi   __mprotect      mprotect
> > +munmap               -       munmap          i:aU    __munmap        munmap
> >  open         -       open            Ci:siv  __libc_open __open open
> >  profil               -       profil          i:piii  __profil        profil
> >  ptrace               -       ptrace          i:iiii  ptrace
> >  read         -       read            Ci:ibn  __libc_read     __read read
> > -readlink     -       readlink        i:spi   __readlink      readlink
> > +readlink     -       readlink        i:spU   __readlink      readlink
> >  readv                -       readv           Ci:ipi  __readv         readv
> >  reboot               -       reboot          i:i     reboot
> >  recv         -       recv            Ci:ibni __libc_recv     recv
>
>
> I went through the list of syscalls, and the following have size
> arguments which need markup (even though they may not be used on Linux):
>
> bind

Kernel has

SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
{
        return __sys_bind(fd, umyaddr, addrlen);
}

No change is needed.

> connect

SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
                int, addrlen)
{
        return __sys_connect(fd, uservaddr, addrlen);
}

> mmap

Will fix.

> read

Will fix.

> recv

Will fix.

> recvrom

Will fix

> recvmsg

Kernel has

SYSCALL_DEFINE3(recvmsg, int, fd, struct user_msghdr __user *, msg,
                unsigned int, flags)
{
        return __sys_recvmsg(fd, msg, flags, true);
}

No change is needed.

> send

Will fix.

> sendmsg

Kernel has

SYSCALL_DEFINE3(sendmsg, int, fd, struct user_msghdr __user *, msg,
unsigned int, flags)
{
        return __sys_sendmsg(fd, msg, flags, true);
}

No change is needed.

> sendto (twice)

Kernel has

SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
                unsigned int, flags, struct sockaddr __user *, addr,
                int, addr_len)
{
        return __sys_sendto(fd, buff, len, flags, addr, addr_len);
}

There is only one size_t.

> write

Will fix.

> getdomainname, getgroups, gethostname, sethostname, setsockopt are
> exceptions, they have int size argument in userspace and on the kernel
> side and should therefore not be changed.
>
> fstatfs and statfs do not match the Linux interface, so the correct
> setting is unclear.

No change.

> There's a mismatch between the kernel and userspace definitions for
> readv, writev, setgroups (but not getgroups).

No change.

>
> > diff --git a/sysdeps/unix/sysv/linux/syscalls.list b/sysdeps/unix/sysv/linux/syscalls.list
> > index e40f993495..1b1010d4c8 100644
> > --- a/sysdeps/unix/sysv/linux/syscalls.list
> > +++ b/sysdeps/unix/sysv/linux/syscalls.list
> > @@ -32,12 +32,12 @@ ioperm            -       ioperm          i:iii   ioperm
> >  iopl         -       iopl            i:i     iopl
> >  klogctl              EXTRA   syslog          i:isi   klogctl
> >  lchown               -       lchown          i:sii   __lchown        lchown
> > -mincore              -       mincore         i:anV   mincore
> > -mlock                -       mlock           i:bn    mlock
> > +mincore              -       mincore         i:aUV   mincore
> > +mlock                -       mlock           i:bU    mlock
> >  mlockall     -       mlockall        i:i     mlockall
> > -mount                EXTRA   mount           i:sssip __mount mount
> > -mremap               EXTRA   mremap          b:ainip __mremap        mremap
> > -munlock              -       munlock         i:ai    munlock
> > +mount                EXTRA   mount           i:sssUp __mount mount
> > +mremap               EXTRA   mremap          b:aUUip __mremap        mremap
> > +munlock              -       munlock         i:aU    munlock
> >  munlockall   -       munlockall      i:      munlockall
> >  nfsservctl   EXTRA   nfsservctl      i:ipp   __compat_nfsservctl     nfsservctl@GLIBC_2.0:GLIBC_2.28
> >  pipe         -       pipe            i:f     __pipe          pipe
> > @@ -46,7 +46,7 @@ pivot_root  EXTRA   pivot_root      i:ss    pivot_root
> >  prctl                EXTRA   prctl           i:iiiii __prctl         prctl
> >  query_module EXTRA   query_module    i:sipip __compat_query_module   query_module@GLIBC_2.0:GLIBC_2.23
> >  quotactl     EXTRA   quotactl        i:isip  quotactl
> > -remap_file_pages -   remap_file_pages i:piiii        __remap_file_pages remap_file_pages
> > +remap_file_pages -   remap_file_pages i:pUiUi        __remap_file_pages remap_file_pages
> >  sched_getp   -       sched_getparam  i:ip    __sched_getparam        sched_getparam
> >  sched_gets   -       sched_getscheduler      i:i     __sched_getscheduler    sched_getscheduler
> >  sched_primax -       sched_get_priority_max  i:i     __sched_get_priority_max        sched_get_priority_max
> > @@ -54,7 +54,7 @@ sched_primin        -       sched_get_priority_min  i:i     __sched_get_priority_min        sched_get_pri
> >  sched_setp   -       sched_setparam  i:ip    __sched_setparam        sched_setparam
> >  sched_sets   -       sched_setscheduler      i:iip   __sched_setscheduler    sched_setscheduler
> >  sched_yield  -       sched_yield     i:      __sched_yield   sched_yield
> > -sendfile     -       sendfile        i:iipi  sendfile
> > +sendfile     -       sendfile        i:iipU  sendfile
> >  sendfile64   -       sendfile64      i:iipi  sendfile64
> >  setfsgid     EXTRA   setfsgid        i:i     setfsgid
> >  setfsuid     EXTRA   setfsuid        i:i     setfsuid
> > @@ -71,7 +71,7 @@ chown               -       chown           i:sii   __libc_chown    __chown chown
> >  fchownat     -       fchownat        i:isiii fchownat
> >  linkat               -       linkat          i:isisi linkat
> >  mkdirat              -       mkdirat         i:isi   mkdirat
> > -readlinkat   -       readlinkat      i:issi  readlinkat
> > +readlinkat   -       readlinkat      i:issU  readlinkat
> >  symlinkat    -       symlinkat       i:sis   symlinkat
> >  unlinkat     -       unlinkat        i:isi   unlinkat
>
> Missing updates:
>
> ioperm

Will fix.

> sendfile64

Will fix.

> setxattr
> setxattr
> lsetxattr
> fsetxattr
> getxattr
> lgetxattr
> fgetxattr
> listxattr
> llistxattr
> flistxattr

Will fix them.

> prctl looks busted (too many arguments).  It will need a C wrapper, I
> think.  Likewise process_vm_readv, process_vm_writev.  These can be a
> separate patches, I guess.

Will do.

> epoll_create is special (int size argument).
>
> The rest of the patch looks good to me.  It's okay to push this if you
> can verify that stripped libc.so.6 does not change on i686 and x86-64.

Thanks.

-- 
H.J.


More information about the Libc-alpha mailing list