diff --git a/valgrind-3.16.0-shmctl.patch b/valgrind-3.16.0-shmctl.patch new file mode 100644 index 0000000..16d9d7c --- /dev/null +++ b/valgrind-3.16.0-shmctl.patch @@ -0,0 +1,111 @@ +commit 232893d9b3c7d79d018db7f303aee219161a86d0 +Author: Anssi Hannula +Date: Thu Jul 2 14:49:17 2020 +0300 + + Fix shmat() on Linux nanomips and x86 + + On Linux, there are two variants of the direct shmctl syscall: + - sys_shmctl: always uses shmid64_ds, does not accept IPC_64 + - sys_old_shmctl: uses shmid_ds or shmid64_ds depending on IPC_64 + + The following Linux ABIs have the sys_old_shmctl variant: + alpha, arm, microblaze, mips n32/n64, xtensa + + Other ABIs (and future ABIs) have the sys_shmctl variant, including ABIs + that only got sys_shmctl in Linux 5.1 (such as x86, mips o32, ppc, + s390x). + + We incorrectly assume the sys_old_shmctl variant on nanomips and x86, + causing shmat() calls under valgrind to fail with EINVAL. + + On x86, the issue was previously masked by the non-existence of + __NR_shmctl until a9fc7bceeb0b0 ("Update Linux x86 system call number + definitions") in 2019. + + On mips o32, ppc, and s390x this issue is not visible as our headers do + not have __NR_shmctl for those ABIs (396 since Linux 5.1). + + Fix the issue by correcting the preprocessor check in get_shm_size() to + only assume the old Linux sys_old_shmctl behavior on the specific + affected platforms. + + Also, exclude the use of direct shmctl entirely on Linux x86, ppc, + mips o32, s390x in order to keep compatibility with pre-5.1 kernel + versions that did not yet have direct shmctl for those ABIs. + This currently only has actual effect on x86 as only it has __NR_shmctl + in our headers. + + Fixes tests mremap4, mremap5, mremap6. + + https://bugs.kde.org/show_bug.cgi?id=410743 + +diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c +index badb8c778..7d4b385a3 100644 +--- a/coregrind/m_syswrap/syswrap-generic.c ++++ b/coregrind/m_syswrap/syswrap-generic.c +@@ -1960,11 +1960,27 @@ ML_(generic_POST_sys_semctl) ( ThreadId tid, + static + SizeT get_shm_size ( Int shmid ) + { +-#if defined(__NR_shmctl) ++ /* ++ * The excluded platforms below gained direct shmctl in Linux 5.1. Keep ++ * using ipc-multiplexed shmctl to keep compatibility with older kernel ++ * versions. ++ */ ++#if defined(__NR_shmctl) && \ ++ !defined(VGP_x86_linux) && !defined(VGP_mips32_linux) && \ ++ !defined(VGP_ppc32_linux) && !defined(VGP_ppc64be_linux) && \ ++ !defined(VGP_ppc64le_linux) && !defined(VGP_s390x_linux) + # ifdef VKI_IPC_64 + struct vki_shmid64_ds buf; +-# if defined(VGP_amd64_linux) || defined(VGP_arm64_linux) +- /* See bug 222545 comment 7 */ ++ /* ++ * On Linux, the following ABIs use old shmid_ds by default with direct ++ * shmctl and require IPC_64 for shmid64_ds (i.e. the direct syscall is ++ * mapped to sys_old_shmctl): ++ * alpha, arm, microblaze, mips n32/n64, xtensa ++ * Other Linux ABIs use shmid64_ds by default and do not recognize IPC_64 ++ * with the direct shmctl syscall (but still recognize it for the ++ * ipc-multiplexed version if that exists for the ABI). ++ */ ++# if defined(VGO_linux) && !defined(VGP_arm_linux) && !defined(VGP_mips64_linux) + SysRes __res = VG_(do_syscall3)(__NR_shmctl, shmid, + VKI_IPC_STAT, (UWord)&buf); + # else +commit 620dba22be67dea2ada9fa825b2ed4d61774af82 +Author: Mark Wielaard +Date: Wed Feb 3 16:56:14 2021 +0100 + + syswrap-linux.c: Pass implicit VKI_IPC_64 for shmctl also on arm64. + + The shmctl syscall on amd64, arm64 and riscv (but we don't have a port + for that last one) always use IPC_64. Explicitly pass it to the generic + PRE/POST handlers so they select the correct (64bit) data structures on + those architectures. + + https://bugzilla.redhat.com/show_bug.cgi?id=1909548 + +diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c +index 328e02a98..52074149d 100644 +--- a/coregrind/m_syswrap/syswrap-linux.c ++++ b/coregrind/m_syswrap/syswrap-linux.c +@@ -5127,7 +5127,7 @@ PRE(sys_shmctl) + PRINT("sys_shmctl ( %ld, %ld, %#" FMT_REGWORD "x )", SARG1, SARG2, ARG3); + PRE_REG_READ3(long, "shmctl", + int, shmid, int, cmd, struct shmid_ds *, buf); +-#ifdef VGP_amd64_linux ++#if defined(VGP_amd64_linux) || defined(VGP_arm64_linux) + ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2|VKI_IPC_64,ARG3); + #else + ML_(generic_PRE_sys_shmctl)(tid, ARG1,ARG2,ARG3); +@@ -5136,7 +5136,7 @@ PRE(sys_shmctl) + + POST(sys_shmctl) + { +-#ifdef VGP_amd64_linux ++#if defined(VGP_amd64_linux) || defined(VGP_arm64_linux) + ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2|VKI_IPC_64,ARG3); + #else + ML_(generic_POST_sys_shmctl)(tid, RES,ARG1,ARG2,ARG3); diff --git a/valgrind.spec b/valgrind.spec index 7264d47..5a33e04 100644 --- a/valgrind.spec +++ b/valgrind.spec @@ -3,7 +3,7 @@ Summary: Tool for finding memory management bugs in programs Name: %{?scl_prefix}valgrind Version: 3.16.1 -Release: 15%{?dist} +Release: 16%{?dist} Epoch: 1 License: GPLv2+ URL: http://www.valgrind.org/ @@ -143,6 +143,10 @@ Patch21: valgrind-3.16.1-ppc64-scv-hwcap.patch # KDE#432102 Support DWARF5 Patch22: valgrind-3.16.1-dwarf5.patch +# KDE#410743 shmat() calls for 32-bit programs fail when running in 64-bit +# RHBZ#1909548 shmctl(IPC_STAT) doesn't set shm_nattch on aarch64 +Patch23: valgrind-3.16.0-shmctl.patch + BuildRequires: make BuildRequires: glibc-devel @@ -294,6 +298,7 @@ Valgrind User Manual for details. %patch20 -p1 %patch21 -p1 %patch22 -p1 +%patch23 -p1 %build # LTO triggers undefined symbols in valgrind. Valgrind has a --enable-lto @@ -518,6 +523,9 @@ fi %endif %changelog +* Wed Feb 3 2021 Mark Wielaard - 3.16.1-16 +- Add valgrind-3.16.0-shmctl.patch + * Wed Jan 27 2021 Fedora Release Engineering - 1:3.16.1-15 - Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild