Davidlohr Bueso a70510
From 1ce53e2c2ac069e7b3c400a427002a70deb4a916 Mon Sep 17 00:00:00 2001
Davidlohr Bueso a70510
From: Alejandro Colomar <alx.manpages@gmail.com>
Davidlohr Bueso a70510
Date: Sat, 28 Nov 2020 13:39:46 +0100
Davidlohr Bueso a70510
Subject: [PATCH] futex: Change utime parameter to be 'const ... *'
Davidlohr Bueso a70510
Git-commit: 1ce53e2c2ac069e7b3c400a427002a70deb4a916
Davidlohr Bueso a70510
Patch-mainline: v5.12-rc1
Davidlohr Bueso a70510
References: git-fixes
Davidlohr Bueso a70510
Davidlohr Bueso a70510
futex(2) says that 'utime' is a pointer to 'const'.  The implementation
Davidlohr Bueso a70510
doesn't use 'const'; however, it _never_ modifies the contents of utime.
Davidlohr Bueso a70510
Davidlohr Bueso a70510
- futex() either uses 'utime' as a pointer to struct or as a 'u32'.
Davidlohr Bueso a70510
Davidlohr Bueso a70510
- In case it's used as a 'u32', it makes a copy of it, and of course it is
Davidlohr Bueso a70510
  not dereferenced.
Davidlohr Bueso a70510
Davidlohr Bueso a70510
- In case it's used as a 'struct __kernel_timespec __user *', the pointer
Davidlohr Bueso a70510
  is not dereferenced inside the futex() definition, and it is only passed
Davidlohr Bueso a70510
  to a function: get_timespec64(), which accepts a 'const struct
Davidlohr Bueso a70510
  __kernel_timespec __user *'.
Davidlohr Bueso a70510
Davidlohr Bueso a70510
[ tglx: Make the same change to the compat syscall and fixup the prototypes. ]
Davidlohr Bueso a70510
Davidlohr Bueso a70510
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Davidlohr Bueso a70510
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Davidlohr Bueso a70510
Link: https://lore.kernel.org/r/20201128123945.4592-1-alx.manpages@gmail.com
Davidlohr Bueso a70510
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
Davidlohr Bueso a70510
Davidlohr Bueso a70510
---
Davidlohr Bueso a70510
 include/linux/syscalls.h | 8 ++++----
Davidlohr Bueso a70510
 kernel/futex.c           | 6 +++---
Davidlohr Bueso a70510
 2 files changed, 7 insertions(+), 7 deletions(-)
Davidlohr Bueso a70510
Davidlohr Bueso a70510
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
Davidlohr Bueso a70510
index f3929aff39cf..5cb74edd9a4f 100644
Davidlohr Bueso a70510
--- a/include/linux/syscalls.h
Davidlohr Bueso a70510
+++ b/include/linux/syscalls.h
Davidlohr Bueso a70510
@@ -583,11 +583,11 @@ asmlinkage long sys_unshare(unsigned long unshare_flags);
Davidlohr Bueso a70510
 
Davidlohr Bueso a70510
 /* kernel/futex.c */
Davidlohr Bueso a70510
 asmlinkage long sys_futex(u32 __user *uaddr, int op, u32 val,
Davidlohr Bueso a70510
-			struct __kernel_timespec __user *utime, u32 __user *uaddr2,
Davidlohr Bueso a70510
-			u32 val3);
Davidlohr Bueso a70510
+			  const struct __kernel_timespec __user *utime,
Davidlohr Bueso a70510
+			  u32 __user *uaddr2, u32 val3);
Davidlohr Bueso a70510
 asmlinkage long sys_futex_time32(u32 __user *uaddr, int op, u32 val,
Davidlohr Bueso a70510
-			struct old_timespec32 __user *utime, u32 __user *uaddr2,
Davidlohr Bueso a70510
-			u32 val3);
Davidlohr Bueso a70510
+				 const struct old_timespec32 __user *utime,
Davidlohr Bueso a70510
+				 u32 __user *uaddr2, u32 val3);
Davidlohr Bueso a70510
 asmlinkage long sys_get_robust_list(int pid,
Davidlohr Bueso a70510
 				    struct robust_list_head __user * __user *head_ptr,
Davidlohr Bueso a70510
 				    size_t __user *len_ptr);
Davidlohr Bueso a70510
diff --git a/kernel/futex.c b/kernel/futex.c
Davidlohr Bueso a70510
index c47d1015d759..d0775aab8da9 100644
Davidlohr Bueso a70510
--- a/kernel/futex.c
Davidlohr Bueso a70510
+++ b/kernel/futex.c
Davidlohr Bueso a70510
@@ -3790,8 +3790,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
Davidlohr Bueso a70510
 
Davidlohr Bueso a70510
 
Davidlohr Bueso a70510
 SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
Davidlohr Bueso a70510
-		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
Davidlohr Bueso a70510
-		u32, val3)
Davidlohr Bueso a70510
+		const struct __kernel_timespec __user *, utime,
Davidlohr Bueso a70510
+		u32 __user *, uaddr2, u32, val3)
Davidlohr Bueso a70510
 {
Davidlohr Bueso a70510
 	struct timespec64 ts;
Davidlohr Bueso a70510
 	ktime_t t, *tp = NULL;
Davidlohr Bueso a70510
@@ -3986,7 +3986,7 @@ COMPAT_SYSCALL_DEFINE3(get_robust_list, int, pid,
Davidlohr Bueso a70510
 
Davidlohr Bueso a70510
 #ifdef CONFIG_COMPAT_32BIT_TIME
Davidlohr Bueso a70510
 SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val,
Davidlohr Bueso a70510
-		struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
Davidlohr Bueso a70510
+		const struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
Davidlohr Bueso a70510
 		u32, val3)
Davidlohr Bueso a70510
 {
Davidlohr Bueso a70510
 	struct timespec64 ts;
Davidlohr Bueso a70510
-- 
Davidlohr Bueso a70510
2.26.2
Davidlohr Bueso a70510