96 Commits

Author SHA1 Message Date
Paul Floyd
fd20bb9c67 Make aligned_alloc behave more like the underlying platform aligned_alloc
This is the third part of
Bug 466104 aligned_alloc problems, part 1

Shouldn't affect Linux glibc.
2023-03-05 15:25:51 +01:00
Paul Floyd
e862c6f3d2 Make memalign behave more like the underlying platform memalign
This is the first part of
Bug 466104 aligned_alloc problems, part 1

The bulk of this change is try try to get memalign to be more
platform aware. Previously the Valgrind implementation only
reflected the glibc implementation. That meant non-power of
two alignment values would silently get bumped up to the
next largest power of two. Most other platforms return NULL
and set errno to EINVAL.

There are a few other changes. A couple of the other aligned alloc
functions like valloc were caling the Valgrind memalign. This meant
that there weould be an extra Valgrind memalign in any error
callstacks. Now these functions call the allocator directly.

The memcheck memalign2 testcase has been redone. The memalign
parts moved out to per-platform versions and the tescase
itdelf renamed to posix_memalign, since that is all that is left.
I also modified the testcase so that it checks that the
memalign calls check for non-NULL returns, and on platforms
that set errno that it is correctly set. Previously the
test only worked on non-glibc because NULL & alignment is
zero.  The platform versions have been tested on glibc,
MUSL, FreeBSD and OpenIndiana and should hopefully run OK
both under memcheck and standalone.

There is stil quite a lot that is NOT done

1. I'm not certain that implementations allocate more memory
   and/or use a wider alignment. It doesn't help that almost
   universally the memalign implementations are badly
   documented, undocumented or buggy.
2. We don't handle very large alignment requests well.
   Most implementations will fail and set EINVAL if the
   alignment is over half the memory space. Valgrind will
   core panic if an aligmnt of over 16Mbytes is requested.
3. We don't generate any memcheck errors for invalid values
   of alignment. That's planned in Part 2.
4. The code is static and fixed at compile time. That means that
   if you are using MUSL with a glibc-built Valgrind you
   will still get glibc memalign behaviour.
   I'll wait to see if there are any requests before trying
   to make the behaviour selectable at runtime.
2023-02-28 13:46:08 +01:00
Paul Floyd
7136cd9876 musl regtest : fix warnings and badly initialized struct msghdr 2023-02-21 23:05:22 +01:00
Paul Floyd
99dfad28a5 Cleanup warnings
Now no warnings on Fedora 36
For a short while
2023-01-09 23:57:01 +01: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
Paul Floyd
e484eee0bd Bug 445300 [PATCH] Fix building tests with Musl
Patch contributed by
   Alyssa Ross <hi@alyssa.is>
2021-11-22 08:42:53 +01:00
Bart Van Assche
7cd4d78163 memcheck/tests/linux/stack_changes: Only run this test if setcontext() is available
See also https://bugs.kde.org/show_bug.cgi?id=434775 .
2021-03-28 20:48:22 -07:00
Mark Wielaard
3751e963fa Add memcheck/tests/linux/debuginfod-check.pl to EXTRA_DIST
debuginfod-check.pl is necessary as pre-check for make regtest.
2021-03-15 15:47:54 +01:00
Aaron Merey
fd4e3fb0ff PR432215 Add debuginfod functionality
debuginfod is an HTTP server for distributing ELF/DWARF debugging
information.  When a debuginfo file cannot be found locally, Valgrind
is able to query debuginfod servers for the file using its build-id.

readelf.c: Add debuginfod_find_debug_file(). Spawns a child process to
exec `debuginfod-find` in order to query servers for the debuginfo
file. Also add helper debuginfod_find_path().

pub_core_pathscan.h: Moved from priv_initimg_pathscan.h in order to use
VG_(find_executable)() in readelf.c.

docs: Add information regarding debuginfod to valgrind.1

memcheck/tests/linux: Add new test debuginfod-check.

tests/vg_regtest.in: Clear $DEBUGINFOD_URLS before running any tests.

https://bugs.kde.org/show_bug.cgi?id=432215
2021-02-26 01:38:42 +01:00
Allison Karlitskaya
dec3050653 Linux: Add wrapper for fcntl(F_{GET,ADD}_SEALS)
Add also a testcase to memcheck/tests/linux, enabled according to a new
check for memfd_create() in configure.ac.

