qemu-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-commits] [qemu/qemu] 0a7ec8: linux-user: Fix 'semop()' and 'semtim


From: Peter Maydell
Subject: [Qemu-commits] [qemu/qemu] 0a7ec8: linux-user: Fix 'semop()' and 'semtimedop()' imple...
Date: Fri, 28 Aug 2020 16:15:26 -0700

  Branch: refs/heads/master
  Home:   https://github.com/qemu/qemu
  Commit: 0a7ec8493d506d82aa17bf0ab84231e0a92f8975
      
https://github.com/qemu/qemu/commit/0a7ec8493d506d82aa17bf0ab84231e0a92f8975
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/syscall.c
    M linux-user/syscall_defs.h

  Log Message:
  -----------
  linux-user: Fix 'semop()' and 'semtimedop()' implementation

The implementations of syscalls 'semop()' and 'semtimedop()' in
file 'syscall.c' use function 'target_to_host_sembuf()' to convert
values of 'struct sembuf' from host to target. However, before this
conversion it should be check whether the number of semaphore operations
'nsops' is not bigger than maximum allowed semaphor operations per
syscall: 'SEMOPM'. In these cases, errno 'E2BIG' ("Arg list too long")
should be set. But the implementation will set errno 'EFAULT' ("Bad address")
in this case since the conversion from target to host in this case fails.

This was confirmed with the LTP test for 'semop()' ('ipc/semop/semop02') in
test case where 'nsops' is greater than SEMOPM with unaproppriate errno EFAULT:

semop02.c:130: FAIL: semop failed unexpectedly; expected: E2BIG: EFAULT (14)

This patch changes this by adding a check whether 'nsops' is bigger than
'SEMOPM' before the conversion function 'target_to_host_sembuf()' is called.
After the changes from this patch, the test works fine along with the other
LTP testcases for 'semop()'):

semop02.c:126: PASS: semop failed as expected: E2BIG (7)

Implementation notes:

    A target value ('TARGET_SEMOPM') was added for 'SEMOPM' as to be sure
    in case the value is not available for some targets.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200818180722.45089-1-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: b09d64064bd1ea5e5c37b2d5089e1cc3f65801b2
      
https://github.com/qemu/qemu/commit/b09d64064bd1ea5e5c37b2d5089e1cc3f65801b2
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Fix 'clock_nanosleep()' implementation

Implementation of syscall 'clock_nanosleep()' in 'syscall.c' uses
functions 'target_to_host_timespec()' and 'host_to_target_timespec()'
to transfer the value of 'struct timespec' between target and host.
However, the implementation doesn't check whether this conversion
succeeds and thus can return an unaproppriate error instead of 'EFAULT'
that is expected. This was confirmed with the modified LTP test suite
where testcases with bad 'struct timespec' adress for 'clock_nanosleep()'
were added. This modified LTP suite can be found at:
https://github.com/bozutaf/ltp

(Patch with this new test case will be sent to LTP mailing list soon)

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200727201326.401519-1-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 913b03c2640bcf62c978386aa69a8c6099fa9424
      
https://github.com/qemu/qemu/commit/913b03c2640bcf62c978386aa69a8c6099fa9424
  Author: Chen Gang <chengang@emindsoft.com.cn>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/ioctls.h
    M linux-user/syscall.c
    M linux-user/syscall_defs.h
    M linux-user/syscall_types.h

  Log Message:
  -----------
  linux-user: syscall: ioctls: support DRM_IOCTL_I915_GETPARAM

Another DRM_IOCTL_I915 patches will be sent next.

Signed-off-by: Chen Gang <chengang@emindsoft.com.cn>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200802133938.12055-1-chengang@emindsoft.com.cn>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: e400e11941b036654202e638ad9a6518fea06fde
      
https://github.com/qemu/qemu/commit/e400e11941b036654202e638ad9a6518fea06fde
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/qemu.h
    M linux-user/strace.c
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Make cpu_env accessible in strace.c

Variable "cpu_env" is used in file "syscall.c" to store
the information about the cpu environment. This variable
is used because values of some syscalls can vary between
cpu architectures. This patch makes the "cpu_env" accessible
in "strace.c" so it can enable aproppriate "-strace" argument
printing for these syscalls. This will be a useful addition
for future "-strace" implementation in QEMU.

