All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	martin.lau@linux.dev, song@kernel.org, yhs@fb.com,
	john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com,
	haoluo@google.com, jolsa@kernel.org
Subject: [PATCH bpf-next 4/6] selftests/bpf: Update EFAULT {g,s}etsockopt selftests
Date: Tue, 18 Apr 2023 15:53:41 -0700	[thread overview]
Message-ID: <20230418225343.553806-5-sdf@google.com> (raw)
In-Reply-To: <20230418225343.553806-1-sdf@google.com>

Instead of assuming EFAULT, let's assume the BPF program's
output is ignored.

Remove "getsockopt: deny arbitrary ctx->retval" because it
was actually testing optlen. We have separate set of tests
for retval.

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 .../selftests/bpf/prog_tests/sockopt.c        | 42 ++++++-------------
 1 file changed, 13 insertions(+), 29 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/sockopt.c b/tools/testing/selftests/bpf/prog_tests/sockopt.c
index aa4debf62fc6..bff7d91d1e1d 100644
--- a/tools/testing/selftests/bpf/prog_tests/sockopt.c
+++ b/tools/testing/selftests/bpf/prog_tests/sockopt.c
@@ -249,7 +249,7 @@ static struct sockopt_test {
 		.get_optlen = 64,
 	},
 	{
-		.descr = "getsockopt: deny bigger ctx->optlen",
+		.descr = "getsockopt: ignore bigger ctx->optlen",
 		.insns = {
 			/* ctx->optlen = 65 */
 			BPF_MOV64_IMM(BPF_REG_0, 65),
@@ -268,28 +268,10 @@ static struct sockopt_test {
 		.attach_type = BPF_CGROUP_GETSOCKOPT,
 		.expected_attach_type = BPF_CGROUP_GETSOCKOPT,
 
-		.get_optlen = 64,
-
-		.error = EFAULT_GETSOCKOPT,
-	},
-	{
-		.descr = "getsockopt: deny arbitrary ctx->retval",
-		.insns = {
-			/* ctx->retval = 123 */
-			BPF_MOV64_IMM(BPF_REG_0, 123),
-			BPF_STX_MEM(BPF_W, BPF_REG_1, BPF_REG_0,
-				    offsetof(struct bpf_sockopt, retval)),
-
-			/* return 1 */
-			BPF_MOV64_IMM(BPF_REG_0, 1),
-			BPF_EXIT_INSN(),
-		},
-		.attach_type = BPF_CGROUP_GETSOCKOPT,
-		.expected_attach_type = BPF_CGROUP_GETSOCKOPT,
-
-		.get_optlen = 64,
-
-		.error = EFAULT_GETSOCKOPT,
+		.get_level = SOL_IP,
+		.get_optname = IP_TOS,
+		.get_optval = {},
+		.get_optlen = 4,
 	},
 	{
 		.descr = "getsockopt: support smaller ctx->optlen",
@@ -627,9 +609,10 @@ static struct sockopt_test {
 		.attach_type = BPF_CGROUP_SETSOCKOPT,
 		.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
 
-		.set_optlen = 4,
-
-		.error = EFAULT_SETSOCKOPT,
+		.set_level = SOL_IP,
+		.set_optname = IP_TOS,
+		.set_optval = { 1 << 3 },
+		.set_optlen = 1,
 	},
 	{
 		.descr = "setsockopt: deny ctx->optlen > input optlen",
@@ -644,9 +627,10 @@ static struct sockopt_test {
 		.attach_type = BPF_CGROUP_SETSOCKOPT,
 		.expected_attach_type = BPF_CGROUP_SETSOCKOPT,
 
-		.set_optlen = 64,
-
-		.error = EFAULT_SETSOCKOPT,
+		.set_level = SOL_IP,
+		.set_optname = IP_TOS,
+		.set_optval = { 1 << 3 },
+		.set_optlen = 1,
 	},
 	{
 		.descr = "setsockopt: allow changing ctx->optlen within bounds",
-- 
2.40.0.634.g4ca3ef3211-goog


  parent reply	other threads:[~2023-04-18 22:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 22:53 [PATCH bpf-next 0/6] bpf: handle another corner case in getsockopt Stanislav Fomichev
2023-04-18 22:53 ` [PATCH bpf-next 1/6] bpf: Don't EFAULT for getsockopt with optval=NULL Stanislav Fomichev
2023-04-18 22:53 ` [PATCH bpf-next 2/6] selftests/bpf: Verify optval=NULL case Stanislav Fomichev
2023-04-18 22:53 ` [PATCH bpf-next 3/6] bpf: Don't EFAULT for {g,s}setsockopt with wrong optlen Stanislav Fomichev
2023-04-21 15:24   ` Daniel Borkmann
2023-04-21 16:09     ` Stanislav Fomichev
2023-04-25  0:56       ` Martin KaFai Lau
2023-04-25 17:12         ` Stanislav Fomichev
2023-04-25 18:31           ` Martin KaFai Lau
2023-04-26 17:27             ` Stanislav Fomichev
2023-04-26 18:07               ` Martin KaFai Lau
2023-04-18 22:53 ` Stanislav Fomichev [this message]
2023-04-18 22:53 ` [PATCH bpf-next 5/6] selftests/bpf: Correctly handle optlen > 4096 Stanislav Fomichev
2023-04-18 22:53 ` [PATCH bpf-next 6/6] bpf: Document EFAULT changes for sockopt Stanislav Fomichev
2023-04-19 20:08   ` kernel test robot
2023-04-20 18:17     ` Stanislav Fomichev
2023-04-21 15:20 ` [PATCH bpf-next 0/6] bpf: handle another corner case in getsockopt 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=20230418225343.553806-5-sdf@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=song@kernel.org \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.