1441 Commits

Author SHA1 Message Date
Mark Wielaard
19a34d1d93 Disable linux madvise MADV_GUARD_INSTALL
glibc 2.42+ (with linux 6.13+) uses MADV_GUARD_INSTALL to setup stack
guard pages. valgrind currently isn't able to track this and such
guard pages also don't show up in /proc maps (only in /proc pagemap
since linux 6.14). For now valgrind fails a madvise MADV_GUARD_INSTALL
syscall with EINVAL. This causes glibc to fall back to mprotect
PROT_NONE which valgrind is able to track.

https://bugs.kde.org/show_bug.cgi?id=511717
2026-01-07 22:20:49 +01:00
Paul Floyd
21e5da76b5 valgrind.h: FreeBSD cleanup
Wasn't undefining the PLAT macros
Add FreeBSD to the head and tail comments for each arch

amd64 is getting crowded, if we add any more OSes then I think
just "amd64 platforms" will be enough rather than listing 5 or 6
or more platforms.
2026-01-06 20:33:16 +01:00
Paul Floyd
bd417daf8b Bug 513636 - Support macOS 12.0 (Monterey)
Intel only for the moment.
2025-12-24 17:36:11 +01:00
Paul Floyd
eab939e9c9 Bug 513533 - Support macOS 11.0 (Big Sur)
Most of the work for this was done by Louis Brunner.
Thanks Louis.
2025-12-20 15:47:50 +01:00
Paul Floyd
d3cd66160c Darwin: add macOS 10.15 support
== 721 tests, 46 stderr failures, 6 stdout failures, 0 stderrB failures, 0 stdoutB failures, 4 post failures ==

A couple more failures in none (empty-exe and scripts/shell). Otherwise quite like
macOS 10.14.

Much of the code merged from Louis Brunner's git repo. Many thanks once again
Louis.
2025-12-17 19:42:34 +01:00
Martin Cermak
ce7a2995b3 Wrap new lsm_list_modules syscall
The lsm_list_modules syscall returns a list of the active LSM ids. On
success this function returns the number of @ids array elements. This
value may be zero if there are no LSMs active. If @size is insufficient
to contain the return data -E2BIG is returned and @size is set to the
minimum required size. In all other cases a negative value indicating
the error is returned.

SYSCALL_DEFINE3(lsm_list_modules, u64 __user *, ids, u32 __user *, size,
                u32, flags)

Declare lsm_list_modules wrappers in priv_syswrap-linux.h and hook it
for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x,x86}-linux.

https://bugs.kde.org/show_bug.cgi?id=513257
2025-12-16 09:52:29 +01:00
Paul Floyd
2802b31ae6 Darwin helgrind: redirs for semaphore functions
The semaphore functions are not in the pthread library (similar to FreeBSD).
Change the redirs to use libsystem_kernel.dylib

Unfortunately this doesn't help much. Darwin has deprecated these functions
so the tests will compile (with a warning) but at runtime they all fail
with errors like ENOSYS and EBADF.
2025-12-14 18:21:19 +01:00
Paul Floyd
6878e3f78f Darwin fdleaks: fix handling of recvmsg cmsg
In the Darwin headers the macro __DARWIN_ALIGN32 is used for
the CMSG macros. We were using just ALIGN which looks like
it uses __DARWIN_ALIGN for 8 byte alignment. Using the
wrong alignment gate a wrong count of fds and check_cmsg_for_fds
was only calling ML_(record_fd_open_named) for one fd. The result
was fd errors when writing to a second fd that should have been
recorded.
2025-12-14 13:31:18 +01:00
Paul Floyd
eca0ea6e9a Darwin: add most of the missing bits for Darwin 18 support
Code merged from Louis Brunner. Also add a but of doc about the
oldest OSX that we support. Unfortunately I don't know which version
that is.
2025-12-09 08:58:46 +01:00
Martin Cermak
4ad2f953c4 Wrap new lsm_get_self_attr and lsm_set_self_attr syscalls
Create a system call lsm_get_self_attr() to provide the security
module maintained attributes of the current process.
Create a system call lsm_set_self_attr() to set a security
module maintained attribute of the current process.
Historically these attributes have been exposed to user space via
entries in procfs under /proc/self/attr.

