Skip to content

Commit fc4569e

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 c640618 commit fc4569e

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

kernel/bpf/helpers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3681,6 +3681,8 @@ __bpf_kfunc int bpf_strnstr(const char *s1__ign, const char *s2__ign, size_t len
36813681
return -ENOENT;
36823682
if (c1 != c2)
36833683
break;
3684+
if (j == len - 1)
3685+
return i;
36843686
}
36853687
if (j == XATTR_SIZE_MAX)
36863688
return -E2BIG;

0 commit comments

Comments
 (0)