linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] futex: Change 'utime' parameter to be 'const ... *'
@ 2020-11-28 12:39 Alejandro Colomar
  2020-12-10 17:36 ` Alejandro Colomar (man-pages)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Alejandro Colomar @ 2020-11-28 12:39 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: Alejandro Colomar, Peter Zijlstra, Darren Hart, linux-kernel, linux-man

futex(2) says that 'utime' is a pointer to 'const'.
The implementation doesn't use 'const';
however, it _never_ modifies the contents of utime.

- futex() either uses 'utime' as a pointer to struct or as a 'u32'.

- In case it's used as a 'u32', it makes a copy of it,
  and of course it is not dereferenced.

- In case it's used as a 'struct __kernel_timespec __user *',
  the pointer is not dereferenced inside the futex() definition,
  and it is only passed to a function: get_timespec64(),
  which accepts a 'const struct __kernel_timespec __user *'.

context:
........

[[
FUTEX(2)               Linux Programmer's Manual              FUTEX(2)

NAME
       futex - fast user-space locking

SYNOPSIS
       #include <linux/futex.h>
       #include <stdint.h>
       #include <sys/time.h>

       long futex(uint32_t *uaddr, int futex_op, uint32_t val,
                 const struct timespec *timeout,   /* or: uint32_t val2 */
                 uint32_t *uaddr2, uint32_t val3);

       Note:  There  is  no  glibc  wrapper  for this system call; see
       NOTES.
]]

$ sed -n '/SYSCALL_DEFINE.(futex\>/,/^}/p' linux/kernel/futex.c
SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
		u32, val3)
{
	struct timespec64 ts;
	ktime_t t, *tp = NULL;
	u32 val2 = 0;
	int cmd = op & FUTEX_CMD_MASK;

	if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
		      cmd == FUTEX_WAIT_BITSET ||
		      cmd == FUTEX_WAIT_REQUEUE_PI)) {
		if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG))))
			return -EFAULT;
		if (get_timespec64(&ts, utime))
			return -EFAULT;
		if (!timespec64_valid(&ts))
			return -EINVAL;

		t = timespec64_to_ktime(ts);
		if (cmd == FUTEX_WAIT)
			t = ktime_add_safe(ktime_get(), t);
		else if (!(op & FUTEX_CLOCK_REALTIME))
			t = timens_ktime_to_host(CLOCK_MONOTONIC, t);
		tp = &t;
	}
	/*
	 * requeue parameter in 'utime' if cmd == FUTEX_*_REQUEUE_*.
	 * number of waiters to wake in 'utime' if cmd == FUTEX_WAKE_OP.
	 */
	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
	    cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
		val2 = (u32) (unsigned long) utime;

	return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
}

$ sed -n '/get_timespec64(/,/;/p' linux/include/linux/time.h
int get_timespec64(struct timespec64 *ts,
		const struct __kernel_timespec __user *uts);

...

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---

Hello Thomas & Ingo,

I'm sorry I couldn't test the change in my computers,
as there is a bug since Linux 5.7 where I can't boot
(https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=974166).

Alex

 kernel/futex.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 00259c7e288e..28577c7d2805 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3792,8 +3792,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
 
 
 SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
-		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
-		u32, val3)
+		const struct __kernel_timespec __user *, utime,
+		u32 __user *, uaddr2, u32, val3)
 {
 	struct timespec64 ts;
 	ktime_t t, *tp = NULL;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] futex: Change 'utime' parameter to be 'const ... *'
  2020-11-28 12:39 [PATCH] futex: Change 'utime' parameter to be 'const ... *' Alejandro Colomar
@ 2020-12-10 17:36 ` Alejandro Colomar (man-pages)
  2021-01-17 16:32   ` Ping: " Alejandro Colomar (man-pages)
  2021-01-27 19:31 ` [tip: locking/core] futex: Change utime " tip-bot2 for Alejandro Colomar
  2021-01-28 12:21 ` tip-bot2 for Alejandro Colomar
  2 siblings, 1 reply; 5+ messages in thread
From: Alejandro Colomar (man-pages) @ 2020-12-10 17:36 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: Peter Zijlstra, Darren Hart, linux-kernel, linux-man, linux-api

Hi Thomas & Ingo,

I tested the changes. Everything's OK.

Cheers,

Alex

$ uname -a
Linux debian 5.10.0-rc7+alx3+ #4 SMP Thu Dec 10 18:05:03 CET 2020 x86_64
GNU/Linux

.../linux/tools/testing/selftests/futex$ sudo ./run.sh
[sudo] password for user:

TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=0 owner=0 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=0 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=1 owner=0 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=1 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=0 owner=1 timeout=0ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=1 owner=0 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=1 owner=0 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=0 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=0 owner=0 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=0 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=0 owner=0 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=1 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=5000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=0 owner=1 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=500000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=1 locked=1 owner=0 timeout=2000000000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_requeue_pi: Test requeue functionality
# 	Arguments: broadcast=0 locked=1 owner=0 timeout=2000000000ns
ok 1 futex-requeue-pi
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

TAP version 13
1..1
# futex_requeue_pi_mismatched_ops: Detect mismatched requeue_pi operations
ok 1 futex-requeue-pi-mismatched-ops
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

TAP version 13
1..1
# futex_requeue_pi_signal_restart: Test signal handling during requeue_pi
# 	Arguments: <none>
ok 1 futex-requeue-pi-signal-restart
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

TAP version 13
1..1
# futex_wait_timeout: Block on a futex and wait for timeout
# 	Arguments: timeout=100000ns
ok 1 futex-wait-timeout
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

TAP version 13
1..1
# futex_wait_wouldblock: Test the unexpected futex value in FUTEX_WAIT
ok 1 futex-wait-wouldblock
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

TAP version 13
1..1
# futex_wait_uninitialized_heap: Test the uninitialized futex value in
FUTEX_WAIT
ok 1 futex-wait-uninitialized-heap
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
TAP version 13
1..1
# futex_wait_private_mapped_file: Test the futex value of private file
mappings in FUTEX_WAIT
ok 1 futex-wait-private-mapped-file
# Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0


On 11/28/20 1:39 PM, Alejandro Colomar wrote:
> futex(2) says that 'utime' is a pointer to 'const'.
> The implementation doesn't use 'const';
> however, it _never_ modifies the contents of utime.
> 
> - futex() either uses 'utime' as a pointer to struct or as a 'u32'.
> 
> - In case it's used as a 'u32', it makes a copy of it,
>   and of course it is not dereferenced.
> 
> - In case it's used as a 'struct __kernel_timespec __user *',
>   the pointer is not dereferenced inside the futex() definition,
>   and it is only passed to a function: get_timespec64(),
>   which accepts a 'const struct __kernel_timespec __user *'.
> 
> context:
> ........
> 
> [[
> FUTEX(2)               Linux Programmer's Manual              FUTEX(2)
> 
> NAME
>        futex - fast user-space locking
> 
> SYNOPSIS
>        #include <linux/futex.h>
>        #include <stdint.h>
>        #include <sys/time.h>
> 
>        long futex(uint32_t *uaddr, int futex_op, uint32_t val,
>                  const struct timespec *timeout,   /* or: uint32_t val2 */
>                  uint32_t *uaddr2, uint32_t val3);
> 
>        Note:  There  is  no  glibc  wrapper  for this system call; see
>        NOTES.
> ]]
> 
> $ sed -n '/SYSCALL_DEFINE.(futex\>/,/^}/p' linux/kernel/futex.c
> SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
> 		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
> 		u32, val3)
> {
> 	struct timespec64 ts;
> 	ktime_t t, *tp = NULL;
> 	u32 val2 = 0;
> 	int cmd = op & FUTEX_CMD_MASK;
> 
> 	if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
> 		      cmd == FUTEX_WAIT_BITSET ||
> 		      cmd == FUTEX_WAIT_REQUEUE_PI)) {
> 		if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG))))
> 			return -EFAULT;
> 		if (get_timespec64(&ts, utime))
> 			return -EFAULT;
> 		if (!timespec64_valid(&ts))
> 			return -EINVAL;
> 
> 		t = timespec64_to_ktime(ts);
> 		if (cmd == FUTEX_WAIT)
> 			t = ktime_add_safe(ktime_get(), t);
> 		else if (!(op & FUTEX_CLOCK_REALTIME))
> 			t = timens_ktime_to_host(CLOCK_MONOTONIC, t);
> 		tp = &t;
> 	}
> 	/*
> 	 * requeue parameter in 'utime' if cmd == FUTEX_*_REQUEUE_*.
> 	 * number of waiters to wake in 'utime' if cmd == FUTEX_WAKE_OP.
> 	 */
> 	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
> 	    cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
> 		val2 = (u32) (unsigned long) utime;
> 
> 	return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
> }
> 
> $ sed -n '/get_timespec64(/,/;/p' linux/include/linux/time.h
> int get_timespec64(struct timespec64 *ts,
> 		const struct __kernel_timespec __user *uts);
> 
> ...
> 
> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
> ---
> 
> Hello Thomas & Ingo,
> 
> I'm sorry I couldn't test the change in my computers,
> as there is a bug since Linux 5.7 where I can't boot
> (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=974166).
> 
> Alex
> 
>  kernel/futex.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/futex.c b/kernel/futex.c
> index 00259c7e288e..28577c7d2805 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -3792,8 +3792,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
>  
>  
>  SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
> -		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
> -		u32, val3)
> +		const struct __kernel_timespec __user *, utime,
> +		u32 __user *, uaddr2, u32, val3)
>  {
>  	struct timespec64 ts;
>  	ktime_t t, *tp = NULL;
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Ping: [PATCH] futex: Change 'utime' parameter to be 'const ... *'
  2020-12-10 17:36 ` Alejandro Colomar (man-pages)
@ 2021-01-17 16:32   ` Alejandro Colomar (man-pages)
  0 siblings, 0 replies; 5+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-01-17 16:32 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar
  Cc: Peter Zijlstra, Darren Hart, linux-kernel, linux-man, linux-api

Ping!

On 12/10/20 6:36 PM, Alejandro Colomar (man-pages) wrote:
> Hi Thomas & Ingo,
> 
> I tested the changes. Everything's OK.
> 
> Cheers,
> 
> Alex
> 
> $ uname -a
> Linux debian 5.10.0-rc7+alx3+ #4 SMP Thu Dec 10 18:05:03 CET 2020 x86_64
> GNU/Linux
> 
> .../linux/tools/testing/selftests/futex$ sudo ./run.sh
> [sudo] password for user:
> 
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=0 owner=0 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=0 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=1 owner=0 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=1 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=0 owner=1 timeout=0ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=1 owner=0 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=1 owner=0 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=0 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=0 owner=0 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=0 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=0 owner=0 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=1 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=5000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=0 owner=1 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=500000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=1 locked=1 owner=0 timeout=2000000000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_requeue_pi: Test requeue functionality
> # 	Arguments: broadcast=0 locked=1 owner=0 timeout=2000000000ns
> ok 1 futex-requeue-pi
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> TAP version 13
> 1..1
> # futex_requeue_pi_mismatched_ops: Detect mismatched requeue_pi operations
> ok 1 futex-requeue-pi-mismatched-ops
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> TAP version 13
> 1..1
> # futex_requeue_pi_signal_restart: Test signal handling during requeue_pi
> # 	Arguments: <none>
> ok 1 futex-requeue-pi-signal-restart
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> TAP version 13
> 1..1
> # futex_wait_timeout: Block on a futex and wait for timeout
> # 	Arguments: timeout=100000ns
> ok 1 futex-wait-timeout
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> TAP version 13
> 1..1
> # futex_wait_wouldblock: Test the unexpected futex value in FUTEX_WAIT
> ok 1 futex-wait-wouldblock
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> TAP version 13
> 1..1
> # futex_wait_uninitialized_heap: Test the uninitialized futex value in
> FUTEX_WAIT
> ok 1 futex-wait-uninitialized-heap
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> TAP version 13
> 1..1
> # futex_wait_private_mapped_file: Test the futex value of private file
> mappings in FUTEX_WAIT
> ok 1 futex-wait-private-mapped-file
> # Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> 
> On 11/28/20 1:39 PM, Alejandro Colomar wrote:
>> futex(2) says that 'utime' is a pointer to 'const'.
>> The implementation doesn't use 'const';
>> however, it _never_ modifies the contents of utime.
>>
>> - futex() either uses 'utime' as a pointer to struct or as a 'u32'.
>>
>> - In case it's used as a 'u32', it makes a copy of it,
>>   and of course it is not dereferenced.
>>
>> - In case it's used as a 'struct __kernel_timespec __user *',
>>   the pointer is not dereferenced inside the futex() definition,
>>   and it is only passed to a function: get_timespec64(),
>>   which accepts a 'const struct __kernel_timespec __user *'.
>>
>> context:
>> ........
>>
>> [[
>> FUTEX(2)               Linux Programmer's Manual              FUTEX(2)
>>
>> NAME
>>        futex - fast user-space locking
>>
>> SYNOPSIS
>>        #include <linux/futex.h>
>>        #include <stdint.h>
>>        #include <sys/time.h>
>>
>>        long futex(uint32_t *uaddr, int futex_op, uint32_t val,
>>                  const struct timespec *timeout,   /* or: uint32_t val2 */
>>                  uint32_t *uaddr2, uint32_t val3);
>>
>>        Note:  There  is  no  glibc  wrapper  for this system call; see
>>        NOTES.
>> ]]
>>
>> $ sed -n '/SYSCALL_DEFINE.(futex\>/,/^}/p' linux/kernel/futex.c
>> SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
>> 		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
>> 		u32, val3)
>> {
>> 	struct timespec64 ts;
>> 	ktime_t t, *tp = NULL;
>> 	u32 val2 = 0;
>> 	int cmd = op & FUTEX_CMD_MASK;
>>
>> 	if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
>> 		      cmd == FUTEX_WAIT_BITSET ||
>> 		      cmd == FUTEX_WAIT_REQUEUE_PI)) {
>> 		if (unlikely(should_fail_futex(!(op & FUTEX_PRIVATE_FLAG))))
>> 			return -EFAULT;
>> 		if (get_timespec64(&ts, utime))
>> 			return -EFAULT;
>> 		if (!timespec64_valid(&ts))
>> 			return -EINVAL;
>>
>> 		t = timespec64_to_ktime(ts);
>> 		if (cmd == FUTEX_WAIT)
>> 			t = ktime_add_safe(ktime_get(), t);
>> 		else if (!(op & FUTEX_CLOCK_REALTIME))
>> 			t = timens_ktime_to_host(CLOCK_MONOTONIC, t);
>> 		tp = &t;
>> 	}
>> 	/*
>> 	 * requeue parameter in 'utime' if cmd == FUTEX_*_REQUEUE_*.
>> 	 * number of waiters to wake in 'utime' if cmd == FUTEX_WAKE_OP.
>> 	 */
>> 	if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
>> 	    cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
>> 		val2 = (u32) (unsigned long) utime;
>>
>> 	return do_futex(uaddr, op, val, tp, uaddr2, val2, val3);
>> }
>>
>> $ sed -n '/get_timespec64(/,/;/p' linux/include/linux/time.h
>> int get_timespec64(struct timespec64 *ts,
>> 		const struct __kernel_timespec __user *uts);
>>
>> ...
>>
>> Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
>> ---
>>
>> Hello Thomas & Ingo,
>>
>> I'm sorry I couldn't test the change in my computers,
>> as there is a bug since Linux 5.7 where I can't boot
>> (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=974166).
>>
>> Alex
>>
>>  kernel/futex.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/futex.c b/kernel/futex.c
>> index 00259c7e288e..28577c7d2805 100644
>> --- a/kernel/futex.c
>> +++ b/kernel/futex.c
>> @@ -3792,8 +3792,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
>>  
>>  
>>  SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
>> -		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
>> -		u32, val3)
>> +		const struct __kernel_timespec __user *, utime,
>> +		u32 __user *, uaddr2, u32, val3)
>>  {
>>  	struct timespec64 ts;
>>  	ktime_t t, *tp = NULL;
>>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tip: locking/core] futex: Change utime parameter to be 'const ... *'
  2020-11-28 12:39 [PATCH] futex: Change 'utime' parameter to be 'const ... *' Alejandro Colomar
  2020-12-10 17:36 ` Alejandro Colomar (man-pages)
