76 Commits

Author SHA1 Message Date
Earl Chew
d387566dd7 Support Linux syscall 434 pidfd_open 2023-04-14 23:06:48 +02:00
Lubomir Rintel
a21e890f82 Add close_range(2) support
This is a system call introduced in Linux 5.9.

It's typically used to bulk-close file descriptors that a process inherited
without having desired so and doesn't want to pass them to its offspring
for security reasons. For this reason the sensible upper limit value tends
to be unknown and the users prefer to stay on the safe side by setting it
high.

This is a bit peculiar because, if unfiltered, the syscall could end up
closing descriptors Valgrind uses for its purposes, ending in no end of
mayhem and suffering.

This patch adjusts the upper bounds to a safe value and then skips over
the descriptor Valgrind uses by potentially calling the real system call
with sub-ranges that are safe to close.

The call can fail on negative ranges and bad flags -- we're dealing with
the first condition ourselves while letting the real call fail on bad
flags.

https://bugs.kde.org/show_bug.cgi?id=439090
2021-10-12 22:58:45 +02:00
Mark Wielaard
9aa51a6e25 Hook up acct syscall for amd64, mips32, ppc32 and ppc64
There was already a generic linux wrapper for acct, but it was not
hooked up for all linux arches.
2021-10-04 11:34:08 +02:00
Mark Wielaard
52ed51fc35 Generate a ENOSYS (sys_ni_syscall) for clone3 on all linux arches
glibc 2.34 will try to use clone3 first before falling back to
the clone syscall. So implement clone3 as sys_ni_syscall which
simply return ENOSYS without producing a warning.

https://bugs.kde.org/show_bug.cgi?id=439590
2021-07-21 19:53:21 +02:00
Mark Wielaard
b918f71020 PR423361 Adds io_uring support on arm64/aarch64 (and all other arches)
io_uring syscalls only work on x86/amd64, but they can be enabled on
all arches. Based on a patch by Nathan Ringo <nathan@remexre.xyz>.

https://bugs.kde.org/show_bug.cgi?id=423361
2021-02-04 17:21:56 +01:00
Mark Wielaard
fe4b349df3 Support new faccessat2 linux syscall (439)
faccessat2 is a new syscall in linux 5.8 and will be used by glibc 2.33.
faccessat2 is simply faccessat with a new flag argument. It has
a common number across all linux arches.

https://bugs.kde.org/427787
2020-10-16 02:55:06 +02:00
Mark Wielaard
6323fd5bfd Handle linux syscalls sched_getattr and sched_setattr
The only "special" thing about these syscalls is that the given
struct sched_attr determines its own size for future expansion.

Original fix by "ISHIKAWA,chiaki" <ishikawa@yk.rim.or.jp>

https://bugs.kde.org/show_bug.cgi?id=369029
2020-08-01 15:34:48 +02:00
Mark Wielaard
0a69a8f5bd Add execveat for arm[64], [nano]mips[32|64], ppc[32|64], s390x and x86.
https://bugs.kde.org/show_bug.cgi?id=345077
2020-06-09 09:03:02 +02:00
Petar Jovanovic
4a889e881b mips: remove rt-rk email that is no longer in use
Email mips-valgrind@rt-rk.com is no longer in use.
2020-05-20 13:18:55 +00:00
Michal Privoznik
60a7ebedc0 Add support for setns syscall
I've tested this on amd64 and arm but I'm enabling it on all
arches since the syscall should work identically on all of them.

This was requested by users for a long time (almost 5 years) and
in fact, some programs (like libvirt) use namespaces and fork off
to enter other namespaces. Lack of implementation means valgrind
can't be used with these programs (or their configuration must be
changed to not use namespaces, which defeats the purpose).

Without knowing it, I've converged to same patch as mentioned in
bugs below.

