17110 Commits

Author SHA1 Message Date
Paul Floyd
1fa46af2d4 Make regtest memcheck/tests/amd64/insn-pmovmskb clang friendly
Clang 13 on FreeBSD 13.1 emits a cmov which changes the error
messages. Use an 'if' instead which works with both clang and GCC.
2022-05-19 21:21:18 +02:00
Paul Floyd
c065867e55 Add attribute noinline to memcheck/tests/wrap6.c
With clang 13 this testcase was failing due to inlining/optimization of fn_12.
2022-05-19 20:58:10 +02:00
Paul Floyd
6b7cd3b4e4 Update FreeBSD (f)stat tests for FreeBSD 13.1
Somewhat annoyingly, libc is using tail call optimization
which alters our callstacks.

FreeBSD 13 and earlier had something like

{compatibility API check}
  1372e0:       48 8d 95 08 fe ff ff    lea    -0x1f8(%rbp),%rdx
  1372e7:       bf 8d 01 00 00          mov    $0x18d,%edi
  1372ec:       44 89 f6                mov    %r14d,%esi
  1372ef:       31 c0                   xor    %eax,%eax
  1372f1:       e8 8a c5 09 00          call   1d3880 <syscall@plt>

{compatibility API check}
  1342b9:       3d 9f 4f 12 00          cmp    $0x124f9f,%eax
  1342be:       7c 25                   jl     1342e5 <_fstatfs+0x55>
  1342c0:       49 8b 07                mov    (%r15),%rax
  1342c3:       48 3b 45 e0             cmp    -0x20(%rbp),%rax
  1342c7:       0f 85 51 01 00 00       jne    13441e <_fstatfs+0x18e>

{compatibility not needed}
  1342cd:       44 89 f7                mov    %r14d,%edi
  1342d0:       48 89 de                mov    %rbx,%rsi
  1342d3:       48 81 c4 e8 01 00 00    add    $0x1e8,%rsp
  1342da:       5b                      pop    %rbx
  1342db:       41 5e                   pop    %r14
  1342dd:       41 5f                   pop    %r15
  1342df:       5d                      pop    %rbp

{tail call optimization}

  1342e0:       e9 bb a0 09 00          jmp    1ce3a0 <__sys_fstatfs@plt>

{compatibility API call}

So I've updated the expecteds and added a filter for 13.0 and older.
2022-05-19 19:52:57 +02:00
Paul Floyd
f6316d1b68 Fix memcheck/tests/freebsd/fexecve
This contained a stupid mistake, and had been working by luck.
2022-05-19 10:10:32 +02:00
Paul Floyd
ed78405cd6 Make testcase myrandom() noinline.
With clang 13 none/tests/amd64/amd64locked fails because of what
looks like a clang optimization error. do_bt_G_E_tests is the
point of failure, and one factor is that clang 13 is inlining
myrandom().
2022-05-18 23:41:43 +02:00
Paul Floyd
6cb8e52c34 More changes for FreeBSD 13.1
These concern auxv, swapoff and fcntl F_KINFO

I wanted to use the new fcntl K_INFO to replace the existing
horrible implementation of resolve_filename, but it seems to
have change the behaviour for redirected files. Several
fdleak regtests fail because stdout resolves to an empty
string.
2022-05-14 16:46:03 +02:00
Paul Floyd
7e5073f853 Changes to auxv for FreeBSD 13.1 2022-05-14 16:24:22 +02:00
Mike Crowe
947388eb04 Intercept strncmp for glibc ld.so v2.28+
In glibc 5aad5f617892e75d91d4c8fb7594ff35b610c042 (first released in
v2.28) a call to strncmp was added to dl-load.c:is_dst. This causes
valgrind to complain about glibc's highly-optimised strncmp performing
sixteen-byte reads on short strings in ld.so. Let's intercept strncmp in
ld.so too so we use valgrind's simple version to avoid this problem.
2022-05-14 00:41:18 +02:00
Paul Floyd
277f10d523 Try again for FreeBSD errno_aligned_allocs on x86
Harder than I thought to trigger ENOMEM on x86, so just fake it.
2022-05-10 21:01:01 +02:00
Paul Floyd
d7944c09f5 Update FreeBSD memcheck/tests/freebsd/errno_aligned_allocs.c for x86
Size to force an ENOMEM on 64bit too big for 32bit.
2022-05-10 20:23:27 +02:00
Paul Floyd
1f1abc9ec3 Add check for DRD OMP tests for FreeBSD 2022-05-10 20:08:43 +02:00
Paul Floyd
978eb7f1ab Bug 446754 Improve error codes from alloc functions under memcheck
I've made these changes only for FreeBSD and Solaris for the moment.

