1140 Commits

Author SHA1 Message Date
Mark Wielaard
bd27ad3ff3 Hook linux copy_file_range syscall on arm. 2019-05-05 16:01:41 +02:00
Alexandra Hajkova
5f00db054a Add support for the copy_file_range syscall
Support amd64, x86, arm64, ppc64, ppc32 and s390x architectures.
Also add sys-copy_file_range test case.
2019-05-05 15:27:13 +02:00
Petar Jovanovic
37f09ed248 mips32: pass correct syscall value to kernel in case of __NR_syscall
The syscall number has to be put in register v0 before call into the kernel.
This was omitted when system call is __NR_syscall (and when the syscall
argument is the system call number of interest).

Patch by Nikola Milutinovic.
2019-04-03 17:40:08 +00:00
Petar Jovanovic
dc950d964b mips: get rid of format and implicit-fallthrough warnings
Indicate when the fall through from the previous case label is intentional.
Fix format warnings related to arguments in printf calls.
2019-03-28 18:35:17 +01:00
Mark Wielaard
f04ae9f359 Use gcc -Wimplicit-fallthrough=2 by default if available
GCC 7 instroduced -Wimplicit-fallthrough
https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

It caught a couple of bugs, but it does need a bit of extra comments to
explain when a switch case statement fall-through is deliberate. Luckily
with -Wimplicit-fallthrough=2 various existing comments already do that.
I have fixed the bugs, but adding explicit break statements where
necessary and added comments where the fall-through was correct.

https://bugs.kde.org/show_bug.cgi?id=405430
2019-03-27 15:34:45 +01:00
Mark Wielaard
7f74ba249e Bug 405079 - unhandled ppc64le-linux syscall: 131 (quotactl)
quotactl is really a "generic" linux syscall that just happened to not
have been hooked up for ppc64le. Add it to syswrap-ppc64-linux.c.
2019-03-04 17:22:56 +01:00
Julian Seward
85545d9d25 Fix another format string signedness warning, arm64-linux only. n-i-bz. 2019-02-25 11:48:43 +01:00
Julian Seward
dee1c5ac84 Fix format string warnings from gcc9. No functional change (I think!) 2019-02-02 14:06:51 +01:00
Philippe Waroquiers
d7d8231750 Fix false positive 'Conditional jump or move' on amd64 64 bits ptracing 32 bits.
PTRACE_GET_THREAD_AREA is not handled by amd64 linux syswrap, which leads
to false positive errors in 64 bits program ptrace-ing 32 bits processes.

For example, the below error was wrongly reported on GDB:
==25377== Conditional jump or move depends on uninitialised value(s)
==25377==    at 0x8A1D7EC: td_thr_get_info (td_thr_get_info.c:35)
==25377==    by 0x526819: thread_from_lwp(thread_info*, ptid_t) (linux-thread-db.c:417)
==25377==    by 0x5281D4: thread_db_notice_clone(ptid_t, ptid_t) (linux-thread-db.c:442)
==25377==    by 0x51773B: linux_handle_extended_wait(lwp_info*, int) (linux-nat.c:2027)
....
==25377==  Uninitialised value was created by a stack allocation
==25377==    at 0x69A360: x86_linux_get_thread_area(int, void*, unsigned int*) (x86-linux-nat.c:278)

