public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls
@ 2015-01-16 19:28 Michael Kerrisk (man-pages)
  2015-01-17  2:04 ` Darren Hart
  2015-01-19 11:10 ` [tip:locking/core] futex: Fix argument handling in futex_lock_pi( ) calls tip-bot for Michael Kerrisk
  0 siblings, 2 replies; 4+ messages in thread
From: Michael Kerrisk (man-pages) @ 2015-01-16 19:28 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: mtk.manpages, lkml, Darren Hart, Ingo Molnar

From: Michael Kerrisk <mtk.manpages@gmail.com>

This patch fixes two separate buglets in calls to futex_lock_pi():

  * Eliminate unused 'detect' argument
  * Change unused 'timeout' argument of FUTEX_TRYLOCK_PI to NULL

The 'detect' argument of futex_lock_pi() seems never to have been
used (when it was included with the initial PI mutex implementation
in Linux 2.6.18, all checks against its value were disabled by
ANDing against 0 (i.e., if (detect... && 0)), and with
commit 778e9a9c3e7193ea9f434f382947155ffb59c755, any mention of
this argument in futex_lock_pi() went way altogether. Its presence
now serves only to confuse readers of the code, by giving the
impression that the futex() FUTEX_LOCK_PI operation actually does
use the 'val' argument. This patch removes the argument.

The futex_lock_pi() call that corresponds to FUTEX_TRYLOCK_PI includes
'timeout' as one of its arguments. This misleads the reader into thinking
that the FUTEX_TRYLOCK_PI operation does employ timeouts for some sensible
purpose; but it does not.  Indeed, it cannot, because the checks at the
start of sys_futex() exclude FUTEX_TRYLOCK_PI from the set of operations
that do copy_from_user() on the timeout argument. So, in the
FUTEX_TRYLOCK_PI futex_lock_pi() call it would be simplest to change
'timeout' to 'NULL'. This patch does that.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>

---
Seems obviously safe, but in any case compiled, tested, and booted
on my x86 system.

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

diff --git a/kernel/futex.c b/kernel/futex.c
index 63678b5..4eeb63d 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2258,7 +2258,7 @@ static long futex_wait_restart(struct restart_block *restart)
  * if there are waiters then it will block, it does PI, etc. (Due to
  * races the kernel might see a 0 value of the futex too.)
  */
-static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
+static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
 			 ktime_t *time, int trylock)
 {
 	struct hrtimer_sleeper timeout, *to = NULL;
@@ -2953,11 +2953,11 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
 	case FUTEX_WAKE_OP:
 		return futex_wake_op(uaddr, flags, uaddr2, val, val2, val3);
 	case FUTEX_LOCK_PI:
-		return futex_lock_pi(uaddr, flags, val, timeout, 0);
+		return futex_lock_pi(uaddr, flags, timeout, 0);
 	case FUTEX_UNLOCK_PI:
 		return futex_unlock_pi(uaddr, flags);
 	case FUTEX_TRYLOCK_PI:
-		return futex_lock_pi(uaddr, flags, 0, timeout, 1);
+		return futex_lock_pi(uaddr, flags, NULL, 1);
 	case FUTEX_WAIT_REQUEUE_PI:
 		val3 = FUTEX_BITSET_MATCH_ANY;
 		return futex_wait_requeue_pi(uaddr, flags, val, timeout, val3,
-- 
1.9.3

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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

* Re: [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls
  2015-01-16 19:28 [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls Michael Kerrisk (man-pages)
@ 2015-01-17  2:04 ` Darren Hart
  2015-01-17  8:42   ` Michael Kerrisk (man-pages)
  2015-01-19 11:10 ` [tip:locking/core] futex: Fix argument handling in futex_lock_pi( ) calls tip-bot for Michael Kerrisk
  1 sibling, 1 reply; 4+ messages in thread
From: Darren Hart @ 2015-01-17  2:04 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages)
  Cc: Thomas Gleixner, lkml, Darren Hart, Ingo Molnar

On Fri, Jan 16, 2015 at 08:28:06PM +0100, Michael Kerrisk (man-pages) wrote:
> From: Michael Kerrisk <mtk.manpages@gmail.com>
> 
> This patch fixes two separate buglets in calls to futex_lock_pi():
> 
>   * Eliminate unused 'detect' argument
>   * Change unused 'timeout' argument of FUTEX_TRYLOCK_PI to NULL

One might argue these should be two separate fixes. Since both are trivial and functional
no-ops, I'm going to ignore it and consider it a "cleanup" :-) Thomas may
disagree.

> 
> The 'detect' argument of futex_lock_pi() seems never to have been
> used (when it was included with the initial PI mutex implementation
> in Linux 2.6.18, all checks against its value were disabled by
> ANDing against 0 (i.e., if (detect... && 0)), and with
> commit 778e9a9c3e7193ea9f434f382947155ffb59c755, any mention of
> this argument in futex_lock_pi() went way altogether. Its presence
> now serves only to confuse readers of the code, by giving the
> impression that the futex() FUTEX_LOCK_PI operation actually does
> use the 'val' argument. This patch removes the argument.
> 
> The futex_lock_pi() call that corresponds to FUTEX_TRYLOCK_PI includes
> 'timeout' as one of its arguments. This misleads the reader into thinking
> that the FUTEX_TRYLOCK_PI operation does employ timeouts for some sensible
> purpose; but it does not.  Indeed, it cannot, because the checks at the
> start of sys_futex() exclude FUTEX_TRYLOCK_PI from the set of operations
> that do copy_from_user() on the timeout argument. So, in the
> FUTEX_TRYLOCK_PI futex_lock_pi() call it would be simplest to change
> 'timeout' to 'NULL'. This patch does that.
> 
> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>

Good and correct changes each.

Reviewed-by: Darren Hart <dvhart@linux.intel.com>

Thanks Michael,

-- 
Darren Hart
Intel Open Source Technology Center

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

* Re: [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls
  2015-01-17  2:04 ` Darren Hart
@ 2015-01-17  8:42   ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Kerrisk (man-pages) @ 2015-01-17  8:42 UTC (permalink / raw)
  To: Darren Hart; +Cc: mtk.manpages, Thomas Gleixner, lkml, Darren Hart, Ingo Molnar

On 01/17/2015 03:04 AM, Darren Hart wrote:
> On Fri, Jan 16, 2015 at 08:28:06PM +0100, Michael Kerrisk (man-pages) wrote:
>> From: Michael Kerrisk <mtk.manpages@gmail.com>
>>
>> This patch fixes two separate buglets in calls to futex_lock_pi():
>>
>>   * Eliminate unused 'detect' argument
>>   * Change unused 'timeout' argument of FUTEX_TRYLOCK_PI to NULL
> 
> One might argue these should be two separate fixes. Since both are trivial and functional
> no-ops, I'm going to ignore it and consider it a "cleanup" :-) Thomas may
> disagree.

Yup, and that's what I was going to do until I realized that the patches 
changed the same line. Then I thought it easier to combine them (rather 
than make dependent patches), since they're fairly trivial. But,
I'll split them if Thomas wishes.

Thanks,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/

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

* [tip:locking/core] futex: Fix argument handling in futex_lock_pi( ) calls
  2015-01-16 19:28 [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls Michael Kerrisk (man-pages)
  2015-01-17  2:04 ` Darren Hart
@ 2015-01-19 11:10 ` tip-bot for Michael Kerrisk
  1 sibling, 0 replies; 4+ messages in thread
From: tip-bot for Michael Kerrisk @ 2015-01-19 11:10 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: hpa, darren, linux-kernel, tglx, mingo, mtk.manpages

Commit-ID:  996636ddae5cab8883bd76b996cd4f2ea9a152be
Gitweb:     http://git.kernel.org/tip/996636ddae5cab8883bd76b996cd4f2ea9a152be
Author:     Michael Kerrisk <mtk.manpages@gmail.com>
AuthorDate: Fri, 16 Jan 2015 20:28:06 +0100
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Mon, 19 Jan 2015 12:05:32 +0100

futex: Fix argument handling in futex_lock_pi() calls

This patch fixes two separate buglets in calls to futex_lock_pi():

  * Eliminate unused 'detect' argument
  * Change unused 'timeout' argument of FUTEX_TRYLOCK_PI to NULL

The 'detect' argument of futex_lock_pi() seems never to have been
used (when it was included with the initial PI mutex implementation
in Linux 2.6.18, all checks against its value were disabled by
ANDing against 0 (i.e., if (detect... && 0)), and with
commit 778e9a9c3e7193ea9f434f382947155ffb59c755, any mention of
this argument in futex_lock_pi() went way altogether. Its presence
now serves only to confuse readers of the code, by giving the
impression that the futex() FUTEX_LOCK_PI operation actually does
use the 'val' argument. This patch removes the argument.

The futex_lock_pi() call that corresponds to FUTEX_TRYLOCK_PI includes
'timeout' as one of its arguments. This misleads the reader into thinking
that the FUTEX_TRYLOCK_PI operation does employ timeouts for some sensible
purpose; but it does not.  Indeed, it cannot, because the checks at the
start of sys_futex() exclude FUTEX_TRYLOCK_PI from the set of operations
that do copy_from_user() on the timeout argument. So, in the
FUTEX_TRYLOCK_PI futex_lock_pi() call it would be simplest to change
'timeout' to 'NULL'. This patch does that.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
Reviewed-by: Darren Hart <darren@dvhart.com>
Link: http://lkml.kernel.org/r/54B96646.8010200@gmail.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

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

diff --git a/kernel/futex.c b/kernel/futex.c
index 63678b5..4eeb63d 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2258,7 +2258,7 @@ static long futex_wait_restart(struct restart_block *restart)
  * if there are waiters then it will block, it does PI, etc. (Due to
  * races the kernel might see a 0 value of the futex too.)
  */
-static int futex_lock_pi(u32 __user *uaddr, unsigned int flags, int detect,
+static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
 			 ktime_t *time, int trylock)
 {
 	struct hrtimer_sleeper timeout, *to = NULL;
@@ -2953,11 +2953,11 @@ long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout,
 	case FUTEX_WAKE_OP:
 		return futex_wake_op(uaddr, flags, uaddr2, val, val2, val3);
 	case FUTEX_LOCK_PI:
-		return futex_lock_pi(uaddr, flags, val, timeout, 0);
+		return futex_lock_pi(uaddr, flags, timeout, 0);
 	case FUTEX_UNLOCK_PI:
 		return futex_unlock_pi(uaddr, flags);
 	case FUTEX_TRYLOCK_PI:
-		return futex_lock_pi(uaddr, flags, 0, timeout, 1);
+		return futex_lock_pi(uaddr, flags, NULL, 1);
 	case FUTEX_WAIT_REQUEUE_PI:
 		val3 = FUTEX_BITSET_MATCH_ANY;
 		return futex_wait_requeue_pi(uaddr, flags, val, timeout, val3,

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

end of thread, other threads:[~2015-01-19 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-16 19:28 [PATCH 2/2] futex: Fix argument handling in futex_lock_pi() calls Michael Kerrisk (man-pages)
2015-01-17  2:04 ` Darren Hart
2015-01-17  8:42   ` Michael Kerrisk (man-pages)
2015-01-19 11:10 ` [tip:locking/core] futex: Fix argument handling in futex_lock_pi( ) calls tip-bot for Michael Kerrisk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox