From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH bpf v1 4/5] selftests/bpf: Add selftest for PTR_TO_BTF_ID NULL + off case
Date: Sat, 19 Feb 2022 17:07:43 +0530 [thread overview]
Message-ID: <20220219113744.1852259-5-memxor@gmail.com> (raw)
In-Reply-To: <20220219113744.1852259-1-memxor@gmail.com>
While at it, also try breaking bpf_sock_from_file, since it doesn't
check its argument for NULL in the first place. With our fix, both
shouldn't crash.
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
.../selftests/bpf/prog_tests/d_path_crash.c | 19 ++++++++++++++
.../selftests/bpf/progs/d_path_crash.c | 26 +++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/d_path_crash.c
create mode 100644 tools/testing/selftests/bpf/progs/d_path_crash.c
diff --git a/tools/testing/selftests/bpf/prog_tests/d_path_crash.c b/tools/testing/selftests/bpf/prog_tests/d_path_crash.c
new file mode 100644
index 000000000000..b1ee705d2108
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/d_path_crash.c
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "d_path_crash.skel.h"
+
+void test_d_path_crash(void)
+{
+ struct d_path_crash *skel;
+
+ skel = d_path_crash__open_and_load();
+ if (!ASSERT_OK_PTR(skel, "d_path_crash__open_and_load"))
+ return;
+ skel->bss->pid = getpid();
+ ASSERT_OK(d_path_crash__attach(skel), "d_path__attach");
+ close(open("/dev/null", O_RDONLY));
+ d_path_crash__destroy(skel);
+}
diff --git a/tools/testing/selftests/bpf/progs/d_path_crash.c b/tools/testing/selftests/bpf/progs/d_path_crash.c
new file mode 100644
index 000000000000..a4b1a8b200f3
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/d_path_crash.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <vmlinux.h>
+#include <bpf/bpf_tracing.h>
+#include <bpf/bpf_helpers.h>
+
+int pid = 0;
+
+SEC("lsm/file_open")
+int BPF_PROG(lsm_file_open, struct file *file)
+{
+ struct task_struct *current = bpf_get_current_task_btf();
+ unsigned long *val, l;
+ char buf[64] = {};
+ struct file *f;
+
+ if (current->tgid != pid)
+ return 0;
+
+ f = current->files->fd_array[63];
+ bpf_d_path(&f->f_path, buf, sizeof(buf));
+ /* If we survived, let's try our luck here */
+ bpf_sock_from_file(f);
+ return 0;
+}
+
+char _license[] SEC("license") = "GPL";
--
2.35.1
next prev parent reply other threads:[~2022-02-19 11:38 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-19 11:37 [PATCH bpf v1 0/5] More fixes for crashes due to bad PTR_TO_BTF_ID reg->off Kumar Kartikeya Dwivedi
2022-02-19 11:37 ` [PATCH bpf v1 1/5] bpf: Fix kfunc register offset check for PTR_TO_BTF_ID Kumar Kartikeya Dwivedi
2022-02-20 2:24 ` Alexei Starovoitov
2022-02-20 2:49 ` Kumar Kartikeya Dwivedi
2022-02-21 20:36 ` Alexei Starovoitov
2022-02-22 3:31 ` Kumar Kartikeya Dwivedi
2022-02-22 4:21 ` Alexei Starovoitov
2022-02-23 3:16 ` Kumar Kartikeya Dwivedi
2022-02-19 11:37 ` [PATCH bpf v1 2/5] bpf: Restrict PTR_TO_BTF_ID offset to PAGE_SIZE when calling helpers Kumar Kartikeya Dwivedi
2022-02-19 11:37 ` [PATCH bpf v1 3/5] bpf: Use bpf_ptr_is_invalid for all helpers taking PTR_TO_BTF_ID Kumar Kartikeya Dwivedi
2022-02-19 11:37 ` Kumar Kartikeya Dwivedi [this message]
2022-02-19 11:37 ` [PATCH bpf v1 5/5] selftests/bpf: Adjust verifier selftest for updated message Kumar Kartikeya Dwivedi
2022-02-19 12:10 ` [PATCH bpf v1 0/5] More fixes for crashes due to bad PTR_TO_BTF_ID reg->off Kumar Kartikeya Dwivedi
2022-02-20 2:18 ` Alexei Starovoitov
2022-02-20 2:59 ` Kumar Kartikeya Dwivedi
2022-02-21 20:45 ` Alexei Starovoitov
2022-02-22 3:21 ` Kumar Kartikeya Dwivedi
2022-02-22 3:59 ` Alexei Starovoitov
2022-02-20 2:26 ` Alexei Starovoitov
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=20220219113744.1852259-5-memxor@gmail.com \
--to=memxor@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/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