From: Ze Zuo <zuoze1@huawei.com>
To: <gustavoars@kernel.org>, <akpm@linux-foundation.org>
Cc: <linux-hardening@vger.kernel.org>, <linux-mm@kvack.org>,
<willy@infradead.org>, <keescook@chromium.org>,
<urezki@gmail.com>, <zuoze1@huawei.com>,
<wangkefeng.wang@huawei.com>
Subject: [PATCH -next] mm: usercopy: add a debugfs interface to bypass the vmalloc check.
Date: Tue, 3 Dec 2024 10:31:59 +0800 [thread overview]
Message-ID: <20241203023159.219355-1-zuoze1@huawei.com> (raw)
The commit 0aef499f3172 ("mm/usercopy: Detect vmalloc overruns") introduced
vmalloc check for usercopy. However, in subsystems like networking, when
memory allocated using vmalloc or vmap is subsequently copied using
functions like copy_to_iter/copy_from_iter, the check is triggered. This
adds overhead in the copy path, such as the cost of searching the
red-black tree, which increases the performance burden.
We found that after merging this patch, network bandwidth performance in
the XDP scenario significantly dropped from 25 Gbits/sec to 8 Gbits/sec,
the hardened_usercopy is enabled by default.
To address this, we introduced a debugfs interface that allows selectively
enabling or disabling the vmalloc check based on the use case, optimizing
performance.
By default, vmalloc check for usercopy is enabled.
To disable the vmalloc check:
echo Y > /sys/kernel/debug/bypass_usercopy_vmalloc_check
After executing the above command, the XDP performance returns to 25
Gbits/sec.
Signed-off-by: Ze Zuo <zuoze1@huawei.com>
---
mm/usercopy.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/mm/usercopy.c b/mm/usercopy.c
index 83c164aba6e0..ef1eb23b2273 100644
--- a/mm/usercopy.c
+++ b/mm/usercopy.c
@@ -21,6 +21,7 @@
#include <linux/vmalloc.h>
#include <linux/atomic.h>
#include <linux/jump_label.h>
+#include <linux/debugfs.h>
#include <asm/sections.h>
#include "slab.h"
@@ -159,6 +160,8 @@ static inline void check_bogus_address(const unsigned long ptr, unsigned long n,
usercopy_abort("null address", NULL, to_user, ptr, n);
}
+static bool bypass_vmalloc_check __read_mostly;
+
static inline void check_heap_object(const void *ptr, unsigned long n,
bool to_user)
{
@@ -174,8 +177,13 @@ static inline void check_heap_object(const void *ptr, unsigned long n,
}
if (is_vmalloc_addr(ptr) && !pagefault_disabled()) {
- struct vmap_area *area = find_vmap_area(addr);
+ struct vmap_area *area;
+
+ /* Bypass it since searching the kernel VM area is slow */
+ if (bypass_vmalloc_check)
+ return;
+ area = find_vmap_area(addr);
if (!area)
usercopy_abort("vmalloc", "no area", to_user, 0, n);
@@ -271,6 +279,9 @@ static int __init set_hardened_usercopy(void)
{
if (enable_checks == false)
static_branch_enable(&bypass_usercopy_checks);
+ else
+ debugfs_create_bool("bypass_usercopy_vmalloc_check", 0600,
+ NULL, &bypass_vmalloc_check);
return 1;
}
--
2.25.1
next reply other threads:[~2024-12-03 2:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 2:31 Ze Zuo [this message]
2024-12-03 4:11 ` Matthew Wilcox
2024-12-03 11:23 ` zuoze
2024-12-03 12:39 ` Uladzislau Rezki
2024-12-03 13:10 ` zuoze
2024-12-03 13:25 ` Uladzislau Rezki
2024-12-03 13:30 ` Kefeng Wang
2024-12-03 13:39 ` Uladzislau Rezki
2024-12-03 13:45 ` Kefeng Wang
2024-12-03 13:51 ` Uladzislau Rezki
2024-12-03 14:10 ` Kefeng Wang
2024-12-03 14:20 ` Uladzislau Rezki
2024-12-03 19:02 ` Uladzislau Rezki
2024-12-03 19:56 ` Matthew Wilcox
2024-12-04 1:38 ` zuoze
2024-12-04 4:43 ` Kees Cook
2024-12-04 7:55 ` Uladzislau Rezki
2024-12-04 9:21 ` zuoze
2024-12-04 9:27 ` Uladzislau Rezki
2024-12-04 8:51 ` Uladzislau Rezki
2024-12-16 4:24 ` Matthew Wilcox
2024-12-16 19:18 ` Uladzislau Rezki
2024-12-04 1:21 ` zuoze
2024-12-03 6:12 ` Uladzislau Rezki
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=20241203023159.219355-1-zuoze1@huawei.com \
--to=zuoze1@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=gustavoars@kernel.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=urezki@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=willy@infradead.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