@ 2021-01-27 19:31 ` tip-bot2 for Alejandro Colomar
  2021-01-28 12:21 ` tip-bot2 for Alejandro Colomar
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Alejandro Colomar @ 2021-01-27 19:31 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Alejandro Colomar, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     3018a08401300005536817507dd14c2a7c4ffa69
Gitweb:        https://git.kernel.org/tip/3018a08401300005536817507dd14c2a7c4ffa69
Author:        Alejandro Colomar <alx.manpages@gmail.com>
AuthorDate:    Sat, 28 Nov 2020 13:39:46 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Wed, 27 Jan 2021 12:30:02 +01:00

futex: Change utime parameter to be 'const ... *'

futex(2) says that 'utime' is a pointer to 'const'.  The implementation
doesn't use 'const'; however, it _never_ modifies the contents of utime.

- futex() either uses 'utime' as a pointer to struct or as a 'u32'.

- In case it's used as a 'u32', it makes a copy of it, and of course it is
  not dereferenced.

- In case it's used as a 'struct __kernel_timespec __user *', the pointer
  is not dereferenced inside the futex() definition, and it is only passed
  to a function: get_timespec64(), which accepts a 'const struct
  __kernel_timespec __user *'.

[ tglx: Make the same change to the compat syscall ]

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20201128123945.4592-1-alx.manpages@gmail.com
---
 kernel/futex.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index c47d101..d0775aa 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3790,8 +3790,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
 
 
 SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