Declare lsm_get_self_attr and lsm_set_self_attr wrappers in
priv_syswrap-linux.h and hook it for {amd64,arm,arm64,mips64,\
ppc32,ppc64,riscv64,s390x,x86}-linux.

https://bugs.kde.org/show_bug.cgi?id=510563
2025-12-08 13:20:25 +01:00
Paul Floyd
48354b2083 FreeBSD and Darwin: clean up fake sigreturn syscall numbers
Firstly make them a bit more similar. Secondly, switch Darwin
from using __NR_MAXSYSCALL which changes with every Darwin version
to using 1000 like FreeBSD.

Change NEWS for macOS 10.13, it has now progressed beyond
'preliminary'.
2025-12-07 22:07:19 +01:00
Paul Floyd
965d8e484b Darwin syscall: initial wrapper for kernelrpc_mach_vm_purgable_control_trap
Need to add verification of regs and read/write mem.
2025-12-07 11:48:51 +01:00
Paul Floyd
f916877a38 Darwin syscall: initial wrapper for mach_voucher_extract_attr_recipe
It doesn't do any checking yet. However, with this change running
TextEditor with --tool=none gets as far as drawing a white box on
the screen. Then it fails because there is a missing mach trap handler
for

/* 11 */ MACH_TRAP(_kernelrpc_mach_vm_purgable_control_trap, 4, 5, munge_wlww),
2025-12-07 09:52:04 +01:00
Martin Cermak
37d9e2085e Add ARG4 checks for quotactl and quotactl_fd syswraps
ARG4 can point to different things of varion sizes based on the
cmd arg.  Handle all the possible options and provide missing
checks.

https://bugs.kde.org/show_bug.cgi?id=509634
2025-12-04 14:00:59 +01:00
Paul Floyd
175d836a83 Darwin: update syscalls
Code merged from Louis Brunner, mainly up to OSX 10.13
2025-11-30 17:28:36 +01:00
Paul Floyd
5d68d627f1 Darwin: update signal tramp, helgrind and drd suppressions
Change a couple of testcase asserts to match Darwin quirks.
Signal tramp from Louis Brunner
2025-11-28 22:49:25 +01:00
Paul Floyd
d4d17178ab Darwin Helgrind/DRD: change pthread lib, more filters and suppressions
And turn off one test that is hanging. More to come.
2025-11-28 07:44:51 +01:00
Paul Floyd
bf7c22738b Darwin: many fixes for OSX 10.13
Most of these changes are from Louis Brunner's GitHub repo.
The most imortant changes are to the memory space and to the code
related to getting the host filename during startup. This means
that when Valgrind crashes or hits an assert we now get a legible
host stacktrrace.

This also fixes none/tests/darwin/bug228343
2025-11-27 13:26:57 +01:00
Martin Cermak
3275a177f9 Provide missing syswraps for file_getattr and file_setattr
The syscalls take fd and path. If path is absolute, fd is not
used. If path is empty, fd can be AT_FDCWD or any valid fd which
will be used to get/set attributes on.

https://bugs.kde.org/show_bug.cgi?id=510169
2025-11-27 09:25:07 +01:00
Martin Cermak
2b4b31de69 Memory allegedly uninitialized after ioctl(PROCMAP_QUERY)
Fix ioctl(fd, PROCMAP_QUERY, ...) so that valgrind correctly considers
memory referenced by vma_name_size and vma_name_addr members of struct
procmap_query as initialized by ioctl().

Extend ioctl syscall wrappers with needed PRE_MEM_WRITE() and
mainly POST_MEM_WRITE().  Add a testcase.