Fix this by implementing PTRACE_GET|SET_THREAD_AREA on amd64.
2019-01-12 15:35:59 +01:00
Mark Wielaard
2e2ae5bda8 Implement minimal ptrace support for ppc64[le]-linux. 2018-12-14 14:41:57 +01:00
Mark Wielaard
43fe4bc236 arm64: Fix PTRACE_TRACEME memcheck/tests/linux/getregset.vgtest testcase.
The sys_ptrace post didn't mark the thread as being in traceme mode.
This occassionally would make the memcheck/tests/linux/getregset.vgtest
testcase fail. With this patch it reliably passes.
2018-12-14 14:32:27 +01:00
Mark Wielaard
fdc275808c Hook up statx syscall for s390x-linux
Fixes memcheck/tests/linux/sys-statx.vgtest on s390x-linux.
2018-09-22 11:08:12 +02:00
Mark Wielaard
4692f675b2 Hook up linux membarrier syscall for s390x-linux
Fixes none/tests/linux/membarrier on s390x-linux.
2018-09-22 11:02:08 +02:00
Mark Wielaard
dee4914e6f Hook up linux membarrier syscall for x86-linux
Fixes none/tests/linux/membarrier on x86-linux.
2018-09-18 21:55:45 +02:00
Mark Wielaard
fbefb81c3c Hook up linux membarrier syscall for ppc64[le]
Fixes none/tests/linux/membarrier on ppc64[le] platforms.
2018-09-18 18:22:41 +02:00
Mark Wielaard
790f5f3018 Bug 397354 utimensat should ignore tv_sec if tv_nsec is UTIME_NOW/OMIT.
When code uses utimensat with UTIME_NOW or UTIME_OMIT valgrind memcheck
would generate a warning. But as the utimensat manpage says:

  If the tv_nsec field of one of the timespec structures has the  special
  value  UTIME_NOW,  then  the corresponding file timestamp is set to the
  current time.  If the tv_nsec field of one of the  timespec  structures
  has the special value UTIME_OMIT, then the corresponding file timestamp
  is left unchanged.  In both of these cases, the  value  of  the  corre‐
  sponding tv_sec field is ignored.

So ignore the timespec tv_sec when tv_nsec is set to UTIME_NOW or
UTIME_OMIT.
2018-09-03 11:54:38 +02:00
Petar Jovanovic
0375954c18 mips: fix unhandled mips64-linux syscall: 5326
This fixes memcheck/tests/linux/sys-statx on MIPS64.
2018-08-23 17:20:06 +02:00
Rhys Kidd
2b0aa0a5b8 macos: Fix missing syscall ulock_wait (OS X 10.12). bz#379754
Based upon patch available at:
https://bugs.kde.org/attachment.cgi?id=105482
2018-08-19 15:00:45 -04:00
Tom Hughes
488a5b8bb6 Improve bpf wrapper to check arguments more carefully 2018-08-14 20:47:19 +01:00
Quentin Monnet
0097176525 Add file descriptor tracking in wrappers for bpf system call
Support for the bpf system call was added in a previous commit, but
did not include tracking for file descriptors handled by the call.

Add checks and tracking for file descriptors. Check in PRE() wrapper
that all file descriptors (pointing to object such as eBPF programs or
maps, cgroups, or raw tracepoints) used by the system call are valid,
then add tracking in POST() wrapper for newly produced file descriptors.

As the file descriptors are not always processed in the same way by the
bpf call, add to the header file some additional definitions from bpf.h
that are necessary to sort out under what conditions descriptors should
be checked in the PRE() helper.
2018-08-14 20:47:19 +01:00
Quentin Monnet
1d933b5a4a Add support for bpf system call
Fixes: 388786 - Support bpf syscall in amd64 Linux

Add support for bpf() Linux-specific system call on amd64 platform. The
bpf() syscall is used to handle eBPF objects (programs and maps), and
can be used for a number of operations. It takes three arguments:

- "cmd" is an integer encoding a subcommand to run. Available subcommand
  include loading a new program, creating a map or updating its entries,
  retrieving information about an eBPF object, and may others.
- "attr" is a pointer to an object of type union bpf_attr. This object
  converts to a struct related to selected subcommand, and embeds the
  various parameters used with this subcommand. Some of those parameters
  are read by the kernel (example for an eBPF map lookup: the key of the
  entry to lookup), others are written into (the value retrieved from
  the map lookup).
- "attr_size" is the size of the object pointed by "attr".