https://bugs.kde.org/show_bug.cgi?id=343099
https://bugs.kde.org/show_bug.cgi?id=368923
https://bugs.kde.org/show_bug.cgi?id=369031

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2020-04-28 17:36:20 +02:00
Mark Wielaard
3d6a8157d5 Add 32bit time64 syscalls for arm, mips32, ppc32 and x86.
This patch adds sycall wrappers for the following syscalls which
use a 64bit time_t on 32bit arches: gettime64, settime64,
clock_getres_time64, clock_nanosleep_time64, timer_gettime64,
timer_settime64, timerfd_gettime64, timerfd_settime64,
utimensat_time64, pselect6_time64, ppoll_time64, recvmmsg_time64,
mq_timedsend_time64, mq_timedreceive_time64, semtimedop_time64,
rt_sigtimedwait_time64, futex_time64 and sched_rr_get_interval_time64.

Still missing are clock_adjtime64 and io_pgetevents_time64.

For the more complicated syscalls futex[_time64], pselect6[_time64]
and ppoll[_time64] there are shared pre and/or post helper functions.
Other functions just have their own PRE and POST handler.

Note that the vki_timespec64 struct really is the struct as used by
by glibc (it internally translates a 32bit timespec struct to a 64bit
timespec64 struct before passing it to any of the time64 syscalls).
The kernel uses a 64-bit signed int, but is ignoring the upper 32 bits
of the tv_nsec field. It does always write the full struct though.
So avoid checking the padding is only needed for PRE_MEM_READ.
There are two helper pre_read_timespec64 and pre_read_itimerspec64
to check the new structs.

https://bugs.kde.org/show_bug.cgi?id=416753
2020-03-04 14:46:59 +01:00
Petar Jovanovic
64a63a07c9 mips32: hook up adjtimex syscall
Hook up adjtimex syscall for mips32.

This fixes adjtimex01 failure in the LTP test suite.
2019-11-26 13:25:19 +00:00
Petar Jovanovic
762e60391f mips32: hook up getcpu syscall
Hook up getcpu syscall for mips32.

This fixes getcpu01 failure in the LTP test suite.
2019-11-26 13:19:45 +00:00
Petar Jovanovic
f5a6ad6e78 mips32: hook up waitid syscall
Hook up waitid syscall for mips32.

This fixes waitid01 failure in the LTP test suite.
2019-11-26 13:10:47 +00:00
Petar Jovanovic
cb366f2680 mips32: hook up vmsplice syscall
Hook up vmsplice syscall for mips32.

This fixes vmsplice01 failure in the LTP test suite.
2019-08-21 12:47:11 +00:00
Petar Jovanovic
23a950be4b mips32: hook up vhangup syscall
Hook up vhangup syscall for mips32.

This fixes vhangup01 in the LTP test suite.
2019-08-20 13:30:45 +00:00
Petar Jovanovic
b086d63a73 mips32: hook up utimes syscall
Hook up utimes syscall for mips32.

This fixes utimes01 in the LTP test suite.
2019-08-20 13:17:02 +00:00
Petar Jovanovic
fd640dacde mips32: hook up unshare syscall
Hook up unshare syscall for mips32.

This fixes unshare02 in the LTP test suite.
2019-08-20 12:41:59 +00:00
Petar Jovanovic
8055312c42 mips32: hook up truncate64 syscall
Hook up truncate64 syscall for mips32.

This helps truncate02_64 and several other tests pass without warnings in
the LTP test suite.
2019-08-20 12:29:57 +00:00
Petar Jovanovic
4571112b50 mips32: hook up getitimer syscall
Hook up getitimer syscall for mips32.

This fixes getitimer01 and several other tests in the LTP test suite.
2019-08-19 17:37:17 +00:00
Petar Jovanovic
7cac90f6ba mips32: hook up sethostname syscall
Hook up sethostname syscall for mips32.

This fixes sethostname01 and several other tests in the LTP test suite.
2019-08-19 17:23:58 +00:00
Petar Jovanovic
803bf32f4c mips32: hook up sched_rr_get_interval syscall
Hook up sched_rr_get_interval syscall for mips32.