https://bugs.kde.org/show_bug.cgi?id=508328
2025-11-25 16:50:34 +01:00
Paul Floyd
e3001a5226 Bug 511713 - Refactor syscall argument handling 2025-11-06 20:36:03 +01:00
Paul Floyd
b461657ef9 Darwin: clean up use of Z-encoded libc component libraries in vg_replace_strmem.c
Use macros, mainly for consistency. Not sure how these have evolved post OSX 10.13.
2025-11-04 08:30:57 +01:00
Mark Wielaard
3392155359 Upgrade to GNU General Public License version 3
- Update COPYING and VEX/LICENSE.GPL to version 3.
- Update README, NEWS, docs/manual license and contributing text.
- Update file headers to say either version 3 of the License,
  or (at your option) any later version.
- Leave tests and perf file headers as is, unless the code is derived
  from Valgrind/VEX.
- Leave valgrind.h, cachegrind.h, callgrind.h, drd.h, helgrind.h,
  memcheck.h and dhat.h Hybrid-BSD licensed.
2025-10-18 00:55:07 +02:00
Mark Wielaard
757dc5703d Update where to get a copy of the GNU General Public License
Several files still said to write to the Free Software Foundation at a
particular address. Add a reference to <http://www.gnu.org/licenses/>
instead.

Some files that were imported into valgrind from other places still
mention the old address. They should be updated when new versions
get imported.
2025-10-18 00:55:07 +02:00
Paul Floyd
303ecc60a7 Fix exe name warnings
Most of the exe name functions can take a const char* for the name.
Indeed, on Linux this is a requirement since we also lookup
debuginfod-find using a const char string literal.

The  exception to this rule is for scripts. In this case the script
shebang can refer to another script with another shebang. And so on
until eventually an ELF or macho file is encountered. In that case
VG_(args_the_exename) will get freed if necessary and reassigned
to a new string. So VG_(load_script) needs to be able to take a
non-const char* name, unlike VG_(load_ELF) and VG_(load_macho).

VG_(args_the_exename) is now non-const (which fixes a warning
when freeing it), VG_(load_script) takes a non-const name
and there is an ugly cast for the function pointer.
2025-10-14 08:27:16 +02:00
Martin Cermak
001f7439d6 Define __NR_swapon and __NR_swapoff on riscv64
Update commit c3f8f3ceb4 adding
a missing define.

https://bugs.kde.org/show_bug.cgi?id=368791
2025-10-10 18:12:02 +02:00
Martin Cermak
0aecd4fe70 Wrap the mount_setattr syscall 442
int syscall(SYS_mount_setattr, int dirfd, const char *pathname,
           unsigned int flags, struct mount_attr *attr, size_t size);

The mount_setattr() system call changes the mount properties of a
mount or an entire mount tree.  If pathname is a relative pathname,
then it is interpreted relative to the directory referred to by the
file descriptor dirfd.  If dirfd is the special value AT_FDCWD, then
pathname is interpreted relative to the current working directory of
the calling process.  If pathname is the empty string and
AT_EMPTY_PATH is specified in flags, then the mount properties of the
mount identified by dirfd are changed

Declare a mount_setattr wrapper in priv_syswrap-linux.h and hook it
for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x,x86}-linux
using LINX_ with PRE handler in syswrap-linux.c

Part of this update also is a fix of the sys_move_mount wrapper.
Specifically there was a typo mount_moce vs. move_mount, and also
there was a problem in handling VKI_AT_FDCWD special fd value in the
check for to_fd and to_pathname.

https://bugs.kde.org/show_bug.cgi?id=509566
2025-09-19 23:51:17 +02:00
Martin Cermak
2604bb753a Wrap the setdomainname syscall
The setdomainname() call sets the domain name to the value given in the
character array name.  The len argument specifies the number of bytes in
name.  (Thus, name does not require a terminating null byte.)