I don't know what should be done on Linux for aligned_alloc/memalign.
The current Valgrind code refects the glibc implementation, but not
what the documentation says.
2022-05-09 22:57:06 +02:00
Paul Floyd
35fcf875c6 FreeBSD shm_open2 also accepts first argument as SHM_ANON
Add an extra test to scalar
2022-05-09 21:27:36 +02:00
Paul Floyd
d99b369c09 FreeBSD shm_open2 arg5 seems to be optional
This syscall doesn't have a libc interface and manpage so
the documentation is skimpy.
2022-05-09 11:58:45 +02:00
Paul Floyd
3a883a6c1d Add FreeBSD shm_open2 syscall wrapper 2022-05-09 11:05:49 +02:00
Paul Floyd
a17b8d0198 Add FreeBSD-specific expected for memcheck/tests/gone_abrt_xml
The difference is in the si_code. Linux has a value of 0, FreeBSD has
65537. This is correct.

From vki-freebsd.h

/*
 * si_code values
 */

and indeed this signal gets sent by kill()
2022-05-09 09:47:12 +02:00
Paul Floyd
1ec5d23e73 Make memcheck/tests/clientperm clang-friendly
The use of the ternary operator was causing diffs compared to
GCC output. Switching to use two 'ifs' should remove this
difference.
2022-05-09 09:16:48 +02:00
Paul Floyd
54ee45d208 Update clang version of insn-pmovmskb expected.
I'm not sure when this output changed.

This expected differs from the main GCC expected due to clang emitting
a cmovne for the ternary expression in 'use':
fprintf(stderr, "%d: Invalid value is %s\n", index, invalid ? "true" : "false");
2022-05-09 08:15:06 +02:00
Paul Floyd
407c00c2e9 FreeBSD: only set osrel for executables. 2022-05-09 07:49:56 +02:00
Paul Floyd
e23f5b6a14 FreeBSD x86 small logging changes and add comments explaining why none/tests/manythreads fails 2022-05-07 17:30:23 +02:00
Paul Floyd
295ce0e643 Update FreeBSD struct vki_kinfo_vmentry 2022-05-07 17:28:08 +02:00
Paul Floyd
184e3ba052 Bug 453055 shared_timed_mutex drd test fails with "Lock shared failed" message
Patch submited by Jesus Checa jcheca@redhat.com
2022-04-27 21:13:45 +02:00
Paul Floyd
6af21da952 Bug 452779 Valgrind fails to build on FreeBSD 13.0 with llvm-devel (15.0.0)
Only link with libgcc-sup if the compiler is clang.
Still need -lgcc
2022-04-27 21:10:35 +02:00
Paul Floyd
8b2cf214af Fix warning building memcheck/tests/memalign2
Was getting warnings with clang like

memalign2.c:62:17: warning: requested alignment is not a power of 2 [-Wnon-power-of-two-alignment]
   p = memalign(0, 100);      assert(0 == (long)p % 8);
2022-04-19 22:36:36 +02:00
Paul Floyd
acdef43dce memcheck/tests/amd64/shr_edx builds fine with clang
Make it build unconditionally
2022-04-19 22:27:59 +02:00
Paul Floyd
8187a60ac3 Add a configure test for -ansi and use it for none/tests/ansi 2022-04-19 22:21:37 +02:00
Paul Floyd
1dbc46750f Bug 452779 Valgrind fails to build on FreeBSD 13.0 with llvm-devel (15.0.0)
This fixes building.

I may make the -lgcc and libgcc-sup conditonal on not using clang later.
2022-04-19 22:03:01 +02:00
Di Chen
fca4a3d8e5 Support new memfd_secret linux syscall (447)
memfd_secret is a new syscall in linux 5.14. memfd_secret() is
disabled by default and a command-line option needs to be added to
enable it at boot time.

$ cat /proc/cmdline
[...] secretmem.enable=y

https://bugs.kde.org/451878
https://lwn.net/Articles/865256/
2022-04-19 11:59:36 +02:00
Dario Binacchi
9c9fd9ae24 coregrind: fix compilation for uclibc
It fixes a known iusse whose details are described at [1] and more
generally it guarantees that Valgrind is properly compiled for ulibc.

