* [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list() @ 2022-04-04 16:45 Yuntao Wang 2022-04-04 22:12 ` Andrii Nakryiko 0 siblings, 1 reply; 6+ messages in thread From: Yuntao Wang @ 2022-04-04 16:45 UTC (permalink / raw) To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko Cc: Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, KP Singh, Shuah Khan, netdev, bpf, linux-kernel, linux-kselftest, Yuntao Wang There are some issues in parse_num_list(): 1. The end variable is assigned twice when parsing_end is true. 2. The function does not check that parsing_end should finally be false. Clean up parse_num_list() and fix these issues. Signed-off-by: Yuntao Wang <ytcoode@gmail.com> --- tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index 795b6798ccee..82f0e2d99c23 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) if (errno) return -errno; - if (parsing_end) - end = num; - else + if (!parsing_end) { start = num; + if (*next == '-') { + s = next + 1; + parsing_end = true; + continue; + } + } - if (!parsing_end && *next == '-') { - s = next + 1; - parsing_end = true; - continue; - } else if (*next == ',') { + if (*next == ',') { parsing_end = false; s = next + 1; end = num; @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) set[i] = true; } - if (!set) + if (!set || parsing_end) return -EINVAL; *num_set = set; -- 2.35.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list() 2022-04-04 16:45 [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list() Yuntao Wang @ 2022-04-04 22:12 ` Andrii Nakryiko 2022-04-05 6:24 ` [PATCH bpf-next v2] " Yuntao Wang 0 siblings, 1 reply; 6+ messages in thread From: Andrii Nakryiko @ 2022-04-04 22:12 UTC (permalink / raw) To: Yuntao Wang Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, KP Singh, Shuah Khan, Networking, bpf, open list, open list:KERNEL SELFTEST FRAMEWORK On Mon, Apr 4, 2022 at 9:45 AM Yuntao Wang <ytcoode@gmail.com> wrote: > > There are some issues in parse_num_list(): > > 1. The end variable is assigned twice when parsing_end is true. > 2. The function does not check that parsing_end should finally be false. > > Clean up parse_num_list() and fix these issues. It would be great to also explain user-visible bug. What do you do to trigger bugs? Can you please put that into the commit message, in a before/after fashion? Thanks! > > Signed-off-by: Yuntao Wang <ytcoode@gmail.com> > --- > tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c > index 795b6798ccee..82f0e2d99c23 100644 > --- a/tools/testing/selftests/bpf/testing_helpers.c > +++ b/tools/testing/selftests/bpf/testing_helpers.c > @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > if (errno) > return -errno; > > - if (parsing_end) > - end = num; > - else > + if (!parsing_end) { > start = num; > + if (*next == '-') { > + s = next + 1; > + parsing_end = true; > + continue; > + } > + } > > - if (!parsing_end && *next == '-') { > - s = next + 1; > - parsing_end = true; > - continue; > - } else if (*next == ',') { > + if (*next == ',') { > parsing_end = false; > s = next + 1; > end = num; > @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > set[i] = true; > } > > - if (!set) > + if (!set || parsing_end) > return -EINVAL; > > *num_set = set; > -- > 2.35.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf-next v2] selftests/bpf: Fix issues in parse_num_list() 2022-04-04 22:12 ` Andrii Nakryiko @ 2022-04-05 6:24 ` Yuntao Wang 2022-04-05 23:28 ` Andrii Nakryiko 0 siblings, 1 reply; 6+ messages in thread From: Yuntao Wang @ 2022-04-05 6:24 UTC (permalink / raw) To: andrii.nakryiko Cc: andrii, ast, bpf, daniel, john.fastabend, kafai, kpsingh, linux-kernel, linux-kselftest, netdev, shuah, songliubraving, yhs, ytcoode There are some issues in parse_num_list(): First, the end variable is assigned twice when parsing_end is true, it is unnecessary. Second, the function does not check that parsing_end is false after parsing argument. Thus, if the final part of the argument is something like '4-', parse_num_list() will discard it instead of returning -EINVAL. Clean up parse_num_list() and fix these issues. Before: $ ./test_progs -n 2,4- #2 atomic_bounds:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED After: $ ./test_progs -n 2,4- Failed to parse test numbers. Signed-off-by: Yuntao Wang <ytcoode@gmail.com> --- v1 -> v2: add more details to commit message tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index 795b6798ccee..82f0e2d99c23 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) if (errno) return -errno; - if (parsing_end) - end = num; - else + if (!parsing_end) { start = num; + if (*next == '-') { + s = next + 1; + parsing_end = true; + continue; + } + } - if (!parsing_end && *next == '-') { - s = next + 1; - parsing_end = true; - continue; - } else if (*next == ',') { + if (*next == ',') { parsing_end = false; s = next + 1; end = num; @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) set[i] = true; } - if (!set) + if (!set || parsing_end) return -EINVAL; *num_set = set; -- 2.35.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v2] selftests/bpf: Fix issues in parse_num_list() 2022-04-05 6:24 ` [PATCH bpf-next v2] " Yuntao Wang @ 2022-04-05 23:28 ` Andrii Nakryiko 2022-04-06 0:36 ` [PATCH bpf-next v3] " Yuntao Wang 0 siblings, 1 reply; 6+ messages in thread From: Andrii Nakryiko @ 2022-04-05 23:28 UTC (permalink / raw) To: Yuntao Wang Cc: Andrii Nakryiko, Alexei Starovoitov, bpf, Daniel Borkmann, john fastabend, Martin Lau, KP Singh, open list, open list:KERNEL SELFTEST FRAMEWORK, Networking, Shuah Khan, Song Liu, Yonghong Song On Mon, Apr 4, 2022 at 11:24 PM Yuntao Wang <ytcoode@gmail.com> wrote: > > There are some issues in parse_num_list(): > > First, the end variable is assigned twice when parsing_end is true, it is > unnecessary. > > Second, the function does not check that parsing_end is false after parsing > argument. Thus, if the final part of the argument is something like '4-', > parse_num_list() will discard it instead of returning -EINVAL. > > Clean up parse_num_list() and fix these issues. > > Before: > > $ ./test_progs -n 2,4- > #2 atomic_bounds:OK > Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED > > After: > > $ ./test_progs -n 2,4- > Failed to parse test numbers. > > Signed-off-by: Yuntao Wang <ytcoode@gmail.com> > --- > v1 -> v2: add more details to commit message > > tools/testing/selftests/bpf/testing_helpers.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c > index 795b6798ccee..82f0e2d99c23 100644 > --- a/tools/testing/selftests/bpf/testing_helpers.c > +++ b/tools/testing/selftests/bpf/testing_helpers.c > @@ -20,16 +20,16 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > if (errno) > return -errno; > > - if (parsing_end) > - end = num; > - else > + if (!parsing_end) { > start = num; > + if (*next == '-') { > + s = next + 1; > + parsing_end = true; > + continue; > + } > + } > > - if (!parsing_end && *next == '-') { > - s = next + 1; > - parsing_end = true; > - continue; > - } else if (*next == ',') { I think the new structure of the code is actually harder to follow and there is no need to change this code in the first place just to optimize away parsing_end assignmet. > + if (*next == ',') { > parsing_end = false; > s = next + 1; > end = num; > @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) > set[i] = true; > } > > - if (!set) > + if (!set || parsing_end) > return -EINVAL; > this is a real fix, please submit just and drop the first part of the patch > *num_set = set; > -- > 2.35.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH bpf-next v3] selftests/bpf: Fix issues in parse_num_list() 2022-04-05 23:28 ` Andrii Nakryiko @ 2022-04-06 0:36 ` Yuntao Wang 2022-04-06 17:20 ` patchwork-bot+netdevbpf 0 siblings, 1 reply; 6+ messages in thread From: Yuntao Wang @ 2022-04-06 0:36 UTC (permalink / raw) To: Andrii Nakryiko, bpf Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend, KP Singh, netdev, linux-kernel, Yuntao Wang The function does not check that parsing_end is false after parsing argument. Thus, if the final part of the argument is something like '4-', which is invalid, parse_num_list() will discard it instead of returning -EINVAL. Before: $ ./test_progs -n 2,4- #2 atomic_bounds:OK Summary: 1/0 PASSED, 0 SKIPPED, 0 FAILED After: $ ./test_progs -n 2,4- Failed to parse test numbers. Signed-off-by: Yuntao Wang <ytcoode@gmail.com> --- v1 -> v2: add more details to commit message v2 -> v3: remove the first part of the patch tools/testing/selftests/bpf/testing_helpers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/testing_helpers.c b/tools/testing/selftests/bpf/testing_helpers.c index 795b6798ccee..87867f7a78c3 100644 --- a/tools/testing/selftests/bpf/testing_helpers.c +++ b/tools/testing/selftests/bpf/testing_helpers.c @@ -60,7 +60,7 @@ int parse_num_list(const char *s, bool **num_set, int *num_set_len) set[i] = true; } - if (!set) + if (!set || parsing_end) return -EINVAL; *num_set = set; -- 2.35.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH bpf-next v3] selftests/bpf: Fix issues in parse_num_list() 2022-04-06 0:36 ` [PATCH bpf-next v3] " Yuntao Wang @ 2022-04-06 17:20 ` patchwork-bot+netdevbpf 0 siblings, 0 replies; 6+ messages in thread From: patchwork-bot+netdevbpf @ 2022-04-06 17:20 UTC (permalink / raw) To: Yuntao Wang Cc: andrii.nakryiko, bpf, ast, daniel, andrii, kafai, songliubraving, yhs, john.fastabend, kpsingh, netdev, linux-kernel Hello: This patch was applied to bpf/bpf-next.git (master) by Andrii Nakryiko <andrii@kernel.org>: On Wed, 6 Apr 2022 08:36:22 +0800 you wrote: > The function does not check that parsing_end is false after parsing > argument. Thus, if the final part of the argument is something like '4-', > which is invalid, parse_num_list() will discard it instead of returning > -EINVAL. > > Before: > > [...] Here is the summary with links: - [bpf-next,v3] selftests/bpf: Fix issues in parse_num_list() https://git.kernel.org/bpf/bpf-next/c/958ddfd75d83 You are awesome, thank you! -- Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-06 19:15 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-04-04 16:45 [PATCH bpf-next] selftests/bpf: Fix issues in parse_num_list() Yuntao Wang 2022-04-04 22:12 ` Andrii Nakryiko 2022-04-05 6:24 ` [PATCH bpf-next v2] " Yuntao Wang 2022-04-05 23:28 ` Andrii Nakryiko 2022-04-06 0:36 ` [PATCH bpf-next v3] " Yuntao Wang 2022-04-06 17:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox