lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <606120ab-ef46-fa87-5f2c-d480de9ed2c8@riseup.net>
Date:   Fri, 23 Apr 2021 19:20:44 -0300
From:   André Almeida <andrealmeid@...eup.net>
To:     Thomas Gleixner <tglx@...utronix.de>,
        LKML <linux-kernel@...r.kernel.org>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Adhemerval Zanella <adhemerval.zanella@...aro.org>,
        Lukasz Majewski <lukma@...x.de>,
        Florian Weimer <fweimer@...hat.com>,
        Carlos O'Donell <carlos@...hat.com>,
        "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>,
        Davidlohr Bueso <dave@...olabs.net>,
        Ingo Molnar <mingo@...nel.org>,
        Kurt Kanzenbach <kurt@...utronix.de>,
        Darren Hart <dvhart@...radead.org>,
        Andrei Vagin <avagin@...il.com>, kernel@...labora.com
Subject: Re: [patch 6/6] futex: Provide FUTEX_LOCK_PI2 to support clock
 selection

Hi Thomas,

Às 16:44 de 22/04/21, Thomas Gleixner escreveu:
> The FUTEX_LOCK_PI futex operand uses a CLOCK_REALTIME based absolute
> timeout since it was implemented, but it does not require that the
> FUTEX_CLOCK_REALTIME flag is set, because that was introduced later.
> 
> In theory as none of the user space implementations can set the
> FUTEX_CLOCK_REALTIME flag on this operand, it would be possible to
> creatively abuse it and make the meaning invers, i.e. select CLOCK_REALTIME
> when not set and CLOCK_MONOTONIC when set. But that's a nasty hackery.
> 
> Another option would be to have a new FUTEX_CLOCK_MONOTONIC flag only for
> FUTEX_LOCK_PI, but that's also awkward because it does not allow libraries
> to handle the timeout clock selection consistently.
> 
> So provide a new FUTEX_LOCK_PI2 operand which implements the timeout
> semantics which the other operands use and leave FUTEX_LOCK_PI alone.
> 
> Reported-by: Kurt Kanzenbach <kurt@...utronix.de>
> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> ---
>   include/uapi/linux/futex.h |    1 +
>   kernel/futex.c             |    6 +++++-
>   2 files changed, 6 insertions(+), 1 deletion(-)
> 
> --- a/include/uapi/linux/futex.h
> +++ b/include/uapi/linux/futex.h
> @@ -21,6 +21,7 @@
>   #define FUTEX_WAKE_BITSET	10
>   #define FUTEX_WAIT_REQUEUE_PI	11
>   #define FUTEX_CMP_REQUEUE_PI	12
> +#define FUTEX_LOCK_PI2		13
>   
>   #define FUTEX_PRIVATE_FLAG	128
>   #define FUTEX_CLOCK_REALTIME	256

To keep consistency with other operations, maybe add a 
FUTEX_LOCK_PI2_PRIVATE?

> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -3711,7 +3711,8 @@ long do_futex(u32 __user *uaddr, int op,
>   
>   	if (op & FUTEX_CLOCK_REALTIME) {
>   		flags |= FLAGS_CLOCKRT;
> -		if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI)
> +		if (cmd != FUTEX_WAIT_BITSET && cmd != FUTEX_WAIT_REQUEUE_PI &&
> +		    cmd != FUTEX_LOCK_PI2)
>   			return -ENOSYS;
>   	}

As FUTEX_LOCK_PI, FUTEX_LOCK_PI2 also requires FUTEX_CMPXCHG right? 
Then, add it here:

	switch (cmd) {
	case FUTEX_LOCK_PI:
+	case FUTEX_LOCK_PI2:
	case FUTEX_UNLOCK_PI:
	case FUTEX_TRYLOCK_PI:
	case FUTEX_WAIT_REQUEUE_PI:
	case FUTEX_CMP_REQUEUE_PI:
  		if (!futex_cmpxchg_enabled)
  			return -ENOSYS;
  	}

>   
> @@ -3744,6 +3745,8 @@ long do_futex(u32 __user *uaddr, int op,
>   		return futex_wake_op(uaddr, flags, uaddr2, val, val2, val3);
>   	case FUTEX_LOCK_PI:
>   		flags |= FLAGS_CLOCKRT;
> +		fallthrough;
> +	case FUTEX_LOCK_PI2:
>   		return futex_lock_pi(uaddr, flags, timeout, 0);
>   	case FUTEX_UNLOCK_PI:
>   		return futex_unlock_pi(uaddr, flags);
> @@ -3764,6 +3767,7 @@ static inline bool futex_cmd_has_timeout
>   	switch (cmd) {
>   	case FUTEX_WAIT:
>   	case FUTEX_LOCK_PI:
> +	case FUTEX_LOCK_PI2:
>   	case FUTEX_WAIT_BITSET:
>   	case FUTEX_WAIT_REQUEUE_PI:
>   		return true;
> 

Thanks,
	André

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