lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZttqIOKR9Khhw0H7@mini-arch>
Date: Fri, 6 Sep 2024 13:46:24 -0700
From: Stanislav Fomichev <stfomichev@...il.com>
To: Florian Kauer <florian.kauer@...utronix.de>
Cc: Alexei Starovoitov <ast@...nel.org>,
	Daniel Borkmann <daniel@...earbox.net>,
	"David S. Miller" <davem@...emloft.net>,
	Jakub Kicinski <kuba@...nel.org>,
	Jesper Dangaard Brouer <hawk@...nel.org>,
	John Fastabend <john.fastabend@...il.com>,
	Andrii Nakryiko <andrii@...nel.org>,
	Martin KaFai Lau <martin.lau@...ux.dev>,
	Eduard Zingerman <eddyz87@...il.com>, Song Liu <song@...nel.org>,
	Yonghong Song <yonghong.song@...ux.dev>,
	KP Singh <kpsingh@...nel.org>, Hao Luo <haoluo@...gle.com>,
	Jiri Olsa <jolsa@...nel.org>,
	Toke Høiland-Jørgensen <toke@...hat.com>,
	David Ahern <dsahern@...nel.org>,
	Hangbin Liu <liuhangbin@...il.com>, Mykola Lysenko <mykolal@...com>,
	Shuah Khan <shuah@...nel.org>, netdev@...r.kernel.org,
	bpf@...r.kernel.org, linux-kernel@...r.kernel.org,
	Jesper Dangaard Brouer <brouer@...hat.com>,
	linux-kselftest@...r.kernel.org
Subject: Re: [PATCH net v2 2/2] bpf: selftests: send packet to devmap
 redirect XDP

On 09/06, Stanislav Fomichev wrote:
> On 09/06, Florian Kauer wrote:
> > The current xdp_devmap_attach test attaches a program
> > that redirects to another program via devmap.
> > 
> > It is, however, never executed, so do that to catch
> > any bugs that might occur during execution.
> > 
> > Also, execute the same for a veth pair so that we
> > also cover the non-generic path.
> > 
> > Warning: Running this without the bugfix in this series
> > will likely crash your system.
> > 
> > Signed-off-by: Florian Kauer <florian.kauer@...utronix.de>
> > ---
> >  .../selftests/bpf/prog_tests/xdp_devmap_attach.c   | 114 +++++++++++++++++++--
> >  1 file changed, 108 insertions(+), 6 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
> > index ce6812558287..c9034f8ae63b 100644
> > --- a/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
> > +++ b/tools/testing/selftests/bpf/prog_tests/xdp_devmap_attach.c
> > @@ -1,6 +1,9 @@
> >  // SPDX-License-Identifier: GPL-2.0
> > +#include <arpa/inet.h>
> >  #include <uapi/linux/bpf.h>
> >  #include <linux/if_link.h>
> > +#include <network_helpers.h>
> > +#include <net/if.h>
> >  #include <test_progs.h>
> >  
> >  #include "test_xdp_devmap_helpers.skel.h"
> > @@ -17,7 +20,7 @@ static void test_xdp_with_devmap_helpers(void)
> >  		.ifindex = IFINDEX_LO,
> >  	};
> >  	__u32 len = sizeof(info);
> > -	int err, dm_fd, map_fd;
> > +	int err, dm_fd, dm_fd_redir, map_fd;
> >  	__u32 idx = 0;
> >  
> >  
> > @@ -25,14 +28,11 @@ static void test_xdp_with_devmap_helpers(void)
> >  	if (!ASSERT_OK_PTR(skel, "test_xdp_with_devmap_helpers__open_and_load"))
> >  		return;
> >  
> > -	dm_fd = bpf_program__fd(skel->progs.xdp_redir_prog);
> > -	err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
> > +	dm_fd_redir = bpf_program__fd(skel->progs.xdp_redir_prog);
> > +	err = bpf_xdp_attach(IFINDEX_LO, dm_fd_redir, XDP_FLAGS_SKB_MODE, NULL);
> >  	if (!ASSERT_OK(err, "Generic attach of program with 8-byte devmap"))
> >  		goto out_close;
> >  
> > -	err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
> > -	ASSERT_OK(err, "XDP program detach");
> > -
> >  	dm_fd = bpf_program__fd(skel->progs.xdp_dummy_dm);
> >  	map_fd = bpf_map__fd(skel->maps.dm_ports);
> >  	err = bpf_prog_get_info_by_fd(dm_fd, &info, &len);
> > @@ -47,6 +47,23 @@ static void test_xdp_with_devmap_helpers(void)
> >  	ASSERT_OK(err, "Read devmap entry");
> >  	ASSERT_EQ(info.id, val.bpf_prog.id, "Match program id to devmap entry prog_id");
> >  
> > +	/* send a packet to trigger any potential bugs in there */
> > +	char data[10] = {};
> > +	DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts,
> > +			    .data_in = &data,
> > +			    .data_size_in = 10,
> > +			    .flags = BPF_F_TEST_XDP_LIVE_FRAMES,
> > +			    .repeat = 1,
> > +		);
> > +	err = bpf_prog_test_run_opts(dm_fd_redir, &opts);
> > +	ASSERT_OK(err, "XDP test run");
> > +
> > +	/* wait for the packets to be flushed */
> > +	kern_sync_rcu();
> > +
> > +	err = bpf_xdp_detach(IFINDEX_LO, XDP_FLAGS_SKB_MODE, NULL);
> > +	ASSERT_OK(err, "XDP program detach");
> > +
> >  	/* can not attach BPF_XDP_DEVMAP program to a device */
> >  	err = bpf_xdp_attach(IFINDEX_LO, dm_fd, XDP_FLAGS_SKB_MODE, NULL);
> >  	if (!ASSERT_NEQ(err, 0, "Attach of BPF_XDP_DEVMAP program"))
> > @@ -124,6 +141,88 @@ static void test_xdp_with_devmap_frags_helpers(void)
> >  	test_xdp_with_devmap_frags_helpers__destroy(skel);
> >  }
> >  
> > +static void test_xdp_with_devmap_helpers_veth(void)
> > +{
> > +	struct test_xdp_with_devmap_helpers *skel;
> 
> skel needs to be initialized to NULL ....
> 
> > +	struct bpf_prog_info info = {};
> > +	struct bpf_devmap_val val = {};
> > +	struct nstoken *nstoken = NULL;
> > +	__u32 len = sizeof(info);
> > +	int err, dm_fd, dm_fd_redir, map_fd, ifindex_dst;
> > +	__u32 idx = 0;
> > +
> > +	SYS(out_close, "ip netns add testns");
> > +	nstoken = open_netns("testns");
> > +	if (!ASSERT_OK_PTR(nstoken, "setns"))
> > +		goto out_close;
> 
> ... for this goto to not do test_xdp_with_devmap_helpers__destroy(garbage)
> 
> pw-bot: cr

Ignore everything below and sorry for the spam.
(NIPA doesn't like DKIM on my sdf@...ichev.me, let's see whether it
works from plain gmail.com)

pw-bot: cr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