kernel_samsung_a53x/include
Yonghong Song b4fb5d93ff bpf: Mark bpf_spin_{lock,unlock}() helpers with notrace correctly
[ Upstream commit 178c54666f9c4d2f49f2ea661d0c11b52f0ed190 ]

Currently tracing is supposed not to allow for bpf_spin_{lock,unlock}()
helper calls. This is to prevent deadlock for the following cases:
  - there is a prog (prog-A) calling bpf_spin_{lock,unlock}().
  - there is a tracing program (prog-B), e.g., fentry, attached
    to bpf_spin_lock() and/or bpf_spin_unlock().
  - prog-B calls bpf_spin_{lock,unlock}().
For such a case, when prog-A calls bpf_spin_{lock,unlock}(),
a deadlock will happen.

The related source codes are below in kernel/bpf/helpers.c:
  notrace BPF_CALL_1(bpf_spin_lock, struct bpf_spin_lock *, lock)
  notrace BPF_CALL_1(bpf_spin_unlock, struct bpf_spin_lock *, lock)
notrace is supposed to prevent fentry prog from attaching to
bpf_spin_{lock,unlock}().

But actually this is not the case and fentry prog can successfully
attached to bpf_spin_lock(). Siddharth Chintamaneni reported
the issue in [1]. The following is the macro definition for
above BPF_CALL_1:
  #define BPF_CALL_x(x, name, ...)                                               \
        static __always_inline                                                 \
        u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__));   \
        typedef u64 (*btf_##name)(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
        u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__));         \
        u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__))          \
        {                                                                      \
                return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
        }                                                                      \
        static __always_inline                                                 \
        u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))

  #define BPF_CALL_1(name, ...)   BPF_CALL_x(1, name, __VA_ARGS__)

The notrace attribute is actually applied to the static always_inline function
____bpf_spin_{lock,unlock}(). The actual callback function
bpf_spin_{lock,unlock}() is not marked with notrace, hence
allowing fentry prog to attach to two helpers, and this
may cause the above mentioned deadlock. Siddharth Chintamaneni
actually has a reproducer in [2].

To fix the issue, a new macro NOTRACE_BPF_CALL_1 is introduced which
will add notrace attribute to the original function instead of
the hidden always_inline function and this fixed the problem.

  [1] https://lore.kernel.org/bpf/CAE5sdEigPnoGrzN8WU7Tx-h-iFuMZgW06qp0KHWtpvoXxf1OAQ@mail.gmail.com/
  [2] https://lore.kernel.org/bpf/CAE5sdEg6yUc_Jz50AnUXEEUh6O73yQ1Z6NV2srJnef0ZrQkZew@mail.gmail.com/

Fixes: d83525ca62cf ("bpf: introduce bpf_spin_lock")
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20240207070102.335167-1-yonghong.song@linux.dev
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-19 08:44:44 +01:00
..
acpi Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
asm-generic asm-generic: qspinlock: fix queued_spin_value_unlocked() implementation 2024-11-18 12:11:56 +01:00
clocksource Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
crypto crypto: af_alg - Disallow multiple in-flight AIO requests 2024-11-18 12:12:26 +01:00
drm drm: using mul_u32_u32() requires linux/math64.h 2024-11-18 12:13:21 +01:00
dt-bindings dt-bindings: clock: Update the videocc resets for sm8150 2024-11-18 12:12:41 +01:00
keys Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kunit Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
kvm Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
linux bpf: Mark bpf_spin_{lock,unlock}() helpers with notrace correctly 2024-11-19 08:44:44 +01:00
math-emu Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
media Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
memory Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
misc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
net mptcp: fix lockless access in subflow ULP diag 2024-11-18 22:25:39 +01:00
pcmcia Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
ras Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
rdma Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
scsc Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
scsi scsi: core: Introduce enum scsi_disposition 2024-11-18 12:13:21 +01:00
sdp Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
soc exynos_pm_qos: Remove exynos_pm_qos_update_request_timeout() 2024-11-17 17:44:09 +01:00
sound ASoC: soc-card: Add storage for PCI SSID 2024-11-18 11:43:13 +01:00
target Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
test Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
trace tracing/net_sched: Fix tracepoints that save qdisc_dev() as a string 2024-11-18 23:19:34 +01:00
uapi netfilter: nft_compat: reject unused compat flag 2024-11-18 12:13:25 +01:00
variant1/linux Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
vdso Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
video Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00
xen Import A536BXXU9EXDC 2024-06-15 16:02:09 -03:00