This fixes sched_rr_get_interval01 and several other tests in the LTP test
suite.
2019-08-14 15:43:10 +00:00
Petar Jovanovic
a03ca6eef8 mips32: hook up sched_setparam syscall
Hook up sched_setparam syscall for mips32.

This fixes sched_setparam01 and several other tests in the LTP test suite.
2019-08-14 15:36:07 +00:00
Petar Jovanovic
04614dae3b mips: hook up tee syscall correctly
Hook up sys_tee for mips32 and mips64 correctly.
For mips64, it is just a simplification to use generic linux implementation.

This fixes tee01 test in the LTP test suite for mips32.
2019-08-14 15:27:25 +00:00
Petar Jovanovic
f605da3ef5 mips32: add sync_file_range syscall support
Hook up sync_file_range for mips32.

Along with the change for passing 7th argument in syscalls, this will fix
sync_file_range01 failure within LTP test suite.

Patch by Nikola Milutinovic.
2019-08-13 14:30:30 +00:00
Petar Jovanovic
d830990cd9 mips: hook up splice syscall correctly
Hook up splice syscall for mips32 and mips64 correctly.
This fixes splice01 and several other tests in the LTP test suite.
2019-08-13 12:20:38 +00:00
Petar Jovanovic
60b477684c mips32: hook up lsetxattr syscall
Hook up lsetxattr syscall for mips32.
This fixes llistxattr01 and several other tests in the LTP test suite.
2019-08-13 12:20:38 +00:00
Petar Jovanovic
36e793843e mips32: hook up fsetxattr syscall
Hook up fsetxattr syscall for mips32.
This fixes fgetxattr03 and several other tests in the LTP test suite.
2019-08-02 16:56:25 +00:00
Petar Jovanovic
4f81a5fcbf mips32: enable support for setxattr
Enable support for setxattr syscall for mips32.
2019-07-23 13:24:16 +00:00
Petar Jovanovic
bd2a81f202 mips: hook up preadv, preadv2, pwritev and pwritev2 correctly
Use the correct generic linux sys wrapper.

Follow-up for

  commit b0861063a8d2a55bb7423e90d26806bab0f78a12
  Author: Alexandra Hajkova <ahajkova@redhat.com>
  Date:   Tue Jun 4 13:47:14 2019 +0200

    Add support for preadv2 and pwritev2 syscalls

This should fix
memcheck/tests/linux/sys-preadv2_pwritev2 (stderr)
memcheck/tests/linux/sys-preadv_pwritev  (stderr)

on mips32/mips64.
2019-07-22 19:56:33 +02:00
Mark Wielaard
461cc5c003 Cleanup GPL header address notices by using http://www.gnu.org/licenses/
Sync VEX/LICENSE.GPL with top-level COPYING file. We used 3 different
addresses for writing to the FSF to receive a copy of the GPL. Replace
all different variants with an URL <http://www.gnu.org/licenses/>.

The following files might still have some slightly different (L)GPL
copyright notice because they were derived from other programs:

- files under coregrind/m_demangle which come from libiberty:
  cplus-dem.c, d-demangle.c, demangle.h, rust-demangle.c,
  safe-ctype.c and safe-ctype.h
- coregrind/m_demangle/dyn-string.[hc] derived from GCC.
- coregrind/m_demangle/ansidecl.h derived from glibc.
- VEX files for FMA detived from glibc:
  host_generic_maddf.h and host_generic_maddf.c
- files under coregrin/m_debuginfo derived from LZO:
  lzoconf.h, lzodefs.h, minilzo-inl.c and minilzo.h
- files under coregrind/m_gdbserver detived from GDB:
  gdb/signals.h, inferiors.c, regcache.c, regcache.h,
  regdef.h, remote-utils.c, server.c, server.h, signals.c,
  target.c, target.h and utils.c

Plus the following test files:

