diff mbox series

[net,v2] ptp: Properly handle compat ioctls

Message ID 20250125-posix-clock-compat_ioctl-v2-1-11c865c500eb@weissschuh.net (mailing list archive)
State New
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] ptp: Properly handle compat ioctls | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch warning WARNING: line length of 83 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-01-25--12-00 (tests: 885)

Commit Message

Thomas Weißschuh Jan. 25, 2025, 9:28 a.m. UTC
Pointer arguments passed to ioctls need to pass through compat_ptr() to
work correctly on s390; as explained in Documentation/driver-api/ioctl.rst.
Detect compat mode at runtime and call compat_ptr() for those commands
which do take pointer arguments.

Suggested-by: Arnd Bergmann <arnd@arndb.de>
Link: https://lore.kernel.org/lkml/1ba5d3a4-7931-455b-a3ce-85a968a7cb10@app.fastmail.com/
Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Changes in v2:
- Use in_compat_syscall()
- Discard changes outside drivers/ptp/, they are independent,
  unsuited for the net tree and will be submitted on their own
- Link to v1: https://lore.kernel.org/r/20250121-posix-clock-compat_ioctl-v1-1-c70d5433a825@weissschuh.net
---
 drivers/ptp/ptp_chardev.c | 4 ++++
 1 file changed, 4 insertions(+)


---
base-commit: b46c89c08f4146e7987fc355941a93b12e2c03ef
change-id: 20250103-posix-clock-compat_ioctl-96fbac549146

Best regards,

Comments

Cyrill Gorcunov Jan. 25, 2025, 10:14 a.m. UTC | #1
On Sat, Jan 25, 2025 at 10:28:38AM +0100, Thomas Weißschuh wrote:
> Pointer arguments passed to ioctls need to pass through compat_ptr() to
> work correctly on s390; as explained in Documentation/driver-api/ioctl.rst.
> Detect compat mode at runtime and call compat_ptr() for those commands
> which do take pointer arguments.
> 
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Link: https://lore.kernel.org/lkml/1ba5d3a4-7931-455b-a3ce-85a968a7cb10@app.fastmail.com/
> Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Looks OK for me, thanks Thomas!
Reviewed-by: Cyrill Gorcunov <gorcunov@gmail.com>
Arnd Bergmann Jan. 25, 2025, 5:04 p.m. UTC | #2
On Sat, Jan 25, 2025, at 10:28, Thomas Weißschuh wrote:
> Pointer arguments passed to ioctls need to pass through compat_ptr() to
> work correctly on s390; as explained in Documentation/driver-api/ioctl.rst.
> Detect compat mode at runtime and call compat_ptr() for those commands
> which do take pointer arguments.
>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Link: 
> https://lore.kernel.org/lkml/1ba5d3a4-7931-455b-a3ce-85a968a7cb10@app.fastmail.com/
> Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp 
> clocks.")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Richard Cochran Jan. 25, 2025, 8:21 p.m. UTC | #3
On Sat, Jan 25, 2025 at 10:28:38AM +0100, Thomas Weißschuh wrote:
> Pointer arguments passed to ioctls need to pass through compat_ptr() to
> work correctly on s390; as explained in Documentation/driver-api/ioctl.rst.
> Detect compat mode at runtime and call compat_ptr() for those commands
> which do take pointer arguments.
> 
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Link: https://lore.kernel.org/lkml/1ba5d3a4-7931-455b-a3ce-85a968a7cb10@app.fastmail.com/
> Fixes: d94ba80ebbea ("ptp: Added a brand new class driver for ptp clocks.")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>

Acked-by: Richard Cochran <richardcochran@gmail.com>
diff mbox series

Patch

diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c
index ea96a14d72d141a4b255563b66bac8ed568b45e9..bf6468c56419c56c0737515d614b2267264816c2 100644
--- a/drivers/ptp/ptp_chardev.c
+++ b/drivers/ptp/ptp_chardev.c
@@ -4,6 +4,7 @@ 
  *
  * Copyright (C) 2010 OMICRON electronics GmbH
  */
+#include <linux/compat.h>
 #include <linux/module.h>
 #include <linux/posix-clock.h>
 #include <linux/poll.h>
@@ -176,6 +177,9 @@  long ptp_ioctl(struct posix_clock_context *pccontext, unsigned int cmd,
 	struct timespec64 ts;
 	int enable, err = 0;
 
+	if (in_compat_syscall() && cmd != PTP_ENABLE_PPS && cmd != PTP_ENABLE_PPS2)
+		arg = (unsigned long)compat_ptr(arg);
+
 	tsevq = pccontext->private_clkdata;
 
 	switch (cmd) {