[1] https://www.mail-archive.com/valgrind-users@lists.sourceforge.net/msg05295.html

Suggested-by Michael Trimarchi <michael@amarulasolutions.com>
Co-developed-by: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
2022-04-19 10:44:07 +02:00
Paul Floyd
d6bcd3ba29 Some more auxv extensions for FreeBSD 14
New entries added to testcase and documented in initimg.
May need more work
2022-04-14 00:01:49 +02:00
Paul Floyd
60dd674e71 Missing defines for FreeBSD 14 swapoff
+1 typo
2022-04-13 23:32:55 +02:00
Paul Floyd
cdd98111c7 Updates to FreeBSD syscalls for FreeBSD 14
3 new syscalls, and swapoff has a COMPAT13 version.
2022-04-13 23:00:44 +02:00
Paul Floyd
6c51e110a2 Update FreeBSD scalar for x86
Missed one execve diff.
2022-04-13 22:59:09 +02:00
Mark Wielaard
9fd4181b0e Set version to 3.20.0.GIT 2022-04-13 00:34:39 +02:00
Paul Floyd
d5b782056d Fix typo in EXTRA_DIST 2022-04-12 23:55:46 +02:00
Paul Floyd
3e7774ea5a Bug 452274 memcheck crashes with Assertion 'sci->status.what == SsIdle' failed
FreeBSD (and Darwin) use the carry flag for syscall syscall status.
That means that in the assembler for do_syscall_for_client_WRK
they have a call to LibVEX_GuestAMD64_put_rflag_c (amd64) or
LibVEX_GuestX86_put_eflag_c (x86). These also call WRK functions.

The problem is that do_syscall_for_client_WRK has carefully crafted
labels correspinding to IP addresses. If a signal interrupts
processdings, IP can be compared to these addresses so that
VG_(fixup_guest_state_after_syscall_interrupted) can work
out how to resume the syscall. But if IP is in the save
carry flag functions, the address is not recognized and
VG_(fixup_guest_state_after_syscall_interrupted) fails.

The crash in the title happens because the interrupted
syscall does not reset its status, and on the next syscall
it is expected that the status be idle.

To fix this I added global variables that get set to 1
just before calling the save carry flag functions, and cleared
just after. VG_(fixup_guest_state_after_syscall_interrupted)
can then check this and work out which section we are in
and resume the syscall correctly.

Also:

Start a new NEWS section for 3.20

Add a regtest for this and also a similar one for Bug 445032
(x86-freebsd only, new subdir).

I saw that this problem also probably exists with macOS, so I made
the same changes there (not yet tested)
2022-04-12 23:50:48 +02:00
Paul Floyd
68ac5ca0ea Fix building on macOS
Adds a feature check for clockid_t

Also fix a typo in a macro affecting pthread_mutex_clocklock on Linux.
2022-04-11 22:32:45 +02:00
Mark Wielaard
8d3c8034b8 -> 3.19.0 final. 2022-04-11 15:29:18 +02:00
Mark Wielaard
4c27f0f764 Extend helgrind suppression for _IO_*xsputn* FILE* state manipulation
commit 7b5867b1f "helgrind reports false races for printfs using
mempcpy on FILE* state" extended the helgrind-glibc-io-xsputn
suppression by also covering mempcpy (instead of __GI_mempcpy).
The test added in that commit exposed a couple of other variants
of this suppression where _IO_*xsputn* called memcpy (instead of
mempcpy) and/or had an extra indirection/function in between.

Replace the two two suppressions with one that covers all cases
where _IO_*xsputn* *mem*cpy variants with possibly another ...
function in between.

https://bugs.kde.org/show_bug.cgi?id=450962
2022-04-11 14:45:49 +02:00
Paul Floyd
2b33a318d8 Update Solaris execve with checks for NULL argv
Also requires 2 expected to be updated
2022-04-10 23:02:13 +02:00
Paul Floyd
5f83395616 Fix a crash handling fexecve.
Found this by testing the Solaris execx (the bits that are
Linux-cmpatible) test. That was giving

--28286-- VALGRIND INTERNAL ERROR: Valgrind received a signal 11 (SIGSEGV) - exiting
--28286-- si_code=2;  Faulting address: 0x4A0095A;  sp: 0x1002ca9c88

valgrind: the 'impossible' happened:
   Killed by fatal signal

