netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Sitnicki <jakub@cloudflare.com>
To: John Fastabend <john.fastabend@gmail.com>
Cc: kuniyu@amazon.com, edumazet@google.com, bpf@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [PATCH bpf 2/2] bpf: sockmap, test for unconnected af_unix sock
Date: Fri, 01 Dec 2023 10:39:20 +0100	[thread overview]
Message-ID: <87edg62rcc.fsf@cloudflare.com> (raw)
In-Reply-To: <20231201032316.183845-3-john.fastabend@gmail.com>

On Thu, Nov 30, 2023 at 07:23 PM -08, John Fastabend wrote:
> Add test to sockmap_basic to ensure af_unix sockets that are not connected
> can not be added to the map. Ensure we keep DGRAM sockets working however
> as these will not be connected typically.
>
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---
>  .../selftests/bpf/prog_tests/sockmap_basic.c  | 34 +++++++++++++++++++
>  1 file changed, 34 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> index f75f84d0b3d7..ad96f4422def 100644
> --- a/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_basic.c
> @@ -524,6 +524,37 @@ static void test_sockmap_skb_verdict_peek(void)
>  	test_sockmap_pass_prog__destroy(pass);
>  }
>  
> +static void test_sockmap_unconnected_unix(void)
> +{
> +	int err, map, stream = 0, dgram = 0, zero = 0;
> +	struct test_sockmap_pass_prog *skel;
> +
> +	skel = test_sockmap_pass_prog__open_and_load();
> +	if (!ASSERT_OK_PTR(skel, "open_and_load"))
> +		return;
> +
> +	map = bpf_map__fd(skel->maps.sock_map_rx);
> +
> +	stream = xsocket(AF_UNIX, SOCK_STREAM, 0);
> +	if (!ASSERT_GT(stream, -1, "socket(AF_UNIX, SOCK_STREAM)"))
> +		return;

Isn't it redudant to use both the xsocket wrapper and ASSERT_* macro?
Or is there some debugging value that comes from that, which I missed?

> +
> +	dgram = xsocket(AF_UNIX, SOCK_DGRAM, 0);
> +	if (!ASSERT_GT(dgram, -1, "socket(AF_UNIX, SOCK_DGRAM)")) {
> +		close(stream);
> +		return;
> +	}
> +
> +	err = bpf_map_update_elem(map, &zero, &stream, BPF_ANY);
> +	ASSERT_ERR(err, "bpf_map_update_elem(stream)");
> +
> +	err = bpf_map_update_elem(map, &zero, &dgram, BPF_ANY);
> +	ASSERT_OK(err, "bpf_map_update_elem(dgram)");
> +
> +	close(stream);
> +	close(dgram);
> +}
> +
>  void test_sockmap_basic(void)
>  {
>  	if (test__start_subtest("sockmap create_update_free"))
> @@ -566,4 +597,7 @@ void test_sockmap_basic(void)
>  		test_sockmap_skb_verdict_fionread(false);
>  	if (test__start_subtest("sockmap skb_verdict msg_f_peek"))
>  		test_sockmap_skb_verdict_peek();
> +
> +	if (test__start_subtest("sockmap unconnected af_unix"))
> +		test_sockmap_unconnected_unix();
>  }


  reply	other threads:[~2023-12-01  9:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-01  3:23 [PATCH bpf 0/2] bpf fix for unconnect af_unix socket John Fastabend
2023-12-01  3:23 ` [PATCH bpf 1/2] bpf: syzkaller found null ptr deref in unix_bpf proto add John Fastabend
2023-12-01  9:24   ` Eric Dumazet
2023-12-01  9:35     ` Jakub Sitnicki
2023-12-01 15:36       ` John Fastabend
2023-12-01  3:23 ` [PATCH bpf 2/2] bpf: sockmap, test for unconnected af_unix sock John Fastabend
2023-12-01  9:39   ` Jakub Sitnicki [this message]
2023-12-01 16:35     ` John Fastabend

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=87edg62rcc.fsf@cloudflare.com \
    --to=jakub@cloudflare.com \
    --cc=bpf@vger.kernel.org \
    --cc=edumazet@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).