- none/tests/ppc32/testVMX.c derived from testVMX.
- ppc tests derived from QEMU: jm-insns.c, ppc64_helpers.h
  and test_isa_3_0.c
- tests derived from bzip2 (with embedded GPL text in code):
  hackedbz2.c, origin5-bz2.c, varinfo6.c
- tests detived from glibc: str_tester.c, pth_atfork1.c
- test detived from GCC libgomp: tc17_sembar.c
- performance tests derived from bzip2 or tinycc (with embedded GPL
  text in code): bz2.c, test_input_for_tinycc.c and tinycc.c
2019-05-26 20:07:51 +02:00
Petar Jovanovic
bf33835707 mips: hook linux copy_file_range syscall
Allow copy_file_range syscalls on MIPS32 and MIPS64.
Update .gitignore.

Related Bugzilla issue - KDE #407218.
2019-05-10 16:35:02 +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
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
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
Petar Jovanovic
4f3cd8ff8f mips: reduce compiler warnings
Compiler complained about

warning: implicit declaration of function ‘vgPlain_prctl’

in coregrind/m_machine.c.

Also, it complained about

warning: no previous prototype for ‘vgSysWrap_mips_linux_sys_ptrace_before’
[-Wmissing-prototypes]
warning: no previous prototype for ‘vgSysWrap_mips_linux_sys_ptrace_after’
[-Wmissing-prototypes]

in coregrind/m_syswrap/syswrap-mips32-linux.c

This change fixes those issues.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16345
2017-05-09 15:57:59 +00:00
Ivo Raisr
38edd50c0e Update copyright end year to 2017 in preparation for 3.13 release.
n-i-bz



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16333
2017-05-04 15:09:39 +00:00
Petar Jovanovic
30717ab5a2 Add support for syscall ptrace(traceme)
It fixes Bug 377376.

Patch by Aleksandra Karadzic.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16273
2017-03-15 15:23:27 +00:00
Petar Jovanovic
795ee051e6 mips32: add support for ptrace syscall
Add wrapers for ptrace syscall for mips32.

Patch by Aleksandra Karadzic.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16211
2017-01-27 17:01:49 +00:00
Philippe Waroquiers
489cfd5156 Fix 342040 Valgrind mishandles clone with CLONE_VFORK | CLONE_VM that clones to a different stack
Fix 373192 Calling posix_spawn in glibc 2.24 completely broken

Functionally, this patch just does the following 2 changes to the
fork clone handling:
* It does not mask anymore CLONE_VFORK :
  The only effect of this flag is to suspend the parent, waiting for
  the child to either exit or execve.
  If some applications depends on this synchronisation, better keep it,
  as it will not harm to suspend the parent valgrind waiting for the
  child valgrind to exit or execve.
* In case the guest calls the clone syscall providing a non zero client stack,
  set the child guest SP after the syscall, before executing guest instructions.
  Not setting the guest stack ptr was the source of the problem reported
  in the bugs.

This also adds a test case  none/tests/linux/clonev.
Before this patch, test gives a SEGV, which is fixed by the patch.

The patch is however a lot bigger : this fix was touching some (mostly
identical/duplicated) code in all the linux platforms.
So, the clone/fork code has been factorised as much as possible.
This removes about 1700 lines of code.

This has been tested on:
* amd64
* x86
* ppc64 be and le
* ppc32
* arm64

This has been compiled on but *not really tested* on:
* mips64 (not too clear how to properly build and run valgrind on gcc22)

It has *not* been compiled and *not* tested on:
* arm
* mips32
* tilegx
* darwin   (normally, no impact)
* solaris  (normally, no impact)

The changes are relatively mechanical, so it is not impossible that
it will compile and work out of the box on these platforms.
Otherwise, questions welcome.

A few points of interest:
* Some platforms did have a typedef void vki_modify_ldt_t,
  and some platforms had no definition for this type at all.
  To make it easier to factorise, for such platforms, the following has
  been used:
     typedef char vki_modify_ldt_t;
    When the sizeof vki_modify_ldt_t is > 1, then the arg syscall is checked.
  This is somewhat a hack, but was simplifying the factorisation.