Implementation notes:

    Functions "print_syscall()" and "print_syscall_ret()" which
    are stated and defined in "qemu.h" and "strace.c" respectively
    are used to print syscall arguments before and after syscall
    execution. These functions were changed with addition of a
    new argument "void *cpu_env". Strucute "struct syscallname"
    in "strace.c" is used to store the information about syscalls.
    Fields "call" and "result" represent pointers to functions which
    are used to print syscall arguments before and after execution.
    These fields were also changed with addition of a new "void *"
    argumetn.
    Also, all defined "print_*" and "print_syscall_ret*" functions
    in "strace.c" were changed to have the new "void *cpu_env".
    This was done to not cause build errors (even though none of
    these functions use this argument).

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200811164553.27713-2-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 7c89f343836049b4732acde00db401e633335f8c
      
https://github.com/qemu/qemu/commit/7c89f343836049b4732acde00db401e633335f8c
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/qemu.h
    M linux-user/strace.c
    M linux-user/strace.list
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Add strace support for printing arguments of 
truncate()/ftruncate() and getsid()

This patch implements strace argument printing functionality for following 
syscalls:

    * truncate, ftruncate - truncate a file to a specified length

        int truncate/truncate64(const char *path, off_t length)
        int ftruncate/ftruncate64(int fd, off_t length)
        man page: https://man7.org/linux/man-pages/man2/truncate.2.html

    * getsid - get session ID

        pid_t getsid(pid_t pid)
        man page: https://man7.org/linux/man-pages/man2/getsid.2.html

Implementation notes:

    Syscalls truncate/truncate64 take string argument types and thus a
    separate print function "print_truncate/print_truncate64" is stated in
    file "strace.list". This function is defined and implemented in "strace.c"
    by using an existing function used to print string arguments: 
"print_string()".
    For syscall ftruncate64, a separate printing function was also stated in
    "strace.c" as it requires a special kind of handling.
    The other syscalls have only primitive argument types, so the rest of the
    implementation was handled by stating an appropriate printing format in file
    "strace.list".
    Function "regpairs_aligned()" was cut & pasted from "syscall.c" to "qemu.h"
    as it is used by functions "print_truncate64()" and "print_ftruncate64()"
    to print the offset arguments of "truncate64()" and "ftruncate64()".

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200811164553.27713-3-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 02e5d7d78e423bf8b3ebb66ab36bdaa7e962312a
      
https://github.com/qemu/qemu/commit/02e5d7d78e423bf8b3ebb66ab36bdaa7e962312a
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/aarch64/target_syscall.h
    M linux-user/alpha/target_syscall.h
    M linux-user/arm/target_syscall.h
    M linux-user/cris/target_syscall.h
    M linux-user/hppa/target_syscall.h
    M linux-user/i386/target_syscall.h
    M linux-user/m68k/target_syscall.h
    M linux-user/microblaze/target_syscall.h
    M linux-user/mips/target_syscall.h
    M linux-user/mips64/target_syscall.h
    M linux-user/nios2/target_syscall.h
    M linux-user/openrisc/target_syscall.h
    M linux-user/ppc/target_syscall.h
    M linux-user/riscv/target_syscall.h
    M linux-user/s390x/target_syscall.h
    M linux-user/sh4/target_syscall.h
    M linux-user/sparc/target_syscall.h
    M linux-user/sparc64/target_syscall.h
    M linux-user/strace.c
    M linux-user/strace.list
    M linux-user/syscall.c
    M linux-user/tilegx/target_syscall.h
    M linux-user/x86_64/target_syscall.h
    M linux-user/xtensa/target_syscall.h

  Log Message:
  -----------
  linux-user: Add strace support for printing arguments of syscalls used to 
lock and unlock memory

This patch implements strace argument printing functionality for following 
syscalls:

    * mlock, munlock, mlockall, munlockall - lock and unlock memory

       int mlock(const void *addr, size_t len)
       int munlock(const void *addr, size_t len)
       int mlockall(int flags)
       int munlockall(void)
       man page: https://man7.org/linux/man-pages/man2/mlock.2.html

