From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: [PATCHv2 bpf-next 1/2] bpf: Add bpf_vma_build_id_parse function and kfunc
Date: Fri, 11 Nov 2022 15:33:40 +0100 [thread overview]
Message-ID: <20221111143341.508022-2-jolsa@kernel.org> (raw)
In-Reply-To: <20221111143341.508022-1-jolsa@kernel.org>
Adding bpf_vma_build_id_parse function to retrieve build id from
passed vma object and making it available as bpf kfunc.
We can't use build_id_parse directly as kfunc, because we would
not have control over the build id buffer size provided by user.
Instead we are adding new bpf_vma_build_id_parse function with
'build_id__sz' argument that instructs verifier to check for the
available space in build_id buffer.
This way we check that there's always available memory space
behind build_id pointer. We also check that the build_id__sz is
at least BUILD_ID_SIZE_MAX so we can place any buildid in.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/linux/bpf.h | 5 +++++
kernel/bpf/helpers.c | 16 ++++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index 798aec816970..5e7c4c50da8e 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -2779,4 +2779,9 @@ struct bpf_key {
bool has_ref;
};
#endif /* CONFIG_KEYS */
+
+extern int bpf_vma_build_id_parse(struct vm_area_struct *vma,
+ unsigned char *build_id,
+ size_t build_id__sz);
+
#endif /* _LINUX_BPF_H */
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index 283f55bbeb70..af7a30dafff3 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -19,6 +19,7 @@
#include <linux/proc_ns.h>
#include <linux/security.h>
#include <linux/btf_ids.h>
+#include <linux/buildid.h>
#include "../../lib/kstrtox.h"
@@ -1706,10 +1707,25 @@ bpf_base_func_proto(enum bpf_func_id func_id)
}
}
+int bpf_vma_build_id_parse(struct vm_area_struct *vma,
+ unsigned char *build_id,
+ size_t build_id__sz)
+{
+ __u32 size;
+ int err;
+
+ if (build_id__sz < BUILD_ID_SIZE_MAX)
+ return -EINVAL;
+
+ err = build_id_parse(vma, build_id, &size);
+ return err ?: (int) size;
+}
+
BTF_SET8_START(tracing_btf_ids)
#ifdef CONFIG_KEXEC_CORE
BTF_ID_FLAGS(func, crash_kexec, KF_DESTRUCTIVE)
#endif
+BTF_ID_FLAGS(func, bpf_vma_build_id_parse)
BTF_SET8_END(tracing_btf_ids)
static const struct btf_kfunc_id_set tracing_kfunc_set = {
--
2.38.1
next prev parent reply other threads:[~2022-11-11 14:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-11 14:33 [PATCHv2 bpf-next 0/2] bpf: Add bpf_vma_build_id_parse kfunc Jiri Olsa
2022-11-11 14:33 ` Jiri Olsa [this message]
2022-11-14 17:40 ` [PATCHv2 bpf-next 1/2] bpf: Add bpf_vma_build_id_parse function and kfunc Alexei Starovoitov
2022-11-14 18:42 ` Song Liu
2022-11-14 21:47 ` Jiri Olsa
2022-11-11 14:33 ` [PATCHv2 bpf-next 2/2] selftests/bpf: Add bpf_vma_build_id_parse kfunc test Jiri Olsa
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=20221111143341.508022-2-jolsa@kernel.org \
--to=jolsa@kernel.org \
--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=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--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