https://bugs.kde.org/show_bug.cgi?id=361770
2021-02-20 21:04:12 +01:00
Mark Wielaard
1c9a0bf58a PR217695 malloc/calloc/realloc/memalign failure doesn't set errno to ENOMEM
When one of the allocation functions in vg_replace_malloc failed
they return NULL, but didn't set errno. This is slightly tricky since
errno is implementation defined and might be a macro. In the case of
glibc ernno is defined as:

  extern int *__errno_location (void) __THROW __attribute__ ((__const__));
  #define errno (*__errno_location ())

We can use the same trick as we use for __libc_freeres in
coregrind/vg_preloaded.c. Define the function as "weak". This means
it will only be defined if another library (glibc in this case)
actually provides a definition. Otherwise it will be NULL.
So we will only call it if it is defined and one of the allocation
functions failed, returned NULL.

Include a new linux only memcheck testcase, enomem.vgtest.

https://bugs.kde.org/show_bug.cgi?id=217695
2021-02-17 13:14:41 +01:00
Alexandra Hájková
6f6ff49ffa Add support for execveat syscall
Refactor the code to be reusable between execve and
execveat syscalls.

https://bugs.kde.org/show_bug.cgi?id=345077
2020-06-08 20:58:09 +02:00
Aleksandar Rikalo
b07722631f Make memcheck/tests/linux/sigqueue usable with musl
Remove offsetof(siginfo_t, _sifields) from the test.
"_sifields" is not a mandatory field of struct siginfo_t so
it should not be used in regular user program.

This patch resolves KDE #417266.
2020-04-23 16:31:50 +00:00
Philippe Waroquiers
4b39d33437 Fix compilation problem when __NR_preadv2 __NR_pwritev2 are undefined
check_preadv2_pwritev2.c: In function ‘main’:
check_preadv2_pwritev2.c:12:12: error: ‘__NR_preadv2’ undeclared (first use in this function)
    syscall(__NR_preadv2, 0, NULL, 0, 0, 0);
            ^
check_preadv2_pwritev2.c:12:12: note: each undeclared identifier is reported only once for each function it appears in
check_preadv2_pwritev2.c:15:12: error: ‘__NR_pwritev2’ undeclared (first use in this function)
    syscall(__NR_pwritev2, 0, NULL, 0, 0, 0);
2019-08-17 18:27:22 +02:00
Stefan Maksimovic
0f7483d1d8 memcheck/tests/sys-preadv2_pwritev2: Check whether these syscalls are supported
[ bvanassche: changed the order of check_PROGRAMS ]
2019-08-16 18:09:44 -07:00
Alexandra Hájková
b0861063a8 Add support for preadv2 and pwritev2 syscalls
Support for amd64, x86 - 64 and 32 bit, arm64, ppc64, ppc64le,
s390x, mips64. This should work identically on all
arches, tested on x86 32bit and 64bit one, but enabled on all.

Refactor the code to be reusable between old/new syscalls. Resolve TODO
items in the code. Add the testcase for the preadv2/pwritev2 and also
add the (similar) testcase for the older preadv/pwritev syscalls.

Trying to test handling an uninitialized flag argument for the v2 syscalls
does not work because the flag always comes out as defined zero.
Turns out glibc does this deliberately on 64bit architectures because
the kernel does actually have a low_offset and high_offset argument, but
ignores the high_offset/assumes it is zero.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=601cc11d054ae4b5e9b5babec3d8e4667a2cb9b5

https://bugs.kde.org/408414
2019-07-03 00:19:16 +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
Mark Wielaard
033d013beb Fix memcheck/tests/linux/sys-copy_file_range open call (mode).
sys-copy_file_range.c calls open with O_CREAT flag and so must provide
a mode argument. valgrind memcheck actually caught this ommission on
some arches (fedora rawhide i686 specifically).

This is a small additional fixup for
https://bugs.kde.org/show_bug.cgi?id=407218
2019-05-24 21:51:31 +02:00
Mark Wielaard
c212b72a63 Explicitly make testcase variable for sys-copy_file_range undefined.
On some systems an extra warning could occur when a variable in
the memcheck/tests/linux/sys-copy_file_range testcase was undefined,
but (accidentially) pointed to known bad memory. Fix by defining the
variable as 0, but then marking it explicitly undefined using memcheck
VALGRIND_MAKE_MEM_UNDEFINED.

