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]
Message-ID: <1663555725-17016-2-git-send-email-wangyufen@huawei.com>
Date:   Mon, 19 Sep 2022 10:48:45 +0800
From:   Wang Yufen <wangyufen@...wei.com>
To:     <andrii@...nel.org>, <ast@...nel.org>, <daniel@...earbox.net>,
        <martin.lau@...ux.dev>, <song@...nel.org>, <yhs@...com>,
        <john.fastabend@...il.com>, <kpsingh@...nel.org>, <sdf@...gle.com>,
        <haoluo@...gle.com>, <jolsa@...nel.org>,
        <paul.walmsley@...ive.com>, <palmer@...belt.com>,
        <aou@...s.berkeley.edu>, <davem@...emloft.net>, <kuba@...nel.org>,
        <hawk@...nel.org>, <nathan@...nel.org>, <ndesaulniers@...gle.com>,
        <trix@...hat.com>
CC:     <bpf@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
        <netdev@...r.kernel.org>, <llvm@...ts.linux.dev>
Subject: [bpf-next v3 2/2] selftests/bpf: Add testcases for pinning to errpath

Add testcases for map and prog pin to errpath.

Signed-off-by: Wang Yufen <wangyufen@...wei.com>
---
 tools/testing/selftests/bpf/prog_tests/pinning.c   | 67 ++++++++++++++++++++++
 .../selftests/bpf/progs/test_pinning_path.c        | 19 ++++++
 2 files changed, 86 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/test_pinning_path.c

diff --git a/tools/testing/selftests/bpf/prog_tests/pinning.c b/tools/testing/selftests/bpf/prog_tests/pinning.c
index d95cee5..ab7780f 100644
--- a/tools/testing/selftests/bpf/prog_tests/pinning.c
+++ b/tools/testing/selftests/bpf/prog_tests/pinning.c
@@ -24,6 +24,61 @@ __u32 get_map_id(struct bpf_object *obj, const char *name)
 	return map_info.id;
 }
 
+static void test_pin_path(void)
+{
+	const char *progfile = "./test_pinning_path.bpf.o";
+	const char *progpinpath = "/sys/fs/bpf/test_pinpath";
+	char errpath[PATH_MAX + 1];
+	char command[64];
+	int prog_fd, err;
+	struct bpf_object *obj;
+	__u32 duration = 0;
+
+	/* Use libbpf 1.0 API mode */
+	libbpf_set_strict_mode(LIBBPF_STRICT_ALL);
+
+	err = bpf_prog_test_load(progfile, BPF_PROG_TYPE_SOCK_OPS, &obj,
+				 &prog_fd);
+	CHECK(err, "bpf_prog_test_load", "err %d errno %d\n", err, errno);
+
+	memset(&errpath, 't', PATH_MAX);
+	err = bpf_object__pin_maps(obj, errpath);
+	if (CHECK(err != -ENAMETOOLONG, "pin maps errpath", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__pin_maps(obj, progpinpath);
+	if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__pin_programs(obj, errpath);
+	if (CHECK(err != -ENAMETOOLONG, "pin progs errpath", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__pin_programs(obj, progpinpath);
+	if (CHECK(err, "pin prog", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__unpin_programs(obj, errpath);
+	if (CHECK(err != -ENAMETOOLONG, "pin progs errpath", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__unpin_programs(obj, progpinpath);
+	if (CHECK(err, "pin prog", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__unpin_maps(obj, errpath);
+	if (CHECK(err != -ENAMETOOLONG, "pin maps errpath", "err %d errno %d\n", err, errno))
+		goto out;
+
+	err = bpf_object__unpin_maps(obj, progpinpath);
+	if (CHECK(err, "pin maps", "err %d errno %d\n", err, errno))
+		goto out;
+out:
+	bpf_object__close(obj);
+	sprintf(command, "rm -r %s", progpinpath);
+	system(command);
+}
+
 void test_pinning(void)
 {
 	const char *file_invalid = "./test_pinning_invalid.bpf.o";
@@ -32,6 +87,7 @@ void test_pinning(void)
 	const char *nopinpath2 = "/sys/fs/bpf/nopinmap2";
 	const char *custpath = "/sys/fs/bpf/custom";
 	const char *pinpath = "/sys/fs/bpf/pinmap";
+	char errpath[PATH_MAX + 1];
 	const char *file = "./test_pinning.bpf.o";
 	__u32 map_id, map_id2, duration = 0;
 	struct stat statbuf = {};
@@ -206,7 +262,17 @@ void test_pinning(void)
 
 	bpf_object__close(obj);
 
+	/* test auto-pinning at err path with open opt */
+	memset(&errpath, 't', PATH_MAX);
+	opts.pin_root_path = errpath;
+	obj = bpf_object__open_file(file, &opts);
+	if (CHECK_FAIL(libbpf_get_error(obj) != -ENAMETOOLONG)) {
+		obj = NULL;
+		goto out;
+	}
+
 	/* test auto-pinning at custom path with open opt */
+	opts.pin_root_path = custpath;
 	obj = bpf_object__open_file(file, &opts);
 	if (CHECK_FAIL(libbpf_get_error(obj))) {
 		obj = NULL;
@@ -277,4 +343,5 @@ void test_pinning(void)
 	rmdir(custpath);
 	if (obj)
 		bpf_object__close(obj);
+	test_pin_path();
 }
diff --git a/tools/testing/selftests/bpf/progs/test_pinning_path.c b/tools/testing/selftests/bpf/progs/test_pinning_path.c
new file mode 100644
index 0000000..b4e2099
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_pinning_path.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+
+struct {
+	__uint(type, BPF_MAP_TYPE_SOCKHASH);
+	__uint(max_entries, 64);
+	__type(key, __u32);
+	__type(value, __u64);
+} sock_ops_map SEC(".maps");
+
+SEC("sockops")
+int bpf_sockmap(struct bpf_sock_ops *skops)
+{
+	return 0;
+}
+
+char _license[] SEC("license") = "GPL";
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