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 <[email protected]>
---
tools/lib/bpf/bpf.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 483c02cf21d1..3cd705802330 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -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));
--
2.54.0