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].
Thanks, Amit
[1]: https://git.morello-project.org/amitdaniel/linux.git review/semctl_msgctl_v1
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..e91a1390dff3 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); }
On 28/09/2022 16:26, Amit Daniel Kachhap wrote:
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..e91a1390dff3 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;
Nit: to be consistent with patch 2 and Téo's "ipc/shm: Adapt shmctl for compat64", let's have just a space before "=". I don't have a preference either way, but changing one patch is easier than two :)
Kevin
+#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 mask out the 32-bit upper half time fields.
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..6bf15be21e6a 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 /* !CONFIG_COMPAT64 */ 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 28/09/2022 16:26, Amit Daniel Kachhap wrote:
semctl/msgctl syscall in compat64 mode use 64-bit long time field similar to native struct semid64_ds/msqid64_ds so mask out the 32-bit upper half time fields.
"mask out" can be confusing, maybe something like "amend the structs' layout 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..6bf15be21e6a 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 /* !CONFIG_COMPAT64 */
Nit: there's no comment after the #else on the two other structs we fixed, probably not necessary to have any.
Kevin
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;
Hi Amit,
On 9/28/22 15:26, 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].
Thanks, Amit
[1]: https://git.morello-project.org/amitdaniel/linux.git review/semctl_msgctl_v1
The series looks good to me ! Téo
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(-)
On 28/09/2022 16:26, 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].
Thanks, Amit
[1]: https://git.morello-project.org/amitdaniel/linux.git review/semctl_msgctl_v1
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
Just have a couple of nits, otherwise this looks good. I'll merge the v2 together with Téo's series.
Kevin
arch/arm64/include/asm/compat.h | 11 +++++++++++ ipc/msg.c | 6 ++++++ ipc/sem.c | 9 +++++++-- 3 files changed, 24 insertions(+), 2 deletions(-)
On 10/11/22 15:22, Kevin Brodsky wrote:
On 28/09/2022 16:26, 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].
Thanks, Amit
review/semctl_msgctl_v1
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
Just have a couple of nits, otherwise this looks good. I'll merge the v2 together with Téo's series.
Thanks for the review. Just sent the v2 along with the suggestions.
Thanks, Amit
Kevin
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