From: Xiaofeng Yuan <yuanxiaofeng1@huawei.com>
To: <keescook@chromium.org>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
Xiaofeng Yuan <yuanxiaofeng1@huawei.com>
Subject: [PATCH RFC] usercopy: optimize stack check flow when the
Date: Tue, 14 Aug 2018 20:17:31 +0800 [thread overview]
Message-ID: <1534249051-56879-1-git-send-email-yuanxiaofeng1@huawei.com> (raw)
The check_heap_object() checks the spanning multiple pages and slab.
When the page-spanning test is disabled, the check_heap_object() is
redundant for spanning multiple pages. However, the kernel stacks are
multiple pages under certain conditions: CONFIG_ARCH_THREAD_STACK_ALLOCATOR
is not defined and (THREAD_SIZE >= PAGE_SIZE). At this point, We can skip
the check_heap_object() for kernel stacks to improve performance.
Similarly, the virtually-mapped stack can skip check_heap_object() also,
beacause virt_addr_valid() will return.
I launched more than 100 apps on smartphone, and recorded total check time
and numbers of kernel stacks. The average time of checking kernel stacks
reduced by 48%.
Signed-off-by: Xiaofeng Yuan <yuanxiaofeng1@huawei.com>
---
mm/usercopy.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/mm/usercopy.c b/mm/usercopy.c
index e9e9325..af350f6 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -255,6 +255,29 @@ void __check_object_size(const void *ptr, unsigned long n, bool to_user)
/* Check for invalid addresses. */
check_bogus_address((const unsigned long)ptr, n, to_user);
+#if !defined(CONFIG_HARDENED_USERCOPY_PAGESPAN) && \
+ !defined(CONFIG_ARCH_THREAD_STACK_ALLOCATOR) && \
+ (THREAD_SIZE >= PAGE_SIZE || defined(CONFIG_VMAP_STACK))
+ /* Check for bad stack object. */
+ switch (check_stack_object(ptr, n)) {
+ case NOT_STACK:
+ /* Object is not touching the current process stack. */
+ break;
+ case GOOD_FRAME:
+ case GOOD_STACK:
+ /*
+ * Object is either in the correct frame (when it
+ * is possible to check) or just generally on the
+ * process stack (when frame checking not available).
+ */
+ return;
+ default:
+ usercopy_abort("process stack", NULL, to_user, 0, n);
+ }
+
+ /* Check for bad heap object. */
+ check_heap_object(ptr, n, to_user);
+#else
/* Check for bad heap object. */
check_heap_object(ptr, n, to_user);
@@ -274,6 +297,7 @@ void __check_object_size(const void *ptr, unsigned long n, bool to_user)
default:
usercopy_abort("process stack", NULL, to_user, 0, n);
}
+#endif
/* Check for object in kernel to avoid text exposure. */
check_kernel_text_object((const unsigned long)ptr, n, to_user);
--
1.9.1
next reply other threads:[~2018-08-14 12:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 12:17 Xiaofeng Yuan [this message]
2018-08-14 12:34 ` [PATCH RFC] usercopy: optimize stack check flow when the Matthew Wilcox
2018-08-14 13:02 ` [PATCH RFC] usercopy: optimize stack check flow when the page-spanning test is disabled Yuanxiaofeng (XiAn)
2018-08-14 13:09 ` Matthew Wilcox
2018-08-14 18:54 ` Kees Cook
2018-08-15 11:59 ` Yuanxiaofeng (XiAn)
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=1534249051-56879-1-git-send-email-yuanxiaofeng1@huawei.com \
--to=yuanxiaofeng1@huawei.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).