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] [thread-next>] [day] [month] [year] [list]
Date: Tue, 2 Apr 2024 16:14:02 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Jordan Rife <jrife@...gle.com>
Cc: linux-kselftest@...r.kernel.org, netdev@...r.kernel.org,
 Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
 Andrii Nakryiko <andrii@...nel.org>, Eduard Zingerman <eddyz87@...il.com>,
 Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>,
 John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
 Stanislav Fomichev <sdf@...gle.com>, Hao Luo <haoluo@...gle.com>,
 Jiri Olsa <jolsa@...nel.org>, Mykola Lysenko <mykolal@...com>,
 Shuah Khan <shuah@...nel.org>, "David S. Miller" <davem@...emloft.net>,
 Jakub Kicinski <kuba@...nel.org>, Jesper Dangaard Brouer <hawk@...nel.org>,
 Daan De Meyer <daan.j.demeyer@...il.com>, bpf@...r.kernel.org
Subject: Re: [PATCH v1 bpf-next 5/8] selftests/bpf: Factor out load_path and
 defines from test_sock_addr

On 3/29/24 12:18 PM, Jordan Rife wrote:
> diff --git a/tools/testing/selftests/bpf/sock_addr_helpers.c b/tools/testing/selftests/bpf/sock_addr_helpers.c
> new file mode 100644
> index 0000000000000..ff2eb09870f16
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/sock_addr_helpers.c
> @@ -0,0 +1,46 @@
> +// SPDX-License-Identifier: GPL-2.0
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +
> +#include <bpf/bpf.h>
> +#include <bpf/libbpf.h>
> +
> +#include "cgroup_helpers.h"
> +#include "sock_addr_helpers.h"
> +#include "testing_helpers.h"
> +
> +int load_path(const char *path, enum bpf_attach_type attach_type,
> +	      bool expect_reject)
> +{
> +	struct bpf_object *obj;
> +	struct bpf_program *prog;
> +	int err;
> +
> +	obj = bpf_object__open_file(path, NULL);

Although it works, it is heading to the opposite direction by reusing things 
from the older test_sock_addr.c.

test_sock_addr.c should have been moved to the test_progs. It is not run by bpf 
CI and bits get rotten [e.g. the bug fix in patch 8]. There is also old practice 
like bpf_object__open_file() should have been replaced with the skeleton 
__open_and_load() instead of refactoring it out to create new use cases.

The newer prog_tests/sock_addr.c was created when adding AF_UNIX support. It has 
a very similar setup as the older test_sock_addr.c and the intention was to 
finally retire test_sock_addr.c. e.g. It also has "load_fn loadfn" but is done 
with skeleton, the program is also attached to cgroup...etc.

Instead of adding a new sock_addr_kern.c in patch 7, it probably will be easier 
to add the kernel socket tests into the existing prog_tests/sock_addr.c.

Also setup the netns and veth in the prog_tests/sock_addr.c instead of calling 
out the test_sock_addr.sh (which should also go away eventually), there are 
examples in prog_tests/ (e.g. mptcp.c).

> +	err = libbpf_get_error(obj);
> +	if (err) {
> +		log_err(">>> Opening BPF object (%s) error.\n", path);
> +		return -1;
> +	}
> +
> +	prog = bpf_object__next_program(obj, NULL);
> +	if (!prog)
> +		goto err_out;
> +
> +	bpf_program__set_type(prog, BPF_PROG_TYPE_CGROUP_SOCK_ADDR);
> +	bpf_program__set_expected_attach_type(prog, attach_type);
> +	bpf_program__set_flags(prog, testing_prog_flags());
> +
> +	err = bpf_object__load(obj);
> +	if (err) {
> +		if (!expect_reject)
> +			log_err(">>> Loading program (%s) error.\n", path);
> +		goto err_out;
> +	}
> +
> +	return bpf_program__fd(prog);
> +err_out:
> +	bpf_object__close(obj);
> +	return -1;
> +}


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