]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: helpers: Add memchr wrapper for string operations
authorJan Polensky <japo@linux.ibm.com>
Mon, 1 Jun 2026 17:46:23 +0000 (19:46 +0200)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Wed, 10 Jun 2026 14:25:13 +0000 (16:25 +0200)
Add a dedicated string helper file with a memchr wrapper that uses the
kernel's instrumented memchr() function to ensure KASAN and FORTIFY_SOURCE
protections are preserved for Rust code.

Reported-by: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
Link: https://lore.kernel.org/rust-for-linux/CANiq72mXAZc0sNM7ShX8VDVs_7zJddawP-e=wt+ERr1YUCcWUw@mail.gmail.com/
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Acked-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
rust/helpers/helpers.c
rust/helpers/string.c [new file with mode: 0644]

index 625921e27dfbc1d0611f5093e85e8bc9f6aa9b0f..592b9bdb4e4affa0fe64497e1ab8928731065c2a 100644 (file)
@@ -88,6 +88,7 @@
 #include "signal.c"
 #include "slab.c"
 #include "spinlock.c"
+#include "string.c"
 #include "sync.c"
 #include "task.c"
 #include "time.c"
diff --git a/rust/helpers/string.c b/rust/helpers/string.c
new file mode 100644 (file)
index 0000000..8ef30eb
--- /dev/null
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/string.h>
+
+__rust_helper void *rust_helper_memchr(const void *s, int c, size_t n)
+{
+       return memchr(s, c, n);
+}