Implementation notes:

    Syscall mlockall() takes an argument that is composed of predefined values
    which represent flags that determine the type of locking operation that is
    to be performed. For that reason, a printing function "print_mlockall" was
    stated in file "strace.list". This printing function uses an already 
existing
    function "print_flags()" to print the "flags" argument.  These flags are 
stated
    inside an array "mlockall_flags" that contains values of type "struct 
flags".
    These values are instantiated using an existing macro "FLAG_TARGET()" that
    crates aproppriate target flag values based on those defined in files
    '/target_syscall.h'. These target flag values were changed from
    "TARGET_MLOCKALL_MCL*" to "TARGET_MCL_*" so that they can be aproppriately 
set
    and recognised in "strace.c" with "FLAG_TARGET()". Value for "MCL_ONFAULT"
    was added in this patch. This value was also added in "syscall.c" in 
function
    "target_to_host_mlockall_arg()". Because this flag value was added in kernel
    version 4.4, it is enwrapped in an #ifdef directive (both in "syscall.c" and
    in "strace.c") as to support older kernel versions.
    The other syscalls have only primitive argument types, so the
    rest of the implementation was handled by stating an appropriate
    printing format in file "strace.list". Syscall mlock2() is not implemented 
in
    "syscall.c" and thus it's argument printing is not implemented in this 
patch.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200811164553.27713-4-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 45f567994c2f0272cede9956ed0ea0d8a6294495
      
https://github.com/qemu/qemu/commit/45f567994c2f0272cede9956ed0ea0d8a6294495
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/strace.c

  Log Message:
  -----------
  linux-user: Add an api to print enumareted argument values with strace

This patch introduces a type 'struct enums' and function 'print_enums()'
that can be used to print enumerated argument values of some syscalls
in strace. This can be used in future strace implementations.

Also, macros 'ENUM_GENERIC()', 'ENUM_TARGET()' and 'ENUM_END', are
introduced to enable automatic generation of aproppriate enumarated
values and their repsective string representations (these macros are
exactly the same as 'FLAG_GENERIC()', 'FLAG_TARGET()' and 'FLAG_END').

Future patches are planned to modify all existing print functions in
'strace.c' that print arguments of syscalls with enumerated values to
use this new api.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200811164553.27713-5-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 1a674adf983204cfa5b5cc35185f2bf3274992c6
      
https://github.com/qemu/qemu/commit/1a674adf983204cfa5b5cc35185f2bf3274992c6
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/strace.c
    M linux-user/strace.list

  Log Message:
  -----------
  linux-user: Add strace support for printing arguments of some clock and time 
functions

This patch implements strace argument printing functionality for following 
syscalls:

    * clock_getres, clock_gettime, clock_settime - clock and time functions

        int clock_getres(clockid_t clockid, struct timespec *res)
        int clock_gettime(clockid_t clockid, struct timespec *tp)
        int clock_settime(clockid_t clockid, const struct timespec *tp)
        man page: https://man7.org/linux/man-pages/man2/clock_getres.2.html

    * gettimeofday - get time

        int gettimeofday(struct timeval *tv, struct timezone *tz)
        man page: https://man7.org/linux/man-pages/man2/gettimeofday.2.html

    * getitimer, setitimer - get or set value of an interval timer

        int getitimer(int which, struct itimerval *curr_value)
        int setitimer(int which, const struct itimerval *new_value,
                      struct itimerval *old_value)
        man page: https://man7.org/linux/man-pages/man2/getitimer.2.html

Implementation notes:

    All of the syscalls have some structue types as argument types and thus
    a separate printing function was stated in file "strace.list" for each
    of them. All of these functions use existing functions for their
    appropriate structure types ("print_timeval()" and "print_timezone()").

    Functions "print_timespec()" and "print_itimerval()" were added in this
    patch so that they can be used to print types "struct timespec" and
    "struct itimerval" used by some of the syscalls. Function 
"print_itimerval()"
    uses the existing function "print_timeval()" to print fields of the
    structure "struct itimerval" that are of type "struct timeval".

    Function "print_enums()", which was introduced in the previous patch, is 
used
    to print the interval timer type which is the first argument of 
