[<prev] [next>] [day] [month] [year] [list]
Message-ID: <tencent_65E5988AD52BEC280D22964189505CD6ED06@qq.com>
Date: Wed, 27 Aug 2025 12:27:23 +0800
From: Rong Tao <rtoax@...mail.com>
To: ast@...nel.org,
daniel@...earbox.net
Cc: rongtao@...tc.cn,
rtoax@...mail.com,
Andrii Nakryiko <andrii@...nel.org>,
Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
bpf@...r.kernel.org (open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)),
linux-kernel@...r.kernel.org (open list)
Subject: [PATCH bpf-next] bpf/helpers: bpf_strnstr: Exact match length
From: Rong Tao <rongtao@...tc.cn>
strnstr should not treat the ending '\0' of s2 as a matching character,
otherwise the parameter 'len' will be meaningless, for example:
1. bpf_strnstr("openat", "open", 4) = -ENOENT
2. bpf_strnstr("openat", "open", 5) = 0
This patch makes (1) return 0, indicating a successful match.
Signed-off-by: Rong Tao <rongtao@...tc.cn>
---
kernel/bpf/helpers.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 401b4932cc49..65bd0050c560 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -3681,6 +3681,8 @@ __bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len
return -ENOENT;
if (c1 != c2)
break;
+ if (j == len - 1)
+ return i;
}
if (j == XATTR_SIZE_MAX)
return -E2BIG;
--
2.51.0
Powered by blists - more mailing lists