From: Helge Deller <deller@gmx.de>
To: Al Viro <viro@zeniv.linux.org.uk>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] compat: fix possible out-of-bound accesses in compat_get_bitmap() and compat_put_bitmap()
Date: Mon, 1 Jun 2015 20:44:37 +0200 [thread overview]
Message-ID: <20150601184437.GA2534@ls3530.box> (raw)
In functions compat_get_bitmap() and compat_put_bitmap() the variable
nr_compat_longs stores how many compat_ulong_t words should be copied in a loop.
The copy-loop itself is this:
if (nr_compat_longs-- > 0) {
if (__get_user(um, umask)) return -EFAULT;
} else {
um = 0;
}
Since nr_compat_longs gets unconditionally decremented in each loop, it's type
needs to be signed instead of unsigned to avoid possibly accessing userspace
memory behind the bitmap which shouldn't be accessed.
This bug seems to have been here for quite some time already, e.g. kernel
2.6.11 has the same coding. I didn't checked earlier versions.
Signed-off-by: Helge Deller <deller@gmx.de>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: stable@vger.kernel.org
diff --git a/kernel/compat.c b/kernel/compat.c
index 24f0061..bfbb312 100644
--- a/kernel/compat.c
+++ b/kernel/compat.c
@@ -893,7 +893,7 @@ long compat_get_bitmap(unsigned long *mask, const compat_ulong_t __user *umask,
int i, j;
unsigned long m;
compat_ulong_t um;
- unsigned long nr_compat_longs;
+ signed long nr_compat_longs;
/* align bitmap up to nearest compat_long_t boundary */
bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
@@ -934,7 +934,7 @@ long compat_put_bitmap(compat_ulong_t __user *umask, unsigned long *mask,
int i, j;
unsigned long m;
compat_ulong_t um;
- unsigned long nr_compat_longs;
+ signed long nr_compat_longs;
/* align bitmap up to nearest compat_long_t boundary */
bitmap_size = ALIGN(bitmap_size, BITS_PER_COMPAT_LONG);
next reply other threads:[~2015-06-01 18:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 18:44 Helge Deller [this message]
2015-06-02 1:49 ` [PATCH] compat: fix possible out-of-bound accesses in compat_get_bitmap() and compat_put_bitmap() Linus Torvalds
2015-06-04 13:45 ` Helge Deller
2015-06-04 16:38 ` Linus Torvalds
2015-06-04 22:07 ` Helge Deller
2015-06-05 0:36 ` Al Viro
2015-06-05 16:49 ` Linus Torvalds
2015-06-05 18:24 ` Al Viro
2015-06-06 16:13 ` Linus Torvalds
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=20150601184437.GA2534@ls3530.box \
--to=deller@gmx.de \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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