BPF List
 help / color / mirror / Atom feed
From: Yang Yingliang <yangyingliang@huawei.com>
To: <linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>,
	<bpf@vger.kernel.org>
Cc: <sdf@google.com>, <kafai@fb.com>, <ast@kernel.org>,
	<andrii@kernel.org>, <mykolal@fb.com>
Subject: [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt()
Date: Wed, 24 Aug 2022 09:39:07 +0800	[thread overview]
Message-ID: <20220824013907.380448-1-yangyingliang@huawei.com> (raw)

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


             reply	other threads:[~2022-08-24  1:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  1:39 Yang Yingliang [this message]
2022-08-24 17:40 ` [PATCH -next] selftests/bpf: fix wrong size passed to bpf_setsockopt() patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220824013907.380448-1-yangyingliang@huawei.com \
    --to=yangyingliang@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mykolal@fb.com \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox