From: Jiri Slaby <jslaby@suse.cz>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 2/3] futex: fix decoding of operation
Date: Fri, 3 Mar 2017 13:27:11 +0100 [thread overview]
Message-ID: <20170303122712.13353-2-jslaby@suse.cz> (raw)
In-Reply-To: <20170303122712.13353-1-jslaby@suse.cz>
encoded_op uses int as type which results in pretty weird behaviour.
E.g. if encoded_op contains oparg 0xfff, it currently results in oparg
being -1.
Switch encoded_op to 'unsigned int' which is correct given it is a bit
mask anyway. And perform upper bound checking on oparg to inform users
about the failure. Finally, avoid int overflows using unsigned shift on
oparg. Note that given we use -fno-strict-overflow, this is not a fix as
there is no problem to fix in the first place.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
kernel/futex.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/futex.c b/kernel/futex.c
index c5ff9850952f..c09424406560 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -1457,7 +1457,7 @@ futex_wake(u32 __user *uaddr, unsigned int flags, int nr_wake, u32 bitset)
return ret;
}
-static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
+static int futex_atomic_op_inuser(unsigned int encoded_op, u32 __user *uaddr)
{
int op = (encoded_op >> 28) & 7;
int cmp = (encoded_op >> 24) & 15;
@@ -1465,8 +1465,11 @@ static int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
int cmparg = (encoded_op << 20) >> 20;
int oldval, ret;
- if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
- oparg = 1 << oparg;
+ if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28)) {
+ if (oparg >= 32)
+ return -EINVAL;
+ oparg = 1U << oparg;
+ }
if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
return -EFAULT;
--
2.12.0
next prev parent reply other threads:[~2017-03-03 18:24 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-03 12:27 [PATCH 1/3] futex: remove duplicated code Jiri Slaby
2017-03-03 12:27 ` Jiri Slaby [this message]
2017-03-03 12:27 ` [PATCH 3/3] futex: make the encoded_op decoding readable Jiri Slaby
2017-03-05 7:55 ` Jiri Slaby
2017-03-03 14:08 ` [PATCH 1/3] futex: remove duplicated code Heiko Carstens
2017-03-03 14:48 ` Chris Metcalf
2017-03-04 12:49 ` Michael Ellerman
2017-03-04 13:05 ` Russell King - ARM Linux
2017-03-04 19:15 ` H. Peter Anvin
2017-03-04 21:38 ` Stafford Horne
2017-03-04 23:03 ` H. Peter Anvin
2017-03-04 23:08 ` H. Peter Anvin
2017-03-04 23:39 ` Stafford Horne
2017-03-06 8:46 ` Jiri Slaby
2017-03-06 9:13 ` H. Peter Anvin
2017-03-06 14:14 ` Geert Uytterhoeven
2017-03-09 4:16 ` Rob Landley
2017-03-09 4:36 ` H. Peter Anvin
2017-03-09 22:37 ` Rich Felker
2017-03-06 1:52 ` Rich Felker
2017-03-09 22:43 ` Vineet Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170303122712.13353-2-jslaby@suse.cz \
--to=jslaby@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®