Since the action performed by the kernel, and the way "attr" attributes
are processed depends on the subcommand in use, the PRE() and POST()
wrappers need to make the distinction as well. For each subcommand, mark
the attributes that are read or written.

For some map operations, the only way to infer the size of the memory
areas used for read or write operations seems to involve reading
from /proc/<pid>/fdinfo/<fd> in order to retrieve the size of keys
and values for this map.

The definitions of union bpf_attr and of other eBPF-related elements
required for adequately performing the checks were added to the Linux
header file.

Processing related to file descriptors is added in a follow-up patch.
2018-08-14 20:47:19 +01:00
Quentin Monnet
c9d555dafa Move pre_check for ASCII string out of PRE(sys_prctl)
The sys_prctl wrapper with PR_SET_NAME option reads an ASCII string passed
as its second argument. This string is supposed to be shorter than a given
limit. As the actual length of the string is unknown, the PRE() wrapper
performs a number of checks on it, including, in worst case, trying to
dereference it byte by byte.

To avoid re-implementing all this logic for other wrappers that could
need it, get the string processing out of the wrapper and move it to a
static function. Note that passing tid as an argument to the function is
required for macros PRE_MEM_RASCIIZ and PRE_MEM_READ to work properly.
2018-08-14 20:47:19 +01:00
Philippe Waroquiers
8bc2b6fd26 Fix 392118 - unhandled amd64-linux syscall: 332 (statx)
Code patch provided by Mattias Andrée

Added a regression test to (somewhat) test stat and statx.

Tested on amd64 only.
2018-08-11 15:56:56 +02:00
Petar Jovanovic
f9606bc01c mips: add membarrier system call support
Fixes none/tests/linux/membarrier on MIPS platforms.
2018-08-07 14:09:43 +02:00
Mark Wielaard
2eb2df759f Bug 397012 - glibc ld.so uses arch_prctl on i386.
arch_prctl used to be amd64 only. But since linux 4.12 it is also
implemented for i386. And since glibc 2.28 ld.so will use it to see
if the cpu/kernel provides CET support.

To prevent seeing:

WARNING: unhandled x86-linux syscall: 384
You may be able to write your own handler.
Read the file README_MISSING_SYSCALL_OR_IOCTL.
Nevertheless we consider this a bug.  Please report
it at http://valgrind.org/support/bug_reports.html.

on every program run under valgrind just make it explicitly
not implemented (ENOSYS). This is fine for the glibc usage.
It just indicates there is no CET support.
2018-08-06 14:58:01 +02:00
Mark Wielaard
21a01b13e2 Bug 396887 - arch_prctl should return EINVAL on unknown option.
Currently arch_prctl calls VG_(core_panic) when it sees an unknown
arch_prctl option which kills the process. glibc uses arch_prctl with
an (as yet) unknown option to see if the kernel supports CET. This
breaks any application running under valgrind on x86_64 with:

valgrind: the 'impossible' happened:
   Unsupported arch_prctl option

Thread 1: status = VgTs_Runnable (lwpid 19934)
==19934==    at 0x121A15: get_cet_status (cpu-features.c:28)
==19934==    by 0x121A15: init_cpu_features (cpu-features.c:474)
==19934==    by 0x121A15: dl_platform_init (dl-machine.h:228)
==19934==    by 0x121A15: _dl_sysdep_start (dl-sysdep.c:231)
==19934==    by 0x10A1D7: _dl_start_final (rtld.c:413)
==19934==    by 0x10A1D7: _dl_start (rtld.c:520)

We already handle all known options. It would be better to do as the
kernel does and just return failure with EINVAL instead.
2018-07-30 12:20:16 +02:00
Philippe Waroquiers
7daa086114 Give some more information in the scheduler information thread status
* In case a thread is executing a syscall, give the syscall no being
  executed.
* Show the address range of the valgrind stack, similarly to the client
  stack
2018-07-28 00:36:35 +02:00
Mark Wielaard
6fbd9bf771 Implement ptrace syscall wrapper for arm64-linux.
With this valgrind is able to run gdb on arm64.
Also fixes the memcheck/tests/linux/getregset testcase.

https://bugs.kde.org/show_bug.cgi?id=368913
2018-06-21 08:17:41 +02:00
Bart Van Assche
959a54cb3a Add support for the Linux membarrier() system call
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
2018-06-15 08:25:28 -07:00
Petar Jovanovic
9a6cf7a41c mips64: add N32 ABI support
Adding MIPS N32 ABI support.

BZ issue - #345763.

Contributed and maintained by mulitple people over the years:
  Crestez Dan Leonard, Maran Pakkirisamy, Dimitrije Nikolic,
  Aleksandar Rikalo, Tamara Vlahovic.
2018-06-14 17:40:08 +00:00
Petar Jovanovic
8b2fe98aca additional use of RegWord
Follow up to "Introduce RegWord type" change.

Part of the changes required for BZ issue - #345763.

Contributed by:
  Tamara Vlahovic and Dimitrije Nikolic.
2018-06-14 17:40:08 +00:00
Rhys Kidd
92d6a53886 Fix missing kevent_qos syscall (macOS 10.11). bz#383723
Based upon patch from Alexandru Croitor.
2018-06-03 12:53:18 -04:00
Philippe Waroquiers
06cb991bcd Unbreak build on macos,
(problem introduced by 54145019b045fffde625447b64f3a91f663de718)
2018-04-14 21:30:25 +02:00
Petar Jovanovic
fc6c463d57 Introduce RegWord type
On majority of architectures size of long matches register width.
On mips n32 size of long is 32 bits and register width is 64 bits.
Valgrind is written with assumption that long size matches register
width. This is the reason why both UWord for Valgrind and HWord for VEX
match size of long. Long size differs from register size on mips n32 ABI.

Introducing RegWord type that will match size of registers.

Part of the changes required for BZ issue - #345763.

Contributed by:
  Tamara Vlahovic and Dimitrije Nikolic.
2018-04-10 14:09:08 +02:00
Philippe Waroquiers
54145019b0 n-i-bz Fix possible stack trashing by semctl syscall wrapping
The modified test none/tests/sem crashes with a SEGV when valgrind is compiled
with lto on various amd64 platforms (debian/gcc 6.3, RHEL7/gcc 6.4,
Ubuntu/gcc 7.2)

The problem is that the vki_semid_ds buf is not what is expected by the kernel:
the kernel expects a bigger structure vki_semid64_ds (at least on
these platforms).
Getting the sem_nsems seems to work by chance, as sem_nsems is at
the same offset in both vki_semid_ds and vki_semid64_ds.
However, e.g. the ctime was not set properly after syscall return,
and 2 words after sem_nsems were set to 0 by the kernel, causing
the SEGV, as a spilled register became 0.

Fix consists in using the 64 bit version for __NR_semctl.
Tested on debian/amd64 and s390x.
2018-04-01 14:31:40 +02:00
Bart Van Assche
a05d86e562 Linux: Add support for the zoned block device ioctls
Shingled magnetic recording drives support a command set called ZBC
(Zoned Block Commands). Two new ioctls have been added to the Linux
kernel to support such drives, namely VKI_BLKREPORTZONE and
VKI_BLKRESETZONE. Add support to Valgrind for these ioctls.
2018-03-12 10:46:15 -07:00
Bart Van Assche
ccd1e177ee Linux: Add support for the BLKFLSBUF ioctl 2018-03-12 10:46:01 -07:00
Rhys Kidd
dcb83cf846 macos: Fix unhandled syscall: mach:43 (mach_generate_activity_id). bz#385279
Based upon a patch provided by Louis Brunner <louis.brunner.fr@gmail.com> and
tested by:
  FX           <fxcoudert@gcc.gnu.org>
  Chris Wilson <chris+kde@qwirx.com>
