From: Kees Cook <keescook@chromium.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Rik van Riel <riel@redhat.com>,
Laura Abbott <labbott@fedoraproject.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
xiaolong.ye@intel.com
Subject: [PATCH] usercopy: Skip multi-page bounds checking on SLOB
Date: Wed, 17 Aug 2016 15:29:22 -0700 [thread overview]
Message-ID: <20160817222921.GA25148@www.outflux.net> (raw)
When an allocator does not mark all allocations as PageSlab, or does not
mark multipage allocations with __GFP_COMP, hardened usercopy cannot
correctly validate the allocation. SLOB lacks this, so short-circuit
the checking for the allocators that aren't marked with
CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR. This also updates the config
help and corrects a typo in the usercopy comments.
Reported-by: xiaolong.ye@intel.com
Signed-off-by: Kees Cook <keescook@chromium.org>
---
mm/usercopy.c | 11 ++++++++++-
security/Kconfig | 5 +++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 8ebae91a6b55..855944b05cc7 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -172,6 +172,15 @@ static inline const char *check_heap_object(const void *ptr, unsigned long n,
return NULL;
}
+#ifndef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
+ /*
+ * If the allocator isn't marking multi-page allocations as
+ * either __GFP_COMP or PageSlab, we cannot correctly perform
+ * bounds checking of multi-page allocations, so we stop here.
+ */
+ return NULL;
+#endif
+
/* Allow kernel data region (if not marked as Reserved). */
if (ptr >= (const void *)_sdata && end <= (const void *)_edata)
return NULL;
@@ -192,7 +201,7 @@ static inline const char *check_heap_object(const void *ptr, unsigned long n,
return NULL;
/*
- * Reject if range is entirely either Reserved (i.e. special or
+ * Allow if range is entirely either Reserved (i.e. special or
* device memory), or CMA. Otherwise, reject since the object spans
* several independently allocated pages.
*/
diff --git a/security/Kconfig b/security/Kconfig
index df28f2b6f3e1..08dce0327d5b 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -122,8 +122,9 @@ config HAVE_HARDENED_USERCOPY_ALLOCATOR
bool
help
The heap allocator implements __check_heap_object() for
- validating memory ranges against heap object sizes in
- support of CONFIG_HARDENED_USERCOPY.
+ validating memory ranges against heap object sizes in support
+ of CONFIG_HARDENED_USERCOPY. It must mark all managed pages as
+ PageSlab(), or set __GFP_COMP for multi-page allocations.
config HAVE_ARCH_HARDENED_USERCOPY
bool
--
2.7.4
--
Kees Cook
Nexus Security
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2016-08-17 22:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-17 22:29 Kees Cook [this message]
2016-08-18 14:21 ` Rik van Riel
2016-08-18 17:42 ` Linus Torvalds
2016-08-18 18:02 ` Rik van Riel
2016-08-19 18:00 ` Kees Cook
2016-08-19 10:31 ` Michal Hocko
2016-08-19 19:41 ` Linus Torvalds
2016-08-19 20:03 ` Kees Cook
2016-08-19 20:07 ` 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=20160817222921.GA25148@www.outflux.net \
--to=keescook@chromium.org \
--cc=labbott@fedoraproject.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=xiaolong.ye@intel.com \
/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