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: <20210310040431.916483-3-andrii@kernel.org>
Date:   Tue, 9 Mar 2021 20:04:23 -0800
From:   Andrii Nakryiko <andrii@...nel.org>
To:     <bpf@...r.kernel.org>, <netdev@...r.kernel.org>, <ast@...com>,
        <daniel@...earbox.net>
CC:     <andrii@...nel.org>, <kernel-team@...com>
Subject: [PATCH bpf-next 02/10] libbpf: add internal helper to get raw BTF strings section

struct btf is an efficient and convenient data structure to be used as a set
of deduplicated strings. This patch adds libbpf-internal btf_raw_str() helper
that gives access to strings section raw data (regardless of whether BTF
object is read-only or writeable) and its size in bytes. This is going to be
used by bpf_linker to implement ELF string table section.

Signed-off-by: Andrii Nakryiko <andrii@...nel.org>
---
 tools/lib/bpf/btf.c             | 11 +++++++++++
 tools/lib/bpf/libbpf_internal.h |  1 +
 2 files changed, 12 insertions(+)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index e0b0a78b04fe..6ee82ffcf3ff 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1296,6 +1296,17 @@ static void *btf_get_raw_data(const struct btf *btf, __u32 *size, bool swap_endi
 	return NULL;
 }
 
+/*
+ * Internal helper to get the size and direct pointer to strings section.
+ * This is used in cases where struct btf is used as an efficient and
+ * convenient strings container (e.g., bpf_linker).
+ */
+const void *btf_raw_strs(const struct btf *btf, size_t *size)
+{
+	*size = btf->hdr->str_len;
+	return btf->strs_data;
+}
+
 const void *btf__get_raw_data(const struct btf *btf_ro, __u32 *size)
 {
 	struct btf *btf = (struct btf *)btf_ro;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index d09860e435c8..069250e8e871 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -115,6 +115,7 @@ struct btf_type *btf_type_by_id(struct btf *btf, __u32 type_id);
 void *btf_add_mem(void **data, size_t *cap_cnt, size_t elem_sz,
 		  size_t cur_cnt, size_t max_cnt, size_t add_cnt);
 int btf_ensure_mem(void **data, size_t *cap_cnt, size_t elem_sz, size_t need_cnt);
+const void *btf_raw_strs(const struct btf *btf, size_t *size);
 
 static inline bool libbpf_validate_opts(const char *opts,
 					size_t opts_sz, size_t user_sz,
-- 
2.24.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