OpenCloudOS-Kernel/arch/x86
Jiri Olsa f64b2dc8a4 bpf: Fix prog_array_map_poke_run map poke update
commit 4b7de801606e504e69689df71475d27e35336fb3 upstream.

Lee pointed out issue found by syscaller [0] hitting BUG in prog array
map poke update in prog_array_map_poke_run function due to error value
returned from bpf_arch_text_poke function.

There's race window where bpf_arch_text_poke can fail due to missing
bpf program kallsym symbols, which is accounted for with check for
-EINVAL in that BUG_ON call.

The problem is that in such case we won't update the tail call jump
and cause imbalance for the next tail call update check which will
fail with -EBUSY in bpf_arch_text_poke.

I'm hitting following race during the program load:

  CPU 0                             CPU 1

  bpf_prog_load
    bpf_check
      do_misc_fixups
        prog_array_map_poke_track

                                    map_update_elem
                                      bpf_fd_array_map_update_elem
                                        prog_array_map_poke_run

                                          bpf_arch_text_poke returns -EINVAL

    bpf_prog_kallsyms_add

After bpf_arch_text_poke (CPU 1) fails to update the tail call jump, the next
poke update fails on expected jump instruction check in bpf_arch_text_poke
with -EBUSY and triggers the BUG_ON in prog_array_map_poke_run.

Similar race exists on the program unload.

Fixing this by moving the update to bpf_arch_poke_desc_update function which
makes sure we call __bpf_arch_text_poke that skips the bpf address check.

Each architecture has slightly different approach wrt looking up bpf address
in bpf_arch_text_poke, so instead of splitting the function or adding new
'checkip' argument in previous version, it seems best to move the whole
map_poke_run update as arch specific code.

  [0] https://syzkaller.appspot.com/bug?extid=97a4fe20470e9bc30810

Fixes: ebf7d1f508 ("bpf, x64: rework pro/epilogue and tailcall handling in JIT")
Reported-by: syzbot+97a4fe20470e9bc30810@syzkaller.appspotmail.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Cc: Lee Jones <lee@kernel.org>
Cc: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Link: https://lore.kernel.org/bpf/20231206083041.1306660-2-jolsa@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-01 12:42:23 +00:00
..
boot x86/sev: Check for user-space IOIO pointing to kernel space 2023-10-17 10:58:16 +02:00
coco x86/tdx: Allow 32-bit emulation by default 2023-12-13 18:45:02 +01:00
configs - The first, cleanup part of the microcode loader reorg tglx has been 2023-08-28 15:55:20 -07:00
crypto crypto: x86/sha - load modules based on CPU features 2023-11-28 17:19:56 +00:00
entry x86/entry: Do not allow external 0x80 interrupts 2023-12-13 18:45:02 +01:00
events perf/x86/lbr: Filter vsyscall addresses 2023-10-08 12:25:18 +02:00
hyperv x86/hyperv: Fix the detection of E820_TYPE_PRAM in a Gen2 VM 2023-12-20 17:01:55 +01:00
ia32 x86/signal/32: Merge native and compat 32-bit signal code 2022-10-19 09:58:49 +02:00
include x86/speculation, objtool: Use absolute relocations for annotations 2023-12-20 17:02:06 +01:00
kernel x86/CPU/AMD: Check vendor in the AMD microcode callback 2023-12-13 18:45:33 +01:00
kvm KVM: SVM: Update EFER software model on CR0 trap for SEV-ES 2023-12-13 18:45:34 +01:00
lib iov_iter, x86: Be consistent about the __user tag on copy_mc_to_user() 2023-11-20 11:58:52 +01:00
math-emu x86/fpu: Include asm/fpu/regset.h 2023-05-18 11:56:18 -07:00
mm x86/coco: Disable 32-bit emulation by default on TDX and SEV 2023-12-13 18:45:02 +01:00
net bpf: Fix prog_array_map_poke_run map poke update 2024-01-01 12:42:23 +00:00
pci x86/PCI: Avoid PME from D3hot/D3cold for AMD Rembrandt and Phoenix USB4 2023-11-28 17:19:56 +00:00
platform efi/x86: Move EFI runtime call setup/teardown helpers out of line 2023-09-11 06:37:50 +00:00
power x86/topology: Remove CPU0 hotplug option 2023-05-15 13:44:49 +02:00
purgatory x86/purgatory: Remove LTO flags 2023-09-17 09:49:03 +02:00
ras
realmode x86/realmode: Make stack lock work in trampoline_compat() 2023-05-30 14:11:47 +02:00
tools ELF: fix all "Elf" typos 2023-04-08 13:45:37 -07:00
um um: Hard-code the result of 'uname -s' 2023-08-26 22:40:37 +02:00
video Merge drm/drm-next into drm-misc-next 2023-07-24 15:44:47 +02:00
virt/vmx/tdx
xen x86/entry: Convert INT 0x80 emulation to IDTENTRY 2023-12-13 18:45:02 +01:00
.gitignore
Kbuild
Kconfig efi/x86: Ensure that EFI_RUNTIME_MAP is enabled for kexec 2023-09-11 06:37:50 +00:00
Kconfig.assembler x86/shstk: Add Kconfig option for shadow stack 2023-07-11 14:12:18 -07:00
Kconfig.cpu x86/cpu: Remove X86_FEATURE_NAMES 2023-05-15 20:03:08 +02:00
Kconfig.debug docs: move x86 documentation into Documentation/arch/ 2023-03-30 12:58:51 -06:00
Makefile Kbuild updates for v6.6 2023-09-05 11:01:47 -07:00
Makefile.postlink x86/build: Avoid relocation information in final vmlinux 2023-06-14 19:54:40 +02:00
Makefile.um um: Only disable SSE on clang to work around old GCC bugs 2023-04-04 09:57:05 +02:00
Makefile_32.cpu