Declare a setdomainname wrapper in priv_syswrap-linux.h and hook it for
{amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x,x86}-linux using
LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=369030
2025-09-19 18:37:18 +02:00
Martin Cermak
53c66de885 Add missing ppc64-linux and s390x-linux syswraps existing on other arches
This update adds following ppc64le and s390x syswraps:
 - sys_msgctl
 - sys_semctl
 - sys_semtimedop
 - sys_sethostname
 - sys_shmctl
 - sys_sigpending
 - sys_stime

This update adds following ppc64le syswraps:
 - sys_setns

This update adds following s390x syswraps:
 - sys_bpf

Blacklist the shmctl05, as it is a long running one.  It does
pass on all architectures afaics, but needs a relatively high
LTP_TIMEOUT_MUL setting. So, let's skip that one.

https://bugs.kde.org/show_bug.cgi?id=509642
https://bugs.kde.org/show_bug.cgi?id=509643
2025-09-19 17:19:12 +02:00
Martin Cermak
553ada1484 Wrap the quotactl_fd syscall
SYSCALL_DEFINE4(quotactl_fd,
    unsigned int, fd,
    unsigned int, cmd,
    qid_t, id,
    void __user *, addr)

The quotactl_fd works in a similar way to quotactl.  They both manipulate
disk quotas.  They differ in how the target file system is specified.
While quotactl takes path, quotactl_fd takes a file descriptor.

Declare a quotactl_fd wrapper in priv_syswrap-linux.h and hook it for
{amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x,x86}-linux using
LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=509567
2025-09-18 21:50:46 +02:00
Paul Floyd
210e092347 FreeBSD auxv: add new values for FreeBSD 15 2025-09-17 08:33:48 +02:00
Paul Floyd
1c123a757c build warning: silence a warning
and correct a comment referring to the wrong system header
2025-09-14 17:36:26 +02:00
Martin Cermak
4b9d06bcde Wrap the futex_waitv syscall
Wrap the futex2/futex_waitv syscall:

sys_futex_waitv(struct futex_waitv __user *, waiters,
                unsigned int, nr_futexes, unsigned int, flags,
                struct __kernel_timespec __user *, timeout, clockid_t, clockid)

sys_futex_waitv - Wait on a list of futexes
@waiters:    List of futexes to wait on
@nr_futexes: Length of futexv
@flags:      Flag for timeout (monotonic/realtime)
@timeout:    Optional absolute timeout.
@clockid:    Clock to be used for the timeout, realtime or monotonic.

Given an array of `struct futex_waitv`, wait on each uaddr. The thread wakes
if a futex_wake() is performed at any uaddr. The syscall returns immediately
if any waiter has *uaddr != val. *timeout is an optional timeout value for
the operation. Each waiter has individual flags. The `flags` argument for
the syscall should be used solely for specifying the timeout as realtime, if
needed. Flags for private futexes, sizes, etc. should be used on the
individual flags of each waiter. Returns the array index of one of the woken
futexes. No further information is provided.

Declare a futex_waitv wrapper in priv_syswrap-linux.h
and hook it for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x\
,x86}- linux using LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=506816
2025-09-12 13:31:03 +02:00
Martin Cermak
818e7661ec Wrap the remap_file_pages syscall
The remap_file_pages() system call is used to create a nonlinear
mapping, that is, a mapping in which the pages of the file are
mapped into a nonsequential order in memory.  It is deprecated
but in some cases it may still be used.  LTP remap_file_pages01
and remap_file_pages02 test-cover it.

Declare a remap_file_pages wrapper in priv_syswrap-linux.h
and hook it for {amd64,arm,arm64,mips64,ppc32,ppc64,riscv64,s390x\
,x86}- linux using LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=309554
2025-09-08 19:13:18 +02:00
Paul Floyd
4cfbb3aaa6 Bug 509258 - FreeBSD: add jail_attach_jd and jail_remove_jd syscall wrappers 2025-09-08 07:31:02 +02:00
Paul Floyd
68f06cbe97 Solaris 11: fix for VG_(lstat)
This function was using SYS_lstat. It works OK with illumos
but not Solaris 11+ which has removed that syscall.