"getitimer()"
    and "setitimer()". Also, this function is used to print the clock id which
    is the first argument of "clock_getres()" and "clock_gettime()". For that
    reason, the existing function "print_clockid()" was removed in this patch.
    Existing function "print_clock_adjtime()" was also changed for this reason
    to use "print_enums()".

    The existing function "print_timeval()" was changed a little so that it
    prints the field names beside the values.

    Syscalls "clock_getres()" and "clock_gettime()" have the same number
    and types of arguments and thus their print functions "print_clock_getres"
    and "print_clock_gettime" share a common definition in file "strace.c".

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200811164553.27713-6-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: fcb6fcf63bab7582d847b956804fe45e536e38c0
      
https://github.com/qemu/qemu/commit/fcb6fcf63bab7582d847b956804fe45e536e38c0
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/aarch64/termbits.h
    M linux-user/arm/termbits.h
    A linux-user/generic/termbits.h
    M linux-user/i386/termbits.h
    M linux-user/m68k/termbits.h
    M linux-user/microblaze/termbits.h
    M linux-user/nios2/termbits.h
    M linux-user/openrisc/termbits.h
    M linux-user/riscv/termbits.h
    M linux-user/s390x/termbits.h
    M linux-user/tilegx/termbits.h
    M linux-user/x86_64/termbits.h

  Log Message:
  -----------
  linux-user: Add generic 'termbits.h' for some archs

This patch introduces a generic 'termbits.h' file for following
archs: 'aarch64', 'arm', 'i386, 'm68k', 'microblaze', 'nios2',
'openrisc', 'riscv', 's390x', 'x86_64'.

Since all of these archs have the same termios flag values and
same ioctl_tty numbers, there is no need for a separate 'termbits.h'
file for each one of them. For that reason one generic 'termbits.h'
file was added for all of them and an '#include' directive was
added for this generic file in every arch 'termbits.h' file.

Also, some of the flag values that were missing were added in this
generic file so that it matches the generic 'termibts.h' and 'ioctls.h'
files from the kernel: 'asm-generic/termbits.h' and 'asm-generic/ioctls.h'.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200723210233.349690-2-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: c218b4ede4f9f8bdd210233f24ab2356f0e04d49
      
https://github.com/qemu/qemu/commit/c218b4ede4f9f8bdd210233f24ab2356f0e04d49
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/alpha/termbits.h
    M linux-user/cris/termbits.h
    M linux-user/hppa/termbits.h
    M linux-user/mips/termbits.h
    M linux-user/ppc/termbits.h
    M linux-user/sh4/termbits.h
    M linux-user/sparc/termbits.h
    M linux-user/sparc64/termbits.h
    M linux-user/syscall.c
    M linux-user/xtensa/termbits.h

  Log Message:
  -----------
  linux-user: Add missing termbits types and values definitions

This patch introduces missing target types ('target_flag_t', 'target_cc_t',
'target_speed_t') in a few 'termibts.h' header files. Also, two missing
values ('TARGET_IUTF8' and 'TARGET_EXTPROC') were also added. These values
were also added in file 'syscall.c' in bitmask tables 'iflag_tbl[]' and
'lflag_tbl[]' which are used to convert values of 'struct termios' between
target and host.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200723210233.349690-3-Filip.Bozuta@syrmia.com>
[lv: keep TARGET_NCCS definition in xtensa/termbits.h]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 888468db949e8ea1641c33d97e70b70f57eb69e9
      
https://github.com/qemu/qemu/commit/888468db949e8ea1641c33d97e70b70f57eb69e9
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M include/exec/user/thunk.h
    M linux-user/qemu.h
    M linux-user/strace.c
    M linux-user/syscall.c
    M thunk.c

  Log Message:
  -----------
  linux-user: Add strace support for printing arguments for ioctls used for 
terminals and serial lines

Functions "print_ioctl()" and "print_syscall_ret_ioctl()" are used
to print arguments of "ioctl()" with "-strace". These functions
use "thunk_print()", which is defined in "thunk.c", to print the
contents of ioctl's third arguments that are not basic types.