-		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
-		u32, val3)
+		const struct __kernel_timespec __user *, utime,
+		u32 __user *, uaddr2, u32, val3)
 {
 	struct timespec64 ts;
 	ktime_t t, *tp = NULL;
@@ -3986,7 +3986,7 @@ err_unlock:
 
 #ifdef CONFIG_COMPAT_32BIT_TIME
 SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val,
-		struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
+		const struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
 		u32, val3)
 {
 	struct timespec64 ts;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [tip: locking/core] futex: Change utime parameter to be 'const ... *'
  2020-11-28 12:39 [PATCH] futex: Change 'utime' parameter to be 'const ... *' Alejandro Colomar
  2020-12-10 17:36 ` Alejandro Colomar (man-pages)
  2021-01-27 19:31 ` [tip: locking/core] futex: Change utime " tip-bot2 for Alejandro Colomar
@ 2021-01-28 12:21 ` tip-bot2 for Alejandro Colomar
  2 siblings, 0 replies; 5+ messages in thread
From: tip-bot2 for Alejandro Colomar @ 2021-01-28 12:21 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Alejandro Colomar, Thomas Gleixner, x86, linux-kernel

The following commit has been merged into the locking/core branch of tip:

Commit-ID:     1ce53e2c2ac069e7b3c400a427002a70deb4a916
Gitweb:        https://git.kernel.org/tip/1ce53e2c2ac069e7b3c400a427002a70deb4a916
Author:        Alejandro Colomar <alx.manpages@gmail.com>
AuthorDate:    Sat, 28 Nov 2020 13:39:46 +01:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Thu, 28 Jan 2021 13:20:18 +01:00

futex: Change utime parameter to be 'const ... *'

futex(2) says that 'utime' is a pointer to 'const'.  The implementation
doesn't use 'const'; however, it _never_ modifies the contents of utime.

- futex() either uses 'utime' as a pointer to struct or as a 'u32'.

- In case it's used as a 'u32', it makes a copy of it, and of course it is
  not dereferenced.

- In case it's used as a 'struct __kernel_timespec __user *', the pointer
  is not dereferenced inside the futex() definition, and it is only passed
  to a function: get_timespec64(), which accepts a 'const struct
  __kernel_timespec __user *'.

[ tglx: Make the same change to the compat syscall and fixup the prototypes. ]

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20201128123945.4592-1-alx.manpages@gmail.com

---
 include/linux/syscalls.h | 8 ++++----
 kernel/futex.c           | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index f3929af..5cb74ed 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -583,11 +583,11 @@ asmlinkage long sys_unshare(unsigned long unshare_flags);
 
 /* kernel/futex.c */
 asmlinkage long sys_futex(u32 __user *uaddr, int op, u32 val,
-			struct __kernel_timespec __user *utime, u32 __user *uaddr2,
-			u32 val3);
+			  const struct __kernel_timespec __user *utime,
+			  u32 __user *uaddr2, u32 val3);
 asmlinkage long sys_futex_time32(u32 __user *uaddr, int op, u32 val,
-			struct old_timespec32 __user *utime, u32 __user *uaddr2,
-			u32 val3);
+				 const struct old_timespec32 __user *utime,
+				 u32 __user *uaddr2, u32 val3);
 asmlinkage long sys_get_robust_list(int pid,
 				    struct robust_list_head __user * __user *head_ptr,
 				    size_t __user *len_ptr);
diff --git a/kernel/futex.c b/kernel/futex.c
index c47d101..d0775aa 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -3790,8 +3790,8 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
 
 
 SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
-		struct __kernel_timespec __user *, utime, u32 __user *, uaddr2,
-		u32, val3)
+		const struct __kernel_timespec __user *, utime,
+		u32 __user *, uaddr2, u32, val3)
 {
 	struct timespec64 ts;
 	ktime_t t, *tp = NULL;
@@ -3986,7 +3986,7 @@ err_unlock:
 
 #ifdef CONFIG_COMPAT_32BIT_TIME
 SYSCALL_DEFINE6(futex_time32, u32 __user *, uaddr, int, op, u32, val,
-		struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
+		const struct old_timespec32 __user *, utime, u32 __user *, uaddr2,
 		u32, val3)
 {
 	struct timespec64 ts;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-01-28 12:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-28 12:39 [PATCH] futex: Change 'utime' parameter to be 'const ... *' Alejandro Colomar
2020-12-10 17:36 ` Alejandro Colomar (man-pages)
2021-01-17 16:32   ` Ping: " Alejandro Colomar (man-pages)
2021-01-27 19:31 ` [tip: locking/core] futex: Change utime " tip-bot2 for Alejandro Colomar
2021-01-28 12:21 ` tip-bot2 for Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).