Instead do like Linux and FreeBSD, use SYS_fstatat with the flag
for no follow link.
2025-09-06 16:49:10 +02:00
Paul Floyd
d7fc1bc7c4 FreeBSD syscalls: new getgroups and setgroups
Wasn't quite right for FreeBSD 15.
2025-08-31 16:40:30 +02:00
Paul Floyd
128017143a Bug 508958 - FreeBSD: add getgroups and setgroups wrappers 2025-08-31 16:32:20 +02:00
Paul Floyd
d9ed6b6f29 Bug 507867 - perf_event_open group_fd isn't checked 2025-08-31 10:44:49 +02:00
Martin Cermak
05aa735a5b Fix mips32 FTBFS
Define __NR_statmount and __NR_listmount.
This update makes the source buildable on the mips32 arch.

https://bugs.kde.org/show_bug.cgi?id=508027
2025-08-11 17:13:23 +02:00
Paul Floyd
7fb17b67f4 Bug 505673 - Valgrind crashes with an internal error and SIGBUS when the guest tries to open its own file with O_WRONLY|O_CREAT|O_TRUNC
This is all quite messy.

It affects open() openat() and openat2() (the last of which is Linux only).
On Linux we also need to check for /proc/self/exe and /proc/PID/exe.
On Linux there are also a couple of RESOLVE flags for openat2() that
mean _don't_ check /proc magic links.
In the general case we need to have some reference to check whether
the filename matches the guest filename. So I've added that as
VG_(resolved_exename) (which I was already using on FreeBSD).
The pathname also needs to be canonicalised. It may be a
relative path, symlink or use RESOLVE_IN_ROOT. That uses
VG_(realpath) (again which was already present for FreBSD).
On illumos the man page says that opening running binaries for
writing failes with errno set to ETXTBSY but that's not what
the open functions do - they just open the file. So I've done nothing
for illumos or Solaris. Maybe I'll open an illumos ticket.
I haven't tried on Darwin.

The Linux open functions with /proc/self/exe and /proc/PID/exe
were just calling dup on the fd that we hold for the client exe.
That means that we were ignoring any other flags. That has now changed.
If the open doesn't fail because the WRONLY/RDWR flags are set then
the syscall gets called from the PRE wrapper using VG_(resolved_exename)
instewad of the /proc pathname.

I haven't tried to handle all of the Linux openat2 RESOLVE*
flags. RESOLVE_NO_MAGICLINKS is handled and I see the LTS test
openat202 now passing, so this should also fix Bug 506910.

I'm not sure that VG_(realpath) handles all forms of weird path
resolution on Linux (on FreeBSD it uses a syscall so that should
work OK).
2025-07-19 15:10:31 +02:00
Paul Floyd
baac076edf FreeBSD: fix check for mmap flags
On FreeBSD, mmap also has MAP_STACK and MAP_GUARD that can
be mapped without a backing file referred to by fd.

As a result during ld.so startup and thread creation mmap for
stacks was failing. So no guest could be load and execute,
with errors like

ld-elf.so.1: /home/paulf/scratch/valgrind_nightly/nightly/valgrind-new/.in_place/vgpreload_core-amd64-freebsd.so: mmap of entire address space failed: Bad file descriptor
2025-07-18 13:24:28 +02:00
Martin Cermak
a4d893c6ef Wrap linux specific syscall 22 (ustat)
The ustat syscall comes from pre-git linux history.  It is
deprecated in favor of statfs.  But in some cases it may
still be used.

int ustat(dev_t dev, struct ustat *ubuf); returns information
about a mounted filesystem.  dev is a device number identifying
a device containing a mounted filesystem.  ubuf is a pointer to
a ustat structure.

