linux/include
Justin Suess a3a81d2476 bpf: Cancel special fields on map value recycle
Map update and delete paths currently call bpf_obj_free_fields() when a
value is being replaced or recycled. That makes field destruction depend
on the context of the update/delete operation. For tracing programs this
can include NMI context, where referenced kptr destructors, uptr
unpinning, and graph root destruction are not generally safe.

Introduce bpf_obj_cancel_fields() for the reusable-value path. It only
performs NMI-safe cleanup for timer, workqueue, and task_work fields.
Fields that need full destruction are left attached to the recycled value
and are destroyed by the final cleanup path instead.

Switch array and hashtab update/delete/recycle paths to this cancel
helper. Keep bpf_obj_free_fields() for final map destruction and for
bpf_mem_alloc destructors. Preallocated hashtabs do not have allocator
destructors, so teardown continues to walk the normal and extra elements
and fully destroy their fields.

This deliberately relaxes the eager-free semantics of map update/delete
for special fields. Programs that relied on a recycled map slot becoming
empty immediately after update/delete were relying on behavior that
cannot be implemented safely from every BPF execution context without
offloading arbitrary destructors.

There is a chance this change breaks programs making assumptions
regarding the eager freeing of fields. If so, we can relax semantics to
cancellation only when irqs_disabled() is true in the future. However,
theoretically, map values that get reused eagerly already have weaker
guarantees as parallel users can recreate freed fields before the new
element becomes visible again.

Fixes: 14a324f6a6 ("bpf: Wire up freeing of referenced kptr")
Signed-off-by: Justin Suess <utilityemal77@gmail.com>
Co-developed-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20260609202548.3571690-3-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
History 2026-06-09 21:23:11 -07:00
..
acpi Merge branches 'acpi-apei', 'acpi-bus', 'acpi-cppc' and 'acpi-video' 2026-04-30 21:07:06 +02:00
asm-generic ring-buffer: Flush and stop persistent ring buffer on panic 2026-05-21 08:20:58 -04:00
clocksource clocksource/drivers/arm_arch_timer_mmio: Switch over to standalone driver 2025-09-23 12:31:50 +02:00
crypto crypto/krb5, rxrpc: Fix lack of pre-decrypt/pre-verify length checks 2026-05-20 16:36:45 -07:00
cxl cxl: export internal structs for external Type2 drivers 2026-03-16 16:24:29 -07:00
drm Short summary of fixes pull: 2026-05-22 07:01:04 +10:00
dt-bindings We've finally gotten rid of the struct clk_ops::round_rate() code after months 2026-04-21 08:33:26 -07:00
hyperv x86/hyperv: Skip LP/VP creation on kexec 2026-04-22 06:23:25 +00:00
keys keys/trusted_keys: establish PKWM as a trusted source 2026-01-30 09:27:26 +05:30
kunit kunit: irq: Ensure timer doesn't fire too frequently 2026-02-24 14:44:21 -08:00
kvm KVM: arm64: Kill arch_timer_context::direct field 2026-04-01 15:42:26 +01:00
linux bpf: Cancel special fields on map value recycle 2026-06-09 21:23:11 -07:00
math-emu powerpc/math-emu: Remove -w build flag and fix warnings 2022-09-05 17:28:25 +10:00
media media: subdev: Split v4l2_subdev_get_frame_desc_passthrough() into locked and unlocked 2026-03-24 11:58:02 +01:00
memory memory: renesas-rpc-if: Add RZ/G3E xSPI support 2025-05-01 12:22:25 +02:00
misc cxl: Remove driver 2025-03-16 22:04:27 +11:00
net tcp: fix stale per-CPU tcp_tw_isn leak enabling ISN prediction 2026-05-20 19:14:06 -07:00
pcmcia pcmcia: remove PCCARD_IODYN 2025-08-16 15:37:47 +02:00
ras PCI/AER: Report CXL or PCIe bus type in AER trace logging 2026-01-22 15:07:04 -07:00
rdma RDMA/core: Do not read wild stack memory in uverbs_get_handler_fn() 2026-05-19 19:32:48 -03:00
rv rv: Add support for per-object monitors in DA/HA 2026-03-31 16:47:17 +02:00
scsi scsi: libsas: Delete unused to_dom_device() and to_dev_attr() 2026-04-08 21:55:51 -04:00
soc firmware: tegra: Changes for v7.1-rc1 2026-04-02 23:13:02 +02:00
sound ASoC: Fixes for v7.1 2026-04-23 09:34:28 +02:00
target scsi: target: Add support for completing commands from backend context 2026-02-28 21:04:02 -05:00
trace Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf 7.1-rc5 2026-05-25 06:33:30 -07:00
uapi bpf: Add support for tracing_multi link session 2026-06-07 10:03:01 -07:00
ufs scsi: ufs: core: Fix bRefClkFreq write failure in HS-LSS mode 2026-04-21 20:58:06 -04:00
vdso vdso/datapage: Trim down unnecessary includes 2026-03-11 15:22:39 +01:00
video fbdev: udlfb: add vm_ops to dlfb_ops_mmap to prevent use-after-free 2026-05-04 10:35:55 +02:00
xen xen/arm: Replace __ASSEMBLY__ with __ASSEMBLER__ in interface.h 2026-05-12 17:31:38 +02:00
Kbuild drm: ensure drm headers are self-contained and pass kernel-doc 2025-02-12 10:44:43 +02:00