public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* FUTEX_WAKE_OP weirdness
@ 2005-11-02  3:15 David Gibson
  0 siblings, 0 replies; only message in thread
From: David Gibson @ 2005-11-02  3:15 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: Paul 'Rusty' Russell, linux-kernel

Linus/Andrew, please apply.

The code for FUTEX_WAKE_OP calls an arch callback,
futex_atomic_op_inuser().  That callback can return an error code, but
currently the caller assumes any error is EFAULT, and will try various
things to resolve the fault before eventually giving up with EFAULT
(regardless of the original error code).  This is not a theoretical
case - arch callbacks currently return -ENOSYS if the opcode they are
given is bogus.

This patch alters the code to detect non-EFAULT errors and return them
directly to the user.

Of course, whether -ENOSYS is the correct return value for the bogus
opcode case, or whether EINVAL would be more appropriate is another
question.

Signed-off-by: David Gibson <dwg@au1.ibm.com>

Index: working-2.6/kernel/futex.c
===================================================================
--- working-2.6.orig/kernel/futex.c	2005-10-31 15:45:01.000000000 +1100
+++ working-2.6/kernel/futex.c	2005-11-02 14:02:08.000000000 +1100
@@ -365,6 +365,11 @@
 		if (bh1 != bh2)
 			spin_unlock(&bh2->lock);
 
+		if (unlikely(op_ret != -EFAULT)) {
+			ret = op_ret;
+			goto out;
+		}
+
 		/* futex_atomic_op_inuser needs to both read and write
 		 * *(int __user *)uaddr2, but we can't modify it
 		 * non-atomically.  Therefore, if get_user below is not


-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/people/dgibson

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-11-02  3:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-02  3:15 FUTEX_WAKE_OP weirdness David Gibson

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