]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
libbpf: Add OPTS_VALID() for log_opts in bpf_map_create
authorLeon Hwang <leon.hwang@linux.dev>
Mon, 18 May 2026 14:54:44 +0000 (22:54 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 19 May 2026 01:51:32 +0000 (18:51 -0700)
There should be an OPTS_VALID() check for log_opts before extracting its
fields.

If no such OPTS_VALID() check and an application compiled against a future
libbpf header passes a log_opts with new, non-zero fields to libbpf.so,
those fields will be ignored silently.

Fixes: 702259006f93 ("libbpf: Add syscall common attributes support for map_create")
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20260518145446.6794-4-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/bpf.c

index 483c02cf21d1fb2ba23744866eeacfb878b404fc..3cd705802330450abf8eb12beb88dafb87e353e7 100644 (file)
@@ -246,6 +246,9 @@ int bpf_map_create(enum bpf_map_type map_type,
        attr.excl_prog_hash_size = OPTS_GET(opts, excl_prog_hash_size, 0);
 
        log_opts = OPTS_GET(opts, log_opts, NULL);
+       if (!OPTS_VALID(log_opts, bpf_log_opts))
+               return libbpf_err(-EINVAL);
+
        if (log_opts && feat_supported(NULL, FEAT_BPF_SYSCALL_COMMON_ATTRS)) {
                memset(&attr_common, 0, attr_common_sz);
                attr_common.log_buf = ptr_to_u64(OPTS_GET(log_opts, buf, NULL));