However, this function doesn't handle ioctls of group ioctl_tty which
are used for terminals and serial lines. These ioctls use a type
"struct termios" which thunk type is defined in a non standard
way using "STRUCT_SPECIAL()". This means that this type is not decoded
regularly using "thunk_convert()" and uses special converting functions
"target_to_host_termios()" and "host_to_target_termios()", which are defined
in "syscall.c" to decode it's values.

For simillar reasons, this type is also not printed regularly using
"thunk_print()". That is the reason why a separate printing function
"print_termios()" is defined in file "strace.c". This function decodes
and prints flag values of the "termios" structure.

Implementation notes:

    Function "print_termios()" was implemented in "strace.c" using
    an existing function "print_flags()" to print flag values of
    "struct termios" fields. Also, recently implemented function
    "print_enums()" was also used to print enumareted values which
    are contained in the fields of 'struct termios'.

    These flag values were defined using an existing macro "FLAG_TARGET()"
    that generates aproppriate target flag values and string representations
    of these flags. Also, the recently defined macro "ENUM_TARGET()" was
    used to generate aproppriate enumarated values and their respective
    string representations.

    Function "print_termios()" was declared in "qemu.h" so that it can
    be accessed in "syscall.c". Type "StructEntry" defined in
    "exec/user/thunk.h" contains information that is used to decode
    structure values. Field "void print(void *arg)" was added in this
    structure as a special print function. Also, function "thunk_print()"
    was changed a little so that it uses this special print function
    in case it is defined. This printing function was instantiated with
    the defined "print_termios()" in "syscall.c" in "struct_termios_def".

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200723210233.349690-4-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: ace3d65459a01bfd8c2c59ecabb5fd6839b2de54
      
https://github.com/qemu/qemu/commit/ace3d65459a01bfd8c2c59ecabb5fd6839b2de54
  Author: Carlo Marcelo Arenas Belón <carenas@gmail.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/elfload.c

  Log Message:
  -----------
  linux-user: detect mismatched ELF ABI in qemu-mips[n32][el]

MIPS provides 2 ILP32 ABIs, and therefore 4 possible qemu-mips binaries
with 2 pairs using the same endianess and bitness.

