Hi,
This series adapts semctl/msgctl for compat64. This depends on Teo's work on shmctl.
These patches can also be found on this location [1].
Changes in v2: * Addressed few minor comments from Kevin.
Thanks, Amit
[1]: https://git.morello-project.org/amitdaniel/linux.git review/semctl_msgctl_v2
Amit Daniel Kachhap (3): ipc/sem: Adapt semctl syscall for compat64 ipc/msg: Adapt msgctl syscall for compat64 arm64: compat: Fix structs compat_semid64_ds/compat_msqid64_ds
arch/arm64/include/asm/compat.h | 11 +++++++++++ ipc/msg.c | 6 ++++++ ipc/sem.c | 9 +++++++-- 3 files changed, 24 insertions(+), 2 deletions(-)
semctl syscall in compat64 mode need to use the arg argument as 64-bit as it may contain user buffer pointer so use type compat_ulong_t instead of type int.
Also 64 bit architectures use a 64-bit long time field similar to the native struct semid64_ds so do not copy the 32-bit lower and upper half time.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com --- ipc/sem.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/ipc/sem.c b/ipc/sem.c index 9f10259ce08b..3bf64f2a26f5 100644 --- a/ipc/sem.c +++ b/ipc/sem.c @@ -1756,10 +1756,15 @@ static int copy_compat_semid_to_user(void __user *buf, struct semid64_ds *in, struct compat_semid64_ds v; memset(&v, 0, sizeof(v)); to_compat_ipc64_perm(&v.sem_perm, &in->sem_perm); +#ifdef CONFIG_COMPAT64 + v.sem_otime = in->sem_otime; + v.sem_ctime = in->sem_ctime; +#else v.sem_otime = lower_32_bits(in->sem_otime); v.sem_otime_high = upper_32_bits(in->sem_otime); v.sem_ctime = lower_32_bits(in->sem_ctime); v.sem_ctime_high = upper_32_bits(in->sem_ctime); +#endif v.sem_nsems = in->sem_nsems; return copy_to_user(buf, &v, sizeof(v)); } else { @@ -1773,7 +1778,7 @@ static int copy_compat_semid_to_user(void __user *buf, struct semid64_ds *in, } }
-static long compat_ksys_semctl(int semid, int semnum, int cmd, int arg, int version) +static long compat_ksys_semctl(int semid, int semnum, int cmd, compat_ulong_t arg, int version) { void __user *p = compat_ptr(arg); struct ipc_namespace *ns; @@ -1818,7 +1823,7 @@ static long compat_ksys_semctl(int semid, int semnum, int cmd, int arg, int vers } }
-COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, int, arg) +COMPAT_SYSCALL_DEFINE4(semctl, int, semid, int, semnum, int, cmd, compat_ulong_t, arg) { return compat_ksys_semctl(semid, semnum, cmd, arg, IPC_64); }
msgctl syscall in compat64 mode use 64-bit long time field similar to the native struct semid64_ds so do not copy the 32-bit lower/upper half time.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com --- ipc/msg.c | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/ipc/msg.c b/ipc/msg.c index a0d05775af2c..2749c182e5ba 100644 --- a/ipc/msg.c +++ b/ipc/msg.c @@ -695,12 +695,18 @@ static int copy_compat_msqid_to_user(void __user *buf, struct msqid64_ds *in, struct compat_msqid64_ds v; memset(&v, 0, sizeof(v)); to_compat_ipc64_perm(&v.msg_perm, &in->msg_perm); +#ifdef CONFIG_COMPAT64 + v.msg_stime = in->msg_stime; + v.msg_rtime = in->msg_rtime; + v.msg_ctime = in->msg_ctime; +#else v.msg_stime = lower_32_bits(in->msg_stime); v.msg_stime_high = upper_32_bits(in->msg_stime); v.msg_rtime = lower_32_bits(in->msg_rtime); v.msg_rtime_high = upper_32_bits(in->msg_rtime); v.msg_ctime = lower_32_bits(in->msg_ctime); v.msg_ctime_high = upper_32_bits(in->msg_ctime); +#endif v.msg_cbytes = in->msg_cbytes; v.msg_qnum = in->msg_qnum; v.msg_qbytes = in->msg_qbytes;
semctl/msgctl syscall in compat64 mode use 64-bit long time field similar to native struct semid64_ds/msqid64_ds so amend the structs accordingly in compat64.
Signed-off-by: Amit Daniel Kachhap amit.kachhap@arm.com --- arch/arm64/include/asm/compat.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h index e4073c91ea73..9c6112ae942b 100644 --- a/arch/arm64/include/asm/compat.h +++ b/arch/arm64/include/asm/compat.h @@ -141,10 +141,15 @@ struct compat_ipc64_perm {
struct compat_semid64_ds { struct compat_ipc64_perm sem_perm; +#ifdef CONFIG_COMPAT64 + compat_long_t sem_otime; + compat_long_t sem_ctime; +#else compat_ulong_t sem_otime; compat_ulong_t sem_otime_high; compat_ulong_t sem_ctime; compat_ulong_t sem_ctime_high; +#endif compat_ulong_t sem_nsems; compat_ulong_t __unused3; compat_ulong_t __unused4; @@ -152,12 +157,18 @@ struct compat_semid64_ds {
struct compat_msqid64_ds { struct compat_ipc64_perm msg_perm; +#ifdef CONFIG_COMPAT64 + compat_long_t msg_stime; + compat_long_t msg_rtime; + compat_long_t msg_ctime; +#else compat_ulong_t msg_stime; compat_ulong_t msg_stime_high; compat_ulong_t msg_rtime; compat_ulong_t msg_rtime_high; compat_ulong_t msg_ctime; compat_ulong_t msg_ctime_high; +#endif compat_ulong_t msg_cbytes; compat_ulong_t msg_qnum; compat_ulong_t msg_qbytes;
On 12/10/2022 06:54, Amit Daniel Kachhap wrote:
Hi,
This series adapts semctl/msgctl for compat64. This depends on Teo's work on shmctl.
These patches can also be found on this location [1].
Changes in v2:
- Addressed few minor comments from Kevin.
Thanks looks good, now applied on next.
Kevin
Thanks, Amit
[1]: https://git.morello-project.org/amitdaniel/linux.git review/semctl_msgctl_v2
Amit Daniel Kachhap (3): ipc/sem: Adapt semctl syscall for compat64 ipc/msg: Adapt msgctl syscall for compat64 arm64: compat: Fix structs compat_semid64_ds/compat_msqid64_ds
arch/arm64/include/asm/compat.h | 11 +++++++++++ ipc/msg.c | 6 ++++++ ipc/sem.c | 9 +++++++-- 3 files changed, 24 insertions(+), 2 deletions(-)
linux-morello@op-lists.linaro.org