From: Martin KaFai Lau <martin.lau@linux.dev>
To: Stanislav Fomichev <sdf@google.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, song@kernel.org, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, haoluo@google.com,
jolsa@kernel.org
Subject: Re: [PATCH bpf-next 2/2] selftests/bpf: Make sure zero-len skbs aren't redirectable
Date: Wed, 16 Nov 2022 12:38:13 -0800 [thread overview]
Message-ID: <b5540340-85a7-6809-5f37-1509bbf9a142@linux.dev> (raw)
In-Reply-To: <20221115031031.3281094-2-sdf@google.com>
On 11/14/22 7:10 PM, Stanislav Fomichev wrote:
> LWT_XMIT to test L3 case, TC to test L2 case.
It will be useful to add more details here to explain which test is testing the
skb->len check in __bpf_redirect_no_mac() and __bpf_redirect_common() in patch 1.
>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
> .../selftests/bpf/prog_tests/empty_skb.c | 140 ++++++++++++++++++
> tools/testing/selftests/bpf/progs/empty_skb.c | 37 +++++
> 2 files changed, 177 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/empty_skb.c
> create mode 100644 tools/testing/selftests/bpf/progs/empty_skb.c
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/empty_skb.c b/tools/testing/selftests/bpf/prog_tests/empty_skb.c
> new file mode 100644
> index 000000000000..6e35739babed
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/empty_skb.c
> @@ -0,0 +1,140 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <test_progs.h>
> +#include <network_helpers.h>
> +#include <net/if.h>
> +#include "empty_skb.skel.h"
> +
> +#define SYS(cmd) ({ \
> + if (!ASSERT_OK(system(cmd), (cmd))) \
> + goto out; \
> +})
> +
> +void test_empty_skb(void)
> +{
> + LIBBPF_OPTS(bpf_test_run_opts, tattr);
> + struct empty_skb *bpf_obj = NULL;
> + struct nstoken *tok = NULL;
> + struct bpf_program *prog;
> + char eth_hlen_pp[15];
> + char eth_hlen[14];
> + int veth_ifindex;
> + int ipip_ifindex;
> + int err;
> + int i;
> +
> + struct {
> + const char *msg;
> + const void *data_in;
> + __u32 data_size_in;
> + int *ifindex;
> + int err;
> + int ret;
> + bool success_on_tc;
> + } tests[] = {
> + /* Empty packets are always rejected. */
> +
> + {
> + .msg = "veth empty ingress packet",
> + .data_in = NULL,
> + .data_size_in = 0,
> + .ifindex = &veth_ifindex,
> + .err = -EINVAL,
> + },
> + {
> + .msg = "ipip empty ingress packet",
> + .data_in = NULL,
> + .data_size_in = 0,
> + .ifindex = &ipip_ifindex,
> + .err = -EINVAL,
> + },
> +
> + /* ETH_HLEN-sized packets:
> + * - can not be redirected at LWT_XMIT
> + * - can be redirected at TC
> + */
> +
> + {
> + .msg = "veth ETH_HLEN packet ingress",
> + .data_in = eth_hlen,
> + .data_size_in = sizeof(eth_hlen),
> + .ifindex = &veth_ifindex,
> + .ret = -ERANGE,
> + .success_on_tc = true,
> + },
> + {
> + .msg = "ipip ETH_HLEN packet ingress",
> + .data_in = eth_hlen,
> + .data_size_in = sizeof(eth_hlen),
> + .ifindex = &veth_ifindex,
> + .ret = -ERANGE,
> + .success_on_tc = true,
> + },
hmm... these two tests don't look right. They are the same except the ".msg"
part. The latter one should use &ipip_ifindex?
> +
> + /* ETH_HLEN+1-sized packet should be redirected. */
> +
> + {
> + .msg = "veth ETH_HLEN+1 packet ingress",
> + .data_in = eth_hlen_pp,
> + .data_size_in = sizeof(eth_hlen_pp),
> + .ifindex = &veth_ifindex,
> + },
> + {
> + .msg = "ipip ETH_HLEN+1 packet ingress",
> + .data_in = eth_hlen_pp,
> + .data_size_in = sizeof(eth_hlen_pp),
> + .ifindex = &veth_ifindex,
> + },
Same here.
next prev parent reply other threads:[~2022-11-16 20:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 3:10 [PATCH bpf-next 1/2] bpf: Move skb->len == 0 checks into __bpf_redirect Stanislav Fomichev
2022-11-15 3:10 ` [PATCH bpf-next 2/2] selftests/bpf: Make sure zero-len skbs aren't redirectable Stanislav Fomichev
2022-11-16 20:38 ` Martin KaFai Lau [this message]
2022-11-16 21:02 ` Stanislav Fomichev
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=b5540340-85a7-6809-5f37-1509bbf9a142@linux.dev \
--to=martin.lau@linux.dev \
--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=sdf@google.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox