summaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2026-10-14 23:28:25 +0200
committerChristian Brauner <brauner@kernel.org>2026-10-14 23:28:25 +0200
commit87c03ba403e68d5a0b9bdf483bfef8fad865e91c (patch)
tree252956071920c9b2f9ab2ceb000ebd48683d59da /tools/lib
parent492b4eda7151ad2818ad8d35e5e6cfab62ec2ff7 (diff)
parent503b65da9a7e5447d91222f62399522f2f62a0fa (diff)
downloadlinux-next-87c03ba403e68d5a0b9bdf483bfef8fad865e91c.tar.gz
linux-next-87c03ba403e68d5a0b9bdf483bfef8fad865e91c.zip
Merge branch 'vfs-7.4.keyring' into vfs.all
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/btf.c14
-rw-r--r--tools/lib/bpf/libbpf.c22
-rw-r--r--tools/lib/bpf/libbpf_internal.h4
-rw-r--r--tools/lib/bpf/libbpf_probes.c11
-rw-r--r--tools/lib/bpf/usdt.c4
5 files changed, 37 insertions, 18 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 8417de92d028..c783359977b4 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -3364,7 +3364,7 @@ static int btf_ext_parse_sec_info(struct btf_ext *btf_ext,
{
const struct btf_ext_info_sec *sinfo;
struct btf_ext_info *ext_info;
- __u32 info_left, record_size;
+ __u32 data_left, info_left, record_size;
size_t sec_cnt = 0;
void *info;
@@ -3377,16 +3377,20 @@ static int btf_ext_parse_sec_info(struct btf_ext *btf_ext,
return -EINVAL;
}
- /* The start of the info sec (including the __u32 record_size). */
- info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off;
- info_left = ext_sec->len;
+ if (btf_ext->hdr->hdr_len > btf_ext->data_size)
+ return -EINVAL;
- if (btf_ext->data + btf_ext->data_size < info + ext_sec->len) {
+ data_left = btf_ext->data_size - btf_ext->hdr->hdr_len;
+ if (ext_sec->off > data_left || ext_sec->len > data_left - ext_sec->off) {
pr_debug("%s section (off:%u len:%u) is beyond the end of the ELF section .BTF.ext\n",
ext_sec->desc, ext_sec->off, ext_sec->len);
return -EINVAL;
}
+ /* The start of the info sec (including the __u32 record_size). */
+ info = btf_ext->data + btf_ext->hdr->hdr_len + ext_sec->off;
+ info_left = ext_sec->len;
+
/* At least a record size */
if (info_left < sizeof(__u32)) {
pr_debug(".BTF.ext %s record size not found\n", ext_sec->desc);
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index bfa64ae6c94d..08570422aa14 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -7886,6 +7886,19 @@ static int tracing_multi_mod_fd(struct bpf_program *prog, int *btf_obj_fd)
return 0;
}
+static int libbpf_setup_prog_flags(struct bpf_program *prog, long cookie)
+{
+ enum sec_def_flags def = cookie;
+
+ if (def & SEC_SLEEPABLE)
+ prog->prog_flags |= BPF_F_SLEEPABLE;
+
+ if (def & SEC_XDP_FRAGS)
+ prog->prog_flags |= BPF_F_XDP_HAS_FRAGS;
+
+ return 0;
+}
+
/* this is called as prog->sec_def->prog_prepare_load_fn for libbpf-supported sec_defs */
static int libbpf_prepare_prog_load(struct bpf_program *prog,
struct bpf_prog_load_opts *opts, long cookie)
@@ -7896,12 +7909,6 @@ static int libbpf_prepare_prog_load(struct bpf_program *prog,
if ((def & SEC_EXP_ATTACH_OPT) && !kernel_supports(prog->obj, FEAT_EXP_ATTACH_TYPE))
opts->expected_attach_type = 0;
- if (def & SEC_SLEEPABLE)
- opts->prog_flags |= BPF_F_SLEEPABLE;
-
- if (prog->type == BPF_PROG_TYPE_XDP && (def & SEC_XDP_FRAGS))
- opts->prog_flags |= BPF_F_XDP_HAS_FRAGS;
-
/* special check for usdt to use uprobe_multi link */
if ((def & SEC_USDT) && kernel_supports(prog->obj, FEAT_UPROBE_MULTI_LINK)) {
/* for BPF_TRACE_UPROBE_MULTI, user might want to query expected_attach_type
@@ -10106,6 +10113,7 @@ int bpf_program__clone(struct bpf_program *prog, const struct bpf_prog_load_opts
.prog_type = BPF_PROG_TYPE_##ptype, \
.expected_attach_type = atype, \
.cookie = (long)(flags), \
+ .prog_setup_fn = libbpf_setup_prog_flags, \
.prog_prepare_load_fn = libbpf_prepare_prog_load, \
__VA_ARGS__ \
}
@@ -11745,7 +11753,7 @@ static int perf_event_open_probe(bool uprobe, bool retprobe, const char *name,
errstr(bit));
return bit;
}
- attr.config |= 1 << bit;
+ attr.config |= 1ULL << bit;
}
attr.size = attr_sz;
attr.type = type;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 4c46d34fc055..cb4d96233844 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -77,7 +77,7 @@
#define JUMPTABLES_SEC ".jumptables"
#define BTF_INFO_ENC(kind, kind_flag, vlen) \
- ((!!(kind_flag) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
+ (((__u32)(!!(kind_flag)) << 31) | ((kind) << 24) | ((vlen) & BTF_MAX_VLEN))
#define BTF_TYPE_ENC(name, info, size_or_type) (name), (info), (size_or_type)
#define BTF_INT_ENC(encoding, bits_offset, nr_bits) \
((encoding) << 24 | (bits_offset) << 16 | (nr_bits))
@@ -259,7 +259,7 @@ static inline enum btf_func_linkage btf_func_linkage(const struct btf_type *t)
static inline __u32 btf_type_info(int kind, int vlen, int kflag)
{
- return (kflag << 31) | (kind << 24) | vlen;
+ return ((__u32)kflag << 31) | (kind << 24) | vlen;
}
enum map_def_parts {
diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
index e40819465ddc..5acf0f84a40a 100644
--- a/tools/lib/bpf/libbpf_probes.c
+++ b/tools/lib/bpf/libbpf_probes.c
@@ -62,7 +62,7 @@ static __u32 get_ubuntu_kernel_version(void)
*/
static __u32 get_debian_kernel_version(struct utsname *info)
{
- __u32 major, minor, patch;
+ __u32 major, minor, patch = 0;
char *p;
p = strstr(info->version, "Debian ");
@@ -71,10 +71,13 @@ static __u32 get_debian_kernel_version(struct utsname *info)
return 0;
}
- if (sscanf(p, "Debian %u.%u.%u", &major, &minor, &patch) != 3)
- return 0;
+ if (sscanf(p, "Debian %u.%u.%u", &major, &minor, &patch) == 3)
+ return KERNEL_VERSION(major, minor, patch);
- return KERNEL_VERSION(major, minor, patch);
+ if (sscanf(p, "Debian %u.%u", &major, &minor) == 2)
+ return KERNEL_VERSION(major, minor, patch);
+
+ return 0;
}
__u32 get_kernel_version(void)
diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index 2e56e3ab5b6c..ee9d1b614883 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -608,8 +608,12 @@ static bool has_nop_combo(int fd, long off)
unsigned char nop_combo[11] = {
0x90, 0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00,
};
+ long page_sz = getpagesize();
unsigned char buf[11];
+ /* the kernel can't attach to a nop10 that crosses a page boundary */
+ if ((off + 1) % page_sz + 10 > page_sz)
+ return false;
if (pread(fd, buf, 11, off) != 11)
return false;
return memcmp(buf, nop_combo, 11) == 0;