Followup for https://bugs.kde.org/show_bug.cgi?id=407218
2019-05-15 21:30:09 +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
Philippe Waroquiers
cfae4f70a6 Modify .exp files following the new error message.
Change:
For counts of detected and suppressed errors, rerun with: -v
to
For lists of detected and suppressed errors, rerun with: -s
2018-12-28 19:33:00 +01:00
Mark Wielaard
2e2ae5bda8 Implement minimal ptrace support for ppc64[le]-linux. 2018-12-14 14:41:57 +01:00
Philippe Waroquiers
7fe4ff55cc Make sys-statx.c test compile with glibc >= 2.28
Newer glibc >= 2.28 provides a wrapper (and struct definitions) for statx.
So, only include linux/stat.h on older glibc.

This fixes a build failure on (at least) fedora 29 with glibc 2.28
2018-08-12 13:28:50 +02: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
Mark Wielaard
190c93d454 Refix dlclose_leak.c test.
By introducing an extra line to declare int i; we broke the expected
line numbers in the test. Just declare i on the same line as the for loop.
2018-01-16 11:31:43 +01:00
Mark Wielaard
400ad0e36e Fix memcheck/tests/linux/dlclose_leak.c build under -std=gnu90.
Older gcc (4.8) default to GNU C90. Causing:

dlclose_leak.c:14:5: error: ‘for’ loop initial declarations are only
                     allowed in C99 mode

Fix by declaring int i before the loop.
2018-01-16 11:08:59 +01:00
Julian Seward
f8ae2f95d6 Bug 79362 - Debug info is lost for .so files when they are dlclose'd. Followup fix to avoid assertion failure when dlopening an object that has previously been dlclosed.
As reported by Matthias Schwarzott <zzam@gentoo.org>.  Testcase patch from him.  The fix is
for check_CFSI_related_invariants() to avoid checking for overlaps against DebugInfos that are
in 'archived' status, since -- if a previously dlopened-and-then-dlclosed object is later
re-dlopened -- this may cause an overlap between the active and archived DebugInfos, which
is of no consequence.  If the kernel maps the object to the same VMA the second time around
then there will *certainly* be an overlap.
2018-01-15 11:25:12 +01:00
Julian Seward
cceed053ce Bug 79362 - Debug info is lost for .so files when they are dlclose'd. Majorly reworked by Philippe Waroquiers. 2018-01-11 19:40:12 +01:00
Ivo Raisr
6fbb3ddfe5 Add .stderr.exp file for memcheck/tests/linux/capget when running inside Docker container. 2017-11-15 23:37:17 +01:00
Mark Wielaard
2b5eab6a8d memcheck/tests: Use ucontext_t instead of struct ucontext
glibc 2.26 does not expose struct ucontext anymore.

Signed-off-by: Khem Raj <raj.khem@gmail.com>

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16457
2017-06-29 15:26:30 +00: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
f8a8e3de4d Fix expected output of brk tests after r16407.
n-i-bz


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16410
2017-05-23 21:22:31 +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
268ff84f7b Document brk segment limitation, reference manual in limit reached msg.
The msg telling brk cannot be extended confuses some users
so improve the documentation and have the msg referencing the doc.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15880
2016-05-22 20:48:09 +00:00
Mark Wielaard
dcb119cf41 Squash glibc warning about _BSD_SOURCE being deprecated tests.
glibc 2.20 deprecated _BSD_SOURCE and _SVID_SOURCE and now requires
_DEFAULT_SOURCE to be defined instead. Add _DEFAULT_SOURCE define to
prevent warnings like:

In file included from /usr/include/stdio.h:27:0,
                 from stack_switch.c:5:
/usr/include/features.h:148:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
   ^

See https://sourceware.org/glibc/wiki/Release/2.20#Packaging_Changes

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15768
2016-01-22 13:49:22 +00:00
Bart Van Assche
d138ed7448 regression tests: Remove superfluous backticks
Backticks are not needed around a shell statement that does not produce
any output.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15439
2015-07-23 02:47:42 +00:00
Florian Krohm
97b35b97f6 Issue an error message if then brk segment overflows.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15155
2015-04-29 12:59:16 +00:00
Florian Krohm
ac9506ad26 Disable testcase because the ptrace system call is not
supported on ppc64.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15010
2015-03-14 09:30:36 +00:00
Florian Krohm
27df6d48bf Followup to r14646. The symbol TIOCSIG is not necessarily defined,
e.g. on s390x with glibc 2.3.4. Modify the testcase to bypass the ioctl
call in that case.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14649
2014-10-22 09:25:03 +00:00
Florian Krohm
17fe8c0a09 Add support for ioctl(fd, TIOCSIG, signal_number) which used
to issue a false complaint. Fixes BZ #339706
Source patch by David Herrmann (dh.herrmann@gmail.com).
Testcase by myself.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14646
2014-10-21 07:20:20 +00:00
Philippe Waroquiers
eb2b193943 Fix dangling ref in m_errormgr.c + report all uninit fields in a syscall param
Some syscall verification code is allocating memory to generate 
the string used to build an error, e.g. syswrap-generic.c verifying fields of
e.g socket addresses (pre_mem_read_sockaddr) or sendmsg/recvmsg args 
(msghdr_foreachfield)

