Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

bpf: Add cookie object to bpf maps

Add a cookie to BPF maps to uniquely identify BPF maps for the timespan
when the node is up. This is different to comparing a pointer or BPF map
id which could get rolled over and reused.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/r/20250730234733.530041-1-daniel@iogearbox.net
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Daniel Borkmann and committed by
Alexei Starovoitov
12df58ad d6084bb8

+7
+1
include/linux/bpf.h
··· 310 310 bool free_after_rcu_gp; 311 311 atomic64_t sleepable_refcnt; 312 312 s64 __percpu *elem_count; 313 + u64 cookie; /* write-once */ 313 314 }; 314 315 315 316 static inline const char *btf_field_type_name(enum btf_field_type type)
+6
kernel/bpf/syscall.c
··· 37 37 #include <linux/trace_events.h> 38 38 #include <linux/tracepoint.h> 39 39 #include <linux/overflow.h> 40 + #include <linux/cookie.h> 40 41 41 42 #include <net/netfilter/nf_bpf_link.h> 42 43 #include <net/netkit.h> ··· 54 53 #define BPF_OBJ_FLAG_MASK (BPF_F_RDONLY | BPF_F_WRONLY) 55 54 56 55 DEFINE_PER_CPU(int, bpf_prog_active); 56 + DEFINE_COOKIE(bpf_map_cookie); 57 57 static DEFINE_IDR(prog_idr); 58 58 static DEFINE_SPINLOCK(prog_idr_lock); 59 59 static DEFINE_IDR(map_idr); ··· 1488 1486 sizeof(attr->map_name)); 1489 1487 if (err < 0) 1490 1488 goto free_map; 1489 + 1490 + preempt_disable(); 1491 + map->cookie = gen_cookie_next(&bpf_map_cookie); 1492 + preempt_enable(); 1491 1493 1492 1494 atomic64_set(&map->refcnt, 1); 1493 1495 atomic64_set(&map->usercnt, 1);