Skip to content

Commit e5d7e36

Browse files
RtoaxKernel Patches Daemon
authored andcommitted
bpf/helpers: bpf_strnstr: Exact match length
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 <[email protected]>
1 parent 83124e1 commit e5d7e36

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/bpf/helpers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3672,10 +3672,12 @@ __bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len
36723672

36733673
guard(pagefault)();
36743674
for (i = 0; i < XATTR_SIZE_MAX; i++) {
3675-
for (j = 0; i + j < len && j < XATTR_SIZE_MAX; j++) {
3675+
for (j = 0; i + j <= len && j < XATTR_SIZE_MAX; j++) {
36763676
__get_kernel_nofault(&c2, s2__ign + j, char, err_out);
36773677
if (c2 == '\0')
36783678
return i;
3679+
if (i + j == len)
3680+
break;
36793681
__get_kernel_nofault(&c1, s1__ign + j, char, err_out);
36803682
if (c1 == '\0')
36813683
return -ENOENT;

0 commit comments

Comments
 (0)