This could lead to an O32 image loading in the N32 binary or vice versa
and in cryptic errors (if lucky that the CPU doesn't match the FPU used)
like :

  qemu: Unexpected FPU mode       (o32 ELF loaded to qemu-mipsn32[el])
  ELF binary's NaN mode not supported by CPU    (n32 -> qemu-mips[el])

Add an ABI check macro that could be used while checking the ELF header
that relies in the ABI2 flag to identify n32 binaries and abort instead
early with a more descriptive error :

  Invalid ELF image for this architecture

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200823101703.18451-1-carenas@gmail.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: dcbcf5cf1cddd0fa3e39fbea3b97e6cd0b5078f4
      
https://github.com/qemu/qemu/commit/dcbcf5cf1cddd0fa3e39fbea3b97e6cd0b5078f4
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Fix 'mq_timedsend()' and 'mq_timedreceive()'

Implementations of syscalls 'mq_timedsend()' and 'mq_timedreceive()'
in 'syscall.c' use functions 'target_to_host_timespec()' and
'host_to_target_timespec()' to transfer the value of 'struct timespec'
between target and host. However, the implementations don'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 modified LTP
test suite where test cases with a bad adress for 'timespec' were
added. This modified test suite can be found at:
https://github.com/bozutaf/ltp

Without the changes from this patch the bad adress testcase for 'mq_timedsend()'
succeds unexpectedly, while the test returns errno 'ETIMEOUT' for
'mq_timedreceive()':

mq_timedsend01.c:190: FAIL: mq_timedsend() returned 0, expected -1: SUCCESS (0)
mq_timedreceive01.c:178: FAIL: mq_timedreceive() failed unexpectedly,
expected EFAULT: ETIMEDOUT (110)

After the changes from this patch, testcases for both syscalls fail with EFAULT
as expected, which is the same test result that is received with native 
execution:

mq_timedsend01.c:187: PASS: mq_timedsend() failed expectedly: EFAULT (14)
mq_timedreceive01.c:180: PASS: mq_timedreceive() failed expectedly: EFAULT (14)

(Patch with this new test case will be sent to LTP mailing list soon)

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824193752.67950-2-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 00576757893aa63d221418a1d05c08ed10f94c09
      
https://github.com/qemu/qemu/commit/00576757893aa63d221418a1d05c08ed10f94c09
  Author: Laurent Vivier <laurent@vivier.eu>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: fix target_to_host_timespec64()

in 32 bit mode, drop the padding in tv_nsec. If host is 64bit and target
is 32bit, the padding bytes will be copied from the target and as the
kernel checks the value, the syscall exits with EINVAL.

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200827070449.2386007-1-laurent@vivier.eu>
Fixes: c6c8d1026e75 ("linux-user/syscall: Add support for 
clock_gettime64/clock_settime64")


  Commit: d107e375738756b0603ce0dcb5ca460966783909
      
https://github.com/qemu/qemu/commit/d107e375738756b0603ce0dcb5ca460966783909
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-27 (Thu, 27 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Add support for 'mq_timedsend_time64()' and 
'mq_timedreceive_time64()'

This patch implements functionality for following time64 syscalls:

*mq_timedsend_time64()

    This is a year 2038 safe vairant of syscall:

    int mq_timedsend(mqd_t mqdes, const char *msg_ptr,
                     size_t msg_len, unsigned int msg_prio,
                     const struct timespec *abs_timeout)
    --send a message to a message queue--
    man page: https://www.man7.org/linux/man-pages/man2/mq_timedsend.2.html

*mq_timedreceive_time64()

    This is a year 2038 safe variant of syscall:

    ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr,
                            size_t msg_len, unsigned int *msg_prio,
                            const struct timespec *abs_timeout)
    --receive a message from a message queue--
    man page: https://man7.org/linux/man-pages/man3/mq_receive.3.html

Implementation notes:

    These syscalls were implemented in similar ways like
    'mq_timedsend()' and 'mq_timedreceive' except that
    functions 'target_to_host_timespec64()' and
    'host_to_target_timespec64()' were used to convert
    values of 'struct timespec' between host and target.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824193752.67950-3-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 6ac03b2cacbadbaf631ca16582f0e9b716653a32
      
https://github.com/qemu/qemu/commit/6ac03b2cacbadbaf631ca16582f0e9b716653a32
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-28 (Fri, 28 Aug 2020)

  Changed paths:
    M linux-user/syscall.c
    M linux-user/syscall_defs.h

  Log Message:
  -----------
  linux-user: Add support for 'clock_nanosleep_time64()' and 'clock_adjtime64()'

This patch implements functionality for following time64 syscall:

*clock_nanosleep_time64()

    This is a year 2038 safe vairant of syscall:
    int clock_nanosleep(clockid_t clockid, int flags,
                        const struct timespec *request,
                        struct timespec *remain)
    --high-resolution sleep with specifiable clock--
    man page: https://man7.org/linux/man-pages/man2/clock_nanosleep.2.html

*clock_adjtime64()

    This is a year 2038 safe variant of syscall:
    int clock_adjtime(clockid_t clk_id, struct timex *buf)
    --tune kernel clock--
    man page: https://man7.org/linux/man-pages/man2/clock_adjtime.2.html

Implementation notes:

    Syscall 'clock_nanosleep_time64()' was implemented similarly
    to syscall 'clock_nanosleep()' except that 'host_to_target_timespec64()'
    and 'target_to_host_timespec64()' were used instead of the regular
    'host_to_target_timespec()' and 'target_to_host_timespec()'.

    For 'clock_adjtime64()' a 64-bit target kernel version of 'struct timex'
    was defined in 'syscall_defs.h': 'struct target__kernel_timex'.
    This type was used to convert the values of 64-bit timex type between
    host and target. For this purpose a 64-bit timex converting functions
    'target_to_host_timex64()' and 'host_to_target_timex64()'. An existing
    function 'copy_to_user_timeval64()' was used to convert the field
    'time' which if of type 'struct timeval' from host to target.
    Function 'copy_from_user_timveal64()' was added in this patch and
    used to convert the 'time' field from target to host.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824192116.65562-2-Filip.Bozuta@syrmia.com>
[lv: add missing ifdef's]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: ddcbde157d66f7ee53d9789cf605ebaa4be0745e
      
https://github.com/qemu/qemu/commit/ddcbde157d66f7ee53d9789cf605ebaa4be0745e
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-28 (Fri, 28 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Add support for 'rt_sigtimedwait_time64()' and 
'sched_rr_get_interval_time64()'

This patch implements functionality for following time64 syscalls:

*rt_sigtimedwait_time64()

    This is a year 2038 safe variant of syscall:

    int rt_sigtimedwait(const sigset_t *set, siginfo_t *info,
                        const struct timespec *timeout, size_t sigsetsize)
    --synchronously wait for queued signals--
    man page: https://man7.org/linux/man-pages/man2/rt_sigtimedwait.2.html

*sched_rr_get_interval_time64()

    This is a year 2038 safe variant of syscall:

    int sched_rr_get_interval(pid_t pid, struct timespec *tp)
    --get  the  SCHED_RR  interval  for the named process--
    man page: https://man7.org/linux/man-pages/man2/sched_rr_get_interval.2.html

Implementation notes:

    These syscalls were implemented in similar ways like
    'rt_sigtimedwait()' and 'sched_rr_get_interval()' except
    that functions 'target_to_host_timespec64()' and
    'host_to_target_timespec64()' were used to convert values
    of 'struct timespec' between host and target.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824192116.65562-3-Filip.Bozuta@syrmia.com>
[lv: add missing defined(TARGET_NR_rt_sigtimedwait_time64)]
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: cac46eb021fbbac77f1f98223b19608f31fc2236
      
https://github.com/qemu/qemu/commit/cac46eb021fbbac77f1f98223b19608f31fc2236
  Author: Filip Bozuta <Filip.Bozuta@syrmia.com>
  Date:   2020-08-28 (Fri, 28 Aug 2020)

  Changed paths:
    M linux-user/syscall.c

  Log Message:
  -----------
  linux-user: Add support for utimensat_time64() and semtimedop_time64()

This patch introduces functionality for following time64 syscalls:

*utimensat_time64()

    int utimensat(int dirfd, const char *pathname,
                  const struct timespec times[2], int flags);
    -- change file timestamps with nanosecond precision --
    man page: https://man7.org/linux/man-pages/man2/utimensat.2.html

*semtimedop_time64()

    int semtimedop(int semid, struct sembuf *sops, size_t nsops,
                   const struct timespec *timeout);
    -- System V semaphore operations --
    man page: https://www.man7.org/linux/man-pages/man2/semtimedop.2.html

Implementation notes:

   Syscall 'utimensat_time64()' is implemented in similar way as its
   regular variants only difference being that time64 converting function
   is used to convert values of 'struct timespec' between host and target
   ('target_to_host_timespec64()').

   For syscall 'semtimedop_time64()' and additional argument is added
   in function 'do_semtimedop()' through which the aproppriate 'struct timespec'
   converting function is called (false for regular target_to_host_timespec()
   and true for target_to_host_timespec64()). For 'do_ipc()' a
   check was added as that additional argument: 'TARGET_ABI_BITS == 64'.

Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20200824223050.92032-3-Filip.Bozuta@syrmia.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>


  Commit: 39335fab59e11cfda9b7cf63929825db2dd3a3e0
      
https://github.com/qemu/qemu/commit/39335fab59e11cfda9b7cf63929825db2dd3a3e0
  Author: Peter Maydell <peter.maydell@linaro.org>
  Date:   2020-08-28 (Fri, 28 Aug 2020)

  Changed paths:
    M include/exec/user/thunk.h
    M linux-user/aarch64/target_syscall.h
    M linux-user/aarch64/termbits.h
    M linux-user/alpha/target_syscall.h
    M linux-user/alpha/termbits.h
    M linux-user/arm/target_syscall.h
    M linux-user/arm/termbits.h
    M linux-user/cris/target_syscall.h
    M linux-user/cris/termbits.h
    M linux-user/elfload.c
    A linux-user/generic/termbits.h
    M linux-user/hppa/target_syscall.h
    M linux-user/hppa/termbits.h
    M linux-user/i386/target_syscall.h
    M linux-user/i386/termbits.h
    M linux-user/ioctls.h
    M linux-user/m68k/target_syscall.h
    M linux-user/m68k/termbits.h
    M linux-user/microblaze/target_syscall.h
    M linux-user/microblaze/termbits.h
    M linux-user/mips/target_syscall.h
    M linux-user/mips/termbits.h
    M linux-user/mips64/target_syscall.h
    M linux-user/nios2/target_syscall.h
    M linux-user/nios2/termbits.h
    M linux-user/openrisc/target_syscall.h
    M linux-user/openrisc/termbits.h
    M linux-user/ppc/target_syscall.h
    M linux-user/ppc/termbits.h
    M linux-user/qemu.h
    M linux-user/riscv/target_syscall.h
    M linux-user/riscv/termbits.h
    M linux-user/s390x/target_syscall.h
    M linux-user/s390x/termbits.h
    M linux-user/sh4/target_syscall.h
    M linux-user/sh4/termbits.h
    M linux-user/sparc/target_syscall.h
    M linux-user/sparc/termbits.h
    M linux-user/sparc64/target_syscall.h
    M linux-user/sparc64/termbits.h
    M linux-user/strace.c
    M linux-user/strace.list
    M linux-user/syscall.c
    M linux-user/syscall_defs.h
    M linux-user/syscall_types.h
    M linux-user/tilegx/target_syscall.h
    M linux-user/tilegx/termbits.h
    M linux-user/x86_64/target_syscall.h
    M linux-user/x86_64/termbits.h
    M linux-user/xtensa/target_syscall.h
    M linux-user/xtensa/termbits.h
    M thunk.c

  Log Message:
  -----------
  Merge remote-tracking branch 
'remotes/vivier2/tags/linux-user-for-5.2-pull-request' into staging

add utimensat_time64, semtimedop_time64, rt_sigtimedwait_time64,
    sched_rr_get_interval_time64, clock_nanosleep_time64, clock_adjtime64,
    mq_timedsend_time64, mq_timedreceive_time64
fix semop, semtimedop, clock_nanosleep, mq_timedsend, target_to_host_timespec64
fix tembits.h
add more strace function
Add upport DRM_IOCTL_I915_GETPARAM
detect mismatched ELF ABI in qemu-mips[n32][el]

# gpg: Signature made Fri 28 Aug 2020 14:37:33 BST
# gpg:                using RSA key CD2F75DDC8E3A4DC2E4F5173F30C38BD3F2FBE3C
# gpg:                issuer "laurent@vivier.eu"
# gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" [full]
# gpg:                 aka "Laurent Vivier <laurent@vivier.eu>" [full]
# gpg:                 aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" 
[full]
# Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F  5173 F30C 38BD 3F2F BE3C

* remotes/vivier2/tags/linux-user-for-5.2-pull-request:
  linux-user: Add support for utimensat_time64() and semtimedop_time64()
  linux-user: Add support for 'rt_sigtimedwait_time64()' and 
'sched_rr_get_interval_time64()'
  linux-user: Add support for 'clock_nanosleep_time64()' and 'clock_adjtime64()'
  linux-user: Add support for 'mq_timedsend_time64()' and 
'mq_timedreceive_time64()'
  linux-user: fix target_to_host_timespec64()
  linux-user: Fix 'mq_timedsend()' and 'mq_timedreceive()'
  linux-user: detect mismatched ELF ABI in qemu-mips[n32][el]
  linux-user: Add strace support for printing arguments for ioctls used for 
terminals and serial lines
  linux-user: Add missing termbits types and values definitions
  linux-user: Add generic 'termbits.h' for some archs
  linux-user: Add strace support for printing arguments of some clock and time 
functions
  linux-user: Add an api to print enumareted argument values with strace
  linux-user: Add strace support for printing arguments of syscalls used to 
lock and unlock memory
  linux-user: Add strace support for printing arguments of 
truncate()/ftruncate() and getsid()
  linux-user: Make cpu_env accessible in strace.c
  linux-user: syscall: ioctls: support DRM_IOCTL_I915_GETPARAM
  linux-user: Fix 'clock_nanosleep()' implementation
  linux-user: Fix 'semop()' and 'semtimedop()' implementation

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>


Compare: https://github.com/qemu/qemu/compare/a4e236b7d4ba...39335fab59e1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]