2018-02-11 19:56:58 -05:00
Petar Jovanovic
fd120874fb mips: add support for mips32/mips64 R6 to coregrind
Changes in PRE(sys_prctl), necessary to support new floating-point modes
in MIPS R6.

Part of MIPS32/64 Revision 6 changes.

Contributed by:
  Tamara Vlahovic, Aleksandar Rikalo and Aleksandra Karadzic.

Related BZ issue - #387410.
2018-02-01 18:28:18 +01:00
Ivo Raisr
f19a956e0a Enable -Wlogical-op for Valgrind; fix an obvious typo.
Fixes BZ#389065.
Reported by: dcb314@hotmail.com
2018-01-23 10:43:19 +01:00
Rhys Kidd
1ce04c35c2 Preliminary support for Darwin 17.x (macOS 10.13) 2017-10-01 19:45:10 -04:00
Rhys Kidd
ed6ad13bc8 Fix missing workq_ops operations (macOS)
Related to discussion in bz#383723. Patch based upon one provided by
Andy Maloney.
2017-10-01 19:05:48 -04:00
Rhys Kidd
128fd6e6a5 Fix syscall param msg->desc.port.name on macOS 10.12. bz#379373
Based upon patch from Louis Brunner.
2017-09-10 10:50:06 -04:00
Rhys Kidd
55fe390c7a Fix missing pselect syscall (OS X 10.11). bz#379748
Based upon patch from Louis Brunner.
2017-09-03 12:55:52 -04:00
Mark Wielaard
3ac87cf927 epoll_pwait can have a NULL sigmask.
According to the epoll_pwait(2) man page:

       The  sigmask  argument  may  be  specified  as  NULL,  in  which  case
       epoll_pwait() is equivalent to epoll_wait().

But doing that under valgrind gives:

==13887== Syscall param epoll_pwait(sigmask) points to unaddressable byte(s)
==13887==    at 0x4F2B940: epoll_pwait (epoll_pwait.c:43)
==13887==    by 0x400ADE: main (syscalls-2007.c:89)
==13887==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

This is because the sys_epoll_pwait wrapper has:

   if (ARG4)
      PRE_MEM_READ( "epoll_pwait(sigmask)", ARG5, sizeof(vki_sigset_t) );

Which looks like a typo (ARG4 is timeout and ARG5 is sigmask).

This shows up with newer glibc which translates an epoll_wait call into
an epoll_pwait call with NULL sigmask.

Fix typo and add a testcase.

https://bugs.kde.org/show_bug.cgi?id=381289

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16451
2017-06-17 13:49:22 +00:00
Ivo Raisr
2cc0e531ec Port changes from r16407 to Solaris OS.
n-i-bz


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16411
2017-05-23 21:37:50 +00:00
Julian Seward
7f2c63135b Make the message "brk segment overflow in thread #%u: can't grow to %#lx"
be printed only once, rather than every time it happens.  Also make it
not be printed in silent mode (-q).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16407
2017-05-22 08:50:07 +00:00
Julian Seward
20b6c5f506 Bug 379966 - WARNING: unhandled amd64-linux syscall: 313 (finit_module).
Patch from Bartosz Golaszewski (bartekgola@gmail.com).


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16403
2017-05-22 07:53:04 +00:00
Ivo Raisr
70e9a82f07 POST syscall wrapper for clock_gettime was not properly hooked up on Solaris.
This resulted in false positive undefined warnings.
Fixes BZ#379895.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16392
2017-05-17 04:36:06 +00:00
Ivo Raisr
754487de4f Add Linux specific ioctl wrapper for CDROMREADMODE1
Fixes BZ#360429
Original patch by: Vasantha Ganesh K <vasanthaganesh.k@tuta.io>


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16358
2017-05-10 23:14:31 +00:00