linux-stable/include
Viktor Malik 31bf1dbccf bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules
This resolves two problems with attachment of fentry/fexit/fmod_ret/lsm
to functions located in modules:

1. The verifier tries to find the address to attach to in kallsyms. This
   is always done by searching the entire kallsyms, not respecting the
   module in which the function is located. Such approach causes an
   incorrect attachment address to be computed if the function to attach
   to is shadowed by a function of the same name located earlier in
   kallsyms.

2. If the address to attach to is located in a module, the module
   reference is only acquired in register_fentry. If the module is
   unloaded between the place where the address is found
   (bpf_check_attach_target in the verifier) and register_fentry, it is
   possible that another module is loaded to the same address which may
   lead to potential errors.

Since the attachment must contain the BTF of the program to attach to,
we extract the module from it and search for the function address in the
correct module (resolving problem no. 1). Then, the module reference is
taken directly in bpf_check_attach_target and stored in the bpf program
(in bpf_prog_aux). The reference is only released when the program is
unloaded (resolving problem no. 2).

Signed-off-by: Viktor Malik <vmalik@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/3f6a9d8ae850532b5ef864ef16327b0f7a669063.1678432753.git.vmalik@redhat.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2023-03-15 18:38:21 -07:00
..
acpi pci-v6.3-changes 2023-02-24 16:51:40 -08:00
asm-generic Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
clocksource
crypto
drm Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
dt-bindings ARM: SoC drivers for 6.3 2023-02-27 10:04:49 -08:00
keys
kunit
kvm
linux bpf: Fix attaching fentry/fexit/fmod_ret/lsm to modules 2023-03-15 18:38:21 -07:00
math-emu
media media updates for v6.3-rc1 2023-02-26 11:47:26 -08:00
memory
misc
net xdp: remove unused {__,}xdp_release_frame() 2023-03-14 15:20:05 -07:00
pcmcia
ras
rdma
rv
scsi SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
soc
sound Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00
target
trace ARM: SoC drivers for 6.3 2023-02-27 10:04:49 -08:00
uapi bpf: use canonical ftrace path 2023-03-13 21:51:30 -07:00
ufs SCSI misc on 20230222 2023-02-22 13:41:41 -08:00
vdso
video
xen Driver core changes for 6.3-rc1 2023-02-24 12:58:55 -08:00