[PATCH v5 4/6] rust: helpers: Add memchr wrapper for string operations

From: Jan Polensky

Date: Mon Jun 01 2026 - 13:53:52 EST


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@xxxxxxxxx>
Link: https://lore.kernel.org/rust-for-linux/CANiq72mXAZc0sNM7ShX8VDVs_7zJddawP-e=wt+ERr1YUCcWUw@xxxxxxxxxxxxxx/
Signed-off-by: Jan Polensky <japo@xxxxxxxxxxxxx>
---
rust/helpers/helpers.c | 1 +
rust/helpers/string.c | 8 ++++++++
2 files changed, 9 insertions(+)
create mode 100644 rust/helpers/string.c

diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
index 625921e27dfb..592b9bdb4e4a 100644
--- a/rust/helpers/helpers.c
+++ b/rust/helpers/helpers.c
@@ -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
index 000000000000..d04340dc9139
--- /dev/null
+++ b/rust/helpers/string.c
@@ -0,0 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <linux/string.h>
+
+void *rust_helper_memchr(const void *s, int c, size_t n)
+{
+ return memchr(s, c, n);
+}
\ No newline at end of file
--
2.53.0