public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt()
@ 2022-08-24  1:39 Yang Yingliang
  2022-08-24 17:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2022-08-24  1:39 UTC (permalink / raw)
  To: linux-kernel, linux-kselftest, bpf; +Cc: sdf, kafai, ast, andrii, mykolal

sizeof(new_cc) is not real memory size that new_cc point to, introduce
new_cc_len to store size then pass it to bpf_setsockopt().

Fixes: 31123c0360e0 ("selftests/bpf: bpf_setsockopt tests")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
 tools/testing/selftests/bpf/progs/setget_sockopt.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/setget_sockopt.c b/tools/testing/selftests/bpf/progs/setget_sockopt.c
index 4a4cb44a4a15..40606ef47a38 100644
--- a/tools/testing/selftests/bpf/progs/setget_sockopt.c
+++ b/tools/testing/selftests/bpf/progs/setget_sockopt.c
@@ -305,15 +305,19 @@ static int bpf_test_tcp_sockopt(__u32 i, struct loop_ctx *lc)
 	if (t->opt == TCP_CONGESTION) {
 		char old_cc[16], tmp_cc[16];
 		const char *new_cc;
+		int new_cc_len;
 
 		if (bpf_getsockopt(ctx, IPPROTO_TCP, TCP_CONGESTION, old_cc, sizeof(old_cc)))
 			return 1;
-		if (!bpf_strncmp(old_cc, sizeof(old_cc), cubic_cc))
+		if (!bpf_strncmp(old_cc, sizeof(old_cc), cubic_cc)) {
 			new_cc = reno_cc;
-		else
+			new_cc_len = sizeof(reno_cc);
+		} else {
 			new_cc = cubic_cc;
+			new_cc_len = sizeof(cubic_cc);
+		}
 		if (bpf_setsockopt(ctx, IPPROTO_TCP, TCP_CONGESTION, (void *)new_cc,
-				   sizeof(new_cc)))
+				   new_cc_len))
 			return 1;
 		if (bpf_getsockopt(ctx, IPPROTO_TCP, TCP_CONGESTION, tmp_cc, sizeof(tmp_cc)))
 			return 1;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt()
  2022-08-24  1:39 [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt() Yang Yingliang
@ 2022-08-24 17:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-24 17:40 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-kernel, linux-kselftest, bpf, sdf, kafai, ast, andrii,
	mykolal

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Wed, 24 Aug 2022 09:39:07 +0800 you wrote:
> sizeof(new_cc) is not real memory size that new_cc point to, introduce
> new_cc_len to store size then pass it to bpf_setsockopt().
> 
> Fixes: 31123c0360e0 ("selftests/bpf: bpf_setsockopt tests")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
>  tools/testing/selftests/bpf/progs/setget_sockopt.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)

Here is the summary with links:
  - [-next] selftests/bpf: fix wrong size passed to bpf_setsockopt()
    https://git.kernel.org/bpf/bpf-next/c/6fc2838b148f

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] 2+ messages in thread

end of thread, other threads:[~2022-08-24 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-24  1:39 [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt() Yang Yingliang
2022-08-24 17:40 ` 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