* for mips32/mips64 and tilegx, there is a strange unconditional assignment
  of 0 to a register (guest_r2 on mips, guest_r0 on tilegx).
  Unclear what this is, in particular because this is assigned whatever
  the result of the syscall (success or not).
  



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16186
2016-12-11 21:39:23 +00:00
Petar Jovanovic
7746f34db7 mips: fix call_on_new_stack_0_1 code
MIPS32 implementation missed to set up a correct (zero) return address.
This led to incorrect execution of get_StackTrace_wrk as it was not
able to unwind stack correctly.
This change fixes memcheck/tests/leak-autofreepool-5.

MIPS64 implementation missed clearing all integer registers before
entering the function.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16166
2016-12-01 16:01:45 +00:00
Petar Jovanovic
9a6096841e mips32: fix fadvise64 system call
For fadvise64 system call, 7th 32-bit argument slot (third on the stack)
will also be used due to MIPS O32 calling convention in passing 64-bit
values.

sys_fadvise64(int fd, loff_t offset, loff_t len, int advice);

NR_fadvise64 -> v0               (sysno)
fd           -> a0               (ARG1)
offset       -> a2, a3           (ARG3, ARG4)
len          -> SP + 16, SP + 20 (ARG5, ARG6)
advise       -> SP + 24          (ARG7)

Change the code according to it.

Patch by Aleksandar Rikalo.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16162
2016-11-29 14:27:25 +00:00
Petar Jovanovic
5fba00cd1f mips: add POST function to sys_prctl
Add missing POST wrapper for sys_prctl.
This fixes regressions from r15934 (on MIPS32 platforms) and r16003
(on MIPS64 platforms).

Related test: memcheck/tests/threadname


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16110
2016-11-01 18:28:26 +00:00
Petar Jovanovic
6e45ce45ac mips32: add pselect6 to the list of supported syscalls
Add pselect6 to the list of supported syscalls on MIPS32.
It fixes:

none/tests/pselect_alarm                 (stderr)
none/tests/pselect_sigmask_null          (stderr)

on mips32 platforms.

Patch by Aleksandra Karadzic.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16031
2016-10-07 17:04:33 +00:00
Petar Jovanovic
296bd45ae0 mips32: fix the wrong offset for mmap2()
The offset for mmap2 is specified in 4096-byte units, not page size
units.

Patch by Duncan Palmer <dpalmer@digisoft.tv>.

It fixes BZ#352197.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16026
2016-10-06 17:46:14 +00:00
Petar Jovanovic
030cea68c8 mips32: add support for FPXX mode
With this patch, MIPS32 Valgrind compiled with -mfpxx can handle all types
(regarding FP_ABI flag) of MIPS32 ELFs.

- Functions arch_elf_pt_proc() and arch_check_elf() are added to elf reader
  according to linux/fs/binfmt_elf.c from Linux 4.1;
- Processing .MIPS.abiflags section and initializing appropriate FPU mode
  for MIPS32 are added;
- Emulation of prctl(GET/SET_FP_MODE) sys-calls are implemented for MIPS32.

Patch by Aleksandar Rikalo <Aleksandar.Rikalo@imgtec.com>

Related VEX change: r3243.

This implements BZ#366079.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15934
2016-08-10 14:38:10 +00:00
Julian Seward
adc2dafee9 Update copyright dates, to include 2015. No functional change.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15577
2015-08-21 11:32:26 +00:00
Florian Krohm
9a3883bf3d Fix printf format inconsistencies as pointed out by gcc -Wformat-signedness.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15510
2015-08-08 21:45:33 +00:00
Florian Krohm
7a474c9455 Fix typos in source code. Patch by Dmitriy (olshevskiy87@bk.ru).
Fixes BZ #349874


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15394
2015-07-05 21:53:33 +00:00