This patch series fixes shmctl, shmat and structs they use for compat64. Update the arm64/Kconfig as we only use ipc_parse_version in compat32.
You can also find the patches at https://git.morello-project.org/Teo-CD/linux/-/tree/review/teo/shm-compat --- v1: Initial shmctl patch v2: Split patch between generic and arm64, shmat fix and Kconfig update v3: Small nits
Teo Couprie Diaz (4): ipc/shm: Adapt shmctl for compat64 arm64: compat: Fix structs for compat64 arm64: compat: Only use legacy SHMLBA in compat32 arm64: Kconfig: ipc_parse_version depends on COMPAT32
arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/compat.h | 10 ++++++++++ arch/arm64/include/asm/shmparam.h | 2 ++ ipc/shm.c | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-)
Update copy_compat_shmid_to_user to support compat_shmid64_ds that doesn't split 64-bit values.
Don't limit shmmax to INT_MAX when in compat64.
Signed-off-by: Teo Couprie Diaz teo.coupriediaz@arm.com --- ipc/shm.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/ipc/shm.c b/ipc/shm.c index 6d929205bc41..679d898373bf 100644 --- a/ipc/shm.c +++ b/ipc/shm.c @@ -1336,8 +1336,10 @@ struct compat_shm_info { static int copy_compat_shminfo_to_user(void __user *buf, struct shminfo64 *in, int version) { +#ifdef CONFIG_COMPAT32 if (in->shmmax > INT_MAX) in->shmmax = INT_MAX; +#endif if (version == IPC_64) { struct compat_shminfo64 info; memset(&info, 0, sizeof(info)); @@ -1381,12 +1383,18 @@ static int copy_compat_shmid_to_user(void __user *buf, struct shmid64_ds *in, struct compat_shmid64_ds v; memset(&v, 0, sizeof(v)); to_compat_ipc64_perm(&v.shm_perm, &in->shm_perm); +#ifdef CONFIG_COMPAT64 + v.shm_atime = in->shm_atime; + v.shm_dtime = in->shm_dtime; + v.shm_ctime = in->shm_ctime; +#else v.shm_atime = lower_32_bits(in->shm_atime); v.shm_atime_high = upper_32_bits(in->shm_atime); v.shm_dtime = lower_32_bits(in->shm_dtime); v.shm_dtime_high = upper_32_bits(in->shm_dtime); v.shm_ctime = lower_32_bits(in->shm_ctime); v.shm_ctime_high = upper_32_bits(in->shm_ctime); +#endif v.shm_segsz = in->shm_segsz; v.shm_nattch = in->shm_nattch; v.shm_cpid = in->shm_cpid;
struct compat_shmid64_ds: Don't split time attributes with two ulongs, use single longs. struct compat_ipc64_perm: In arm64 'mode' is an unsigned int instead of a short. No need for padding in that case.
Signed-off-by: Teo Couprie Diaz teo.coupriediaz@arm.com --- arch/arm64/include/asm/compat.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index 962f954fd194..e4073c91ea73 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -127,8 +127,12 @@ struct compat_ipc64_perm { __compat_gid32_t gid; __compat_uid32_t cuid; __compat_gid32_t cgid; +#ifdef CONFIG_COMPAT64 + unsigned int mode; +#else unsigned short mode; unsigned short __pad1; +#endif unsigned short seq; unsigned short __pad2; compat_ulong_t unused1; @@ -166,12 +170,18 @@ struct compat_msqid64_ds { struct compat_shmid64_ds { struct compat_ipc64_perm shm_perm; compat_size_t shm_segsz; +#ifdef CONFIG_COMPAT64 + compat_long_t shm_atime; + compat_long_t shm_dtime; + compat_long_t shm_ctime; +#else compat_ulong_t shm_atime; compat_ulong_t shm_atime_high; compat_ulong_t shm_dtime; compat_ulong_t shm_dtime_high; compat_ulong_t shm_ctime; compat_ulong_t shm_ctime_high; +#endif compat_pid_t shm_cpid; compat_pid_t shm_lpid; compat_ulong_t shm_nattch;
AArch32 uses a 16k alignment for shmat rather than the page size. Only use the legacy alignment when in compat32 on arm64.
Signed-off-by: Teo Couprie Diaz teo.coupriediaz@arm.com --- arch/arm64/include/asm/shmparam.h | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/arch/arm64/include/asm/shmparam.h b/arch/arm64/include/asm/shmparam.h index f920e22ec677..37f84b356f6d 100644 --- a/arch/arm64/include/asm/shmparam.h +++ b/arch/arm64/include/asm/shmparam.h @@ -5,12 +5,14 @@ #ifndef __ASM_SHMPARAM_H #define __ASM_SHMPARAM_H
+#ifdef CONFIG_COMPAT32 /* * For IPC syscalls from compat tasks, we need to use the legacy 16k * alignment value. Since we don't have aliasing D-caches, the rest of * the time we can safely use PAGE_SIZE. */ #define COMPAT_SHMLBA (4 * PAGE_SIZE) +#endif
#include <asm-generic/shmparam.h>
ipc_parse_version is not used in 64-bit, only when in 32-bit compat. Change ARCH_WANT_COMPAT_IPC_PARSE_VERSION to be selected in COMPAT32 only.
Signed-off-by: Teo Couprie Diaz teo.coupriediaz@arm.com --- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index d402721ccad0..c784d8664a40 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -92,7 +92,7 @@ config ARM64 select ARCH_SUPPORTS_ATOMIC_RMW select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_NUMA_BALANCING - select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT + select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT32 select ARCH_WANT_DEFAULT_BPF_JIT select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT select ARCH_WANT_FRAME_POINTERS
On 28/09/2022 13:17, Teo Couprie Diaz wrote:
This patch series fixes shmctl, shmat and structs they use for compat64. Update the arm64/Kconfig as we only use ipc_parse_version in compat32.
You can also find the patches at https://git.morello-project.org/Teo-CD/linux/-/tree/review/teo/shm-compat
v1: Initial shmctl patch v2: Split patch between generic and arm64, shmat fix and Kconfig update v3: Small nits
Teo Couprie Diaz (4): ipc/shm: Adapt shmctl for compat64 arm64: compat: Fix structs for compat64 arm64: compat: Only use legacy SHMLBA in compat32 arm64: Kconfig: ipc_parse_version depends on COMPAT32
Applied on next, thanks!
Kevin
arch/arm64/Kconfig | 2 +- arch/arm64/include/asm/compat.h | 10 ++++++++++ arch/arm64/include/asm/shmparam.h | 2 ++ ipc/shm.c | 8 ++++++++ 4 files changed, 21 insertions(+), 1 deletion(-)
linux-morello@op-lists.linaro.org