linux-stable/include
Hou Tao f91cd728b1 bpf: Defer the free of inner map when necessary
[ Upstream commit 8766733641 ]

When updating or deleting an inner map in map array or map htab, the map
may still be accessed by non-sleepable program or sleepable program.
However bpf_map_fd_put_ptr() decreases the ref-counter of the inner map
directly through bpf_map_put(), if the ref-counter is the last one
(which is true for most cases), the inner map will be freed by
ops->map_free() in a kworker. But for now, most .map_free() callbacks
don't use synchronize_rcu() or its variants to wait for the elapse of a
RCU grace period, so after the invocation of ops->map_free completes,
the bpf program which is accessing the inner map may incur
use-after-free problem.

Fix the free of inner map by invoking bpf_map_free_deferred() after both
one RCU grace period and one tasks trace RCU grace period if the inner
map has been removed from the outer map before. The deferment is
accomplished by using call_rcu() or call_rcu_tasks_trace() when
releasing the last ref-counter of bpf map. The newly-added rcu_head
field in bpf_map shares the same storage space with work field to
reduce the size of bpf_map.

Fixes: bba1dc0b55 ("bpf: Remove redundant synchronize_rcu.")
Fixes: 638e4b825d ("bpf: Allows per-cpu maps and map-in-map in sleepable programs")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Link: https://lore.kernel.org/r/20231204140425.1480317-5-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 15:35:22 -08:00
..
acpi ACPI: PM: Add acpi_device_fix_up_power_children() function 2023-12-03 07:33:07 +01:00
asm-generic asm-generic: Fix 32 bit __generic_cmpxchg_local 2024-01-25 15:35:19 -08:00
clocksource
crypto crypto: af_alg - Disallow multiple in-flight AIO requests 2024-01-25 15:35:16 -08:00
drm Revert "drm/prime: Unexport helpers for fd/handle conversion" 2024-01-20 11:51:39 +01:00
dt-bindings IOMMU Updates for Linux v6.6 2023-09-01 16:54:25 -07:00
keys
kunit
kvm KVM: arm64: timers: Correctly handle TGE flip with CNTPOFF_EL2 2023-10-12 16:55:21 +01:00
linux bpf: Defer the free of inner map when necessary 2024-01-25 15:35:22 -08:00
math-emu
media media: ipu-bridge: increase sensor_name size 2023-11-28 17:19:46 +00:00
memory
misc
net net: constify sk_dst_get() and __sk_dst_get() argument 2024-01-10 17:17:00 +01:00
pcmcia
ras
rdma RDMA/core: Fix umem iterator when PAGE_SIZE is greater then HCA pgsz 2023-12-13 18:45:16 +01:00
rv rv: Set variable 'da_mon_##name' to static 2023-09-01 21:00:00 -04:00
scsi scsi: sd: Fix system start for ATA devices 2023-12-08 08:52:17 +01:00
soc firmware: tegra: Add suspend hook and reset BPMP IPC early on resume 2023-11-20 11:59:16 +01:00
sound ASoC: soc-dai: add flag to mute and unmute stream during trigger 2023-11-28 17:20:04 +00:00
target
trace 9p: prevent read overrun in protocol dump tracepoint 2024-01-01 12:42:43 +00:00
uapi bpf: Add crosstask check to __bpf_get_stack 2024-01-25 15:35:19 -08:00
ufs Merge branch 'fixes' into misc 2023-09-02 08:25:19 +01:00
vdso
video fbdev: stifb: Make the STI next font pointer a 32-bit signed offset 2023-11-28 17:19:58 +00:00
xen arm/xen: remove lazy mode related definitions 2023-09-19 07:04:49 +02:00