Declare a sys_ustat wrapper in priv_syswrap-linux.h and hook
it for {amd64,arm,arm64,mips64,nanomips,ppc32,ppc64,riscv64,\
s390x,x86}-linux using LINXY with PRE and POST handler in
syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=506928
2025-07-17 13:02:29 +02:00
Mark Wielaard
cad20f3e7d Support mmap MAP_FIXED_NOREPLACE if defined
Define VKI_MAP_FIXED_NOREPLACE for amd64-linux, arm-linux,
arm64-linux, mips32-linux, mips64-linux, riscv64-linux and x86-linux.

If it is defined then ML_(generic_PRE_sys_mmap) will also interpret
VKI_MAP_FIXED_NOREPLACE as an MFixed hint. If the aspace manager
doesn't find a MAP_FIXED_NOREPLACE ok, then fail with EEXIST. If the
actual kernel mmap request fails and MAP_FIXED_NOREPLACE is set also
immediately fail with EEXIST without retrying.

This fixes the LTP mmap17 testcase.

https://bugs.kde.org/show_bug.cgi?id=418756
2025-07-15 23:59:48 +02:00
Paul Floyd
36e090c39c Bug 506499 - Unhandled syscall 592 (exterrctl - FreeBSD)
Also add wrapers for inotify_add_watch_at and inotify_rm_watch

No specific tests for these yet.
2025-07-12 22:23:05 +02:00
Paul Floyd
7cbcd30804 FreeBSD syscall: improve kenv wrapper and add a test for it 2025-07-12 16:22:21 +02:00
Alexandra Hájková
7615845dcd Implement fcntl F_CREATED_QUERY
Define VKI_F_CREATED_QUERY in vki-linux.h.
Recognize it in PRE(sys_fcntl).
This fixes ltp tests failures. When running:
make ltpchecks TESTS="fcntl40 fcntl40_64
the tests would fail with:
fcntl40: unempty log2.filtered:
==1809471== Warning: unimplemented fcntl command: 1028

https://bugs.kde.org/show_bug.cgi?id=506076
2025-07-04 14:46:10 +02:00
Martin Cermak
57152acfc6 Wrap linux specific syscalls 457 (listmount) and 458 (statmount)
The listmount syscall returns a list of mount IDs under the req.mnt_id.
This is meant to be used in conjunction with statmount(2) in order to
provide a way to iterate and discover mounted file systems.

The statmount syscall returns information about a mount, storing it in
the buffer pointed to by smbuf.  The returned buffer is a struct
statmount which is of size bufsize.

Declare a sys_{lis,sta}tmount wrapper in priv_syswrap-linux.h and hook it
for {amd64,arm,arm64,mips64,nanomips,ppc32,ppc64,riscv64,s390x,x86}-linux
using LINXY with PRE and POST handler in syswrap-linux.c

Both syscalls need CAP_SYS_ADMIN, to successfully test.

Resolves: https://bugs.kde.org/show_bug.cgi?id=502968
2025-06-27 22:52:01 +02:00
Martin Cermak
9775bc496e Wrap linux specific mseal syscall
mseal takes address, size and flags.  Flags are reserved for
future use. Modern CPUs support memory permissions such as RW and
NX bits.  The mseal syscall takes address and size parameters to
additionally protect memory mapping against modifications.

FTR: https://docs.kernel.org/userspace-api/mseal.html

Declare a sys_mseal wrapper in priv_syswrap-linux.h and hook it
for {amd64,arm,arm64,mips64,nanomips,ppc32,ppc64,riscv64,s390x,x86}-linux
using LINX_ with PRE handler in syswrap-linux.c

https://bugs.kde.org/show_bug.cgi?id=505228
2025-06-17 17:19:09 +02:00
Paul Floyd
f7b087df5c Bug 504936 - Add FreeBSD amd64 sysarch subcommands AMD64_SET_TLSBASE and AMD64_GET_TLSBASE 2025-05-29 09:58:31 +02:00