The allocated pointer was copied in the error created by VG_(maybe_record_error).

This was wrong for 2 reasons:
1. If the error is a new error, it is stored in a list of errors,
   but the string memory was freed by pre_mem_read_sockaddr, msghdr_foreachfield, ...
   This causes a dangling reference. Was at least visible when giving -v, which
   re-prints all errors at the end of execution.
   Probably this could have some consequences during run while generating new errors,
   and comparing for equality with a recorded error having a dangling reference.
2. the same allocated string is re-used for each piece/field of the verified struct.
   The code in mc_errors.c that checks that 2 errors are identical was then wrongly
   considereing that 2 successive errors for 2 different fields for the same syscall
   arg are identical, just because the error string happened to be produced at
   the same address.
(it is believed that initially, the error string was assumed to be a static
string, which is not the case anymore, causing the above 2 problems).

Changes:
* The fix consists in duplicating in m_errormgr.c the given error string when
  the error is recorded. In other words, the error string is now duplicated similarly
  to the (optional) extra component of the error.

* memcheck/tests/linux/rfcomm.c test modified as now an error is reported
  for each uninit field.

* socketaddr unknown family is also better reported (using sa_data field name,
  rather than an empty field name.

* minor reformatting in m_errormgr.c, to be below 80 characters.

Some notes:
1. the string is only duplicated if the error is recorded
   (ie. printed or the first time an error matches a suppression).
   The string is not duplicated for duplicated errors or following errors
   matching the first (suppressed) error.
   The string is also not duplicated for 'unique errors' (that are printed
   and then not recorded).
2. duplicating the string for each recorded error is not deemed to
   use a lot of memory:
     * error strings are usually NULL or short (often 10 bytes or so).
     * we expect no program has a huge number of errors
   If ever this string duplicate would be significant, having a DedupPoolAlloc
   in m_errormgr.c for these strings would reduce this memory (as we expect to
   have very few different strings, even with millions of errors).



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14214
2014-07-30 22:20:29 +00:00
Philippe Waroquiers
9b67d18f11 Improve address description for address in the stack.
--read-var-info=yes is very memory and cpu intensive.
This patch ensures that even witout --read-var-info=yes that
the frame where the address point is reported in the address
description.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13991
2014-05-22 23:48:24 +00:00
Mark Wielaard
86f74d6026 Support Linux kernel AF_BLUETOOTH for bind().
Bug #320116. sockaddr_rc might contain some padding which might not be
initialized. Explicitly check the sockaddr_rc fields are set. That also
produces better diagnostics about which field is unitialized.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13404
2013-05-22 10:21:10 +00:00
Florian Krohm
8c76e43290 Make sys-openat test conditional upon the existence of AT_FDCWD.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13171
2012-12-08 19:26:03 +00:00
Julian Seward
12a820fcbf Fix some gcc complaints about unused variables in these tests.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13167
2012-12-06 23:11:19 +00:00
Julian Seward
36468d9ae2 For sys-openat the dirfd argument should be ignored when the pathname
is absolute.  Fixes #307103.  (Mark Wielaard, mjw@redhat.com)



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13159
2012-12-06 16:05:18 +00:00
Petar Jovanovic
516de0bcd6 Correctly skip memcheck's getregset for MIPS.
Previous change r13145 incorrectly disables getregset test for all architectures
rather than just for MIPS arch. Issue spotted by Bart Van Assche and reported on
the list.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13148
2012-12-03 00:31:42 +00:00
Petar Jovanovic
a167c7a54d Skip memcheck's getregset for MIPS.
Skip the getregset test for MIPS since we still does not have TRACEHOOK
support in MIPS kernel for it, and that is needed to support PTRACE_GETREGSET.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13145
2012-12-02 03:37:36 +00:00
Christian Borntraeger
73744bb25f GETREGSET was introduced with 2.6.33.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13115
2012-11-09 08:06:14 +00:00