host stacktrace:
==28286==    at 0x5803DE54: vgPlain_strcpy (m_libcbase.c:309)
==28286==    by 0x5810A9B3: vgSysWrap_linux_sys_execveat_before (syswrap-linux.c:13310)
==28286==    by 0x580953C9: vgPlain_client_syscall (syswrap-main.c:2234)

It's a mistake to copy the path obtained with VG_(resolve_filename) to
the client ARG2, it's unlikely to have space for the path.

Instead just copy the pointer.
2022-04-10 20:55:28 +02:00
Mark Wielaard
116b93b490 -> 3.19.0.RC2 2022-04-09 02:13:46 +02:00
Mark Wielaard
7b5867b1fd helgrind reports false races for printfs using mempcpy on FILE* state
We already have a suppression for helgrind which is for when glibc
uses __GI_mempcpy to manipulate internal FILE state (this was bug
352130). But since glibc-2.26 mempcpy is used instead __GI_mempcpy,
making the suppresion from the original bug obsolete.

This patch adds a new suppression using mempcpy but doesn't replace
the original suppression for older systems.

Patch adding suppression + testcase by Jesus Checa <jcheca@redhat.com>

https://bugs.kde.org/show_bug.cgi?id=450962
2022-04-08 14:58:38 +02:00
Mark Wielaard
a1bb40171a Move ht_sigchld_ignore and ht_ignore_node to pub_tool_signals.h
ht_sigchld_ignore and ht_ignore_node were defined in pub_core_signals.h
which cannot include any other tool header.

...checking header files and include directives
*** File coregrind/pub_core_signals.h must not include pub_tool_hashtable.h

So move the definition and type to pub_tool_signals.h
2022-04-08 09:42:18 +02:00
Randy MacLeod
2c0fb66569 Fix out of tree builds.
The paths to these files need to be fully specified in
the out of tree build case. glibc-2.X.supp is a generated file so the
full path is deliberately not specified in that case.

Also adjust the mpi include dir location as valgrind.h is
generated as well and needs to be taken out of build dir.

Also adjust the location of generated xml file. And the search paths
for the xmllint, xsltproc and xmlto programs.

Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
2022-04-07 23:44:02 +02:00
Aaron Merey
2ad9335044 Bug 445011: SIGCHLD is sent when valgrind uses debuginfod-find
Valgrind fork+execs debuginfod-find in order to perform debuginfod
queries. Any SIGCHLD debuginfod-find sends upon termination can
mistakenly be delivered to the client running under valgrind.

To prevent this, record in a hash table the PID of each process
valgrind forks for internal use. Do not send SIGCHLD to the client
if it is from a PID in this hash table.

https://bugs.kde.org/show_bug.cgi?id=445011
2022-04-07 22:09:57 +02:00
Mark Wielaard
7959d0661b Update mc_main Copyright message to include 2022
We haven't ran auxprogs/change-copyright-year since we switched to git.
This means most Copyright year ranges still say 2017. The script also
doesn't work for years >= 2020. Instead of trying to figure out how to
correctly update the per file Copyright year ranges just update the
main copyright notice that the program outputs on startup.
2022-04-07 22:02:12 +02:00
Paul Floyd
19584a93d1 Update FreeBSD [f]execve expecteds
As requested by Mark, for https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-07 07:56:27 +02:00
Di Chen
6a35b364c5 memfd test should be memfd_create test
Currently, syscall memfd_create was tested by this:

$ perl tests/vg_regtest memcheck/tests/linux/memfd.vgtest

Since memfd_secret introduced in kernel 5.14, valgrind should rename
the "memfd" test to "memfd_create" test to avoid the ambiguity, so that
user will not get confused with the "memfd_secret" test.

After this change, syscall memfd_create will be tested by:

$ perl tests/vg_regtest memcheck/tests/linux/memfd_create.vgtest
2022-04-07 00:36:41 +02:00
Mark Wielaard
8eb547054a Warn for execve syscall with argv or argv[0] being NULL.
For execve valgrind would silently fail when argv was NULL or
unadressable. Make sure that this produces a warning under memcheck.

The linux kernel accepts argv[0] being NULL, but most other kernels
don't since posix says it should be non-NULL and it causes argc to
be zero which is unexpected and might cause security issues.

This adjusts some testcases so they don't rely on execve succeeding
when argv is NULL and expect warnings about argv or argv[0] being
NULL or unaddressable.

https://bugs.kde.org/show_bug.cgi?id=450437
2022-04-06 22:48:45 +02:00