android_kernel_samsung_sm8650/arch
Jiri Olsa ec46fe0ac7 UPSTREAM: 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

Bug: 309551558
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>
(cherry picked from commit 57a6b0a464)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I251c3da579e5d48cd7de4043913fd42d0671d6b5
2024-01-08 17:00:17 +00:00
..
alpha alpha: remove __init annotation from exported page_is_ram() 2023-08-16 18:27:31 +02:00
arc ARC: atomics: Add compiler barrier to atomic operations... 2023-09-19 12:28:04 +02:00
arm Merge 6.1.56 into android14-6.1-lts 2023-10-27 09:17:04 +00:00
arm64 ANDROID: KVM: arm64: Don't prepopulate MMIO regions for host stage-2 2024-01-05 12:43:55 +00:00
csky UPSTREAM: mm/fault: convert remaining simple cases to lock_mm_and_find_vma() 2023-07-27 05:04:57 +00:00
hexagon UPSTREAM: mm/fault: convert remaining simple cases to lock_mm_and_find_vma() 2023-07-27 05:04:57 +00:00
ia64 Merge 6.1.44 into android14-6.1-lts 2023-09-12 15:09:42 +00:00
loongarch Merge 6.1.56 into android14-6.1-lts 2023-10-27 09:17:04 +00:00
m68k m68k: Fix invalid .section syntax 2023-09-13 09:42:21 +02:00
microblaze BACKPORT: mm: always expand the stack with the mmap write lock held 2023-07-27 11:47:21 +00:00
mips MIPS: Alchemy: only build mmc support helpers if au1xmmc is enabled 2023-10-06 14:56:45 +02:00
nios2 Merge branch 'android14-6.1' into 'android14-6.1-lts' 2023-08-23 18:31:43 +00:00
openrisc Merge branch 'android14-6.1' into 'android14-6.1-lts' 2023-08-23 18:31:43 +00:00
parisc This is the 6.1.57 stable release 2023-11-02 07:05:54 +00:00
powerpc FROMGIT: arch/mm/fault: fix major fault accounting when retrying under per-VMA lock 2024-01-03 20:45:51 +00:00
riscv FROMGIT: arch/mm/fault: fix major fault accounting when retrying under per-VMA lock 2024-01-03 20:45:51 +00:00
s390 FROMGIT: arch/mm/fault: fix major fault accounting when retrying under per-VMA lock 2024-01-03 20:45:51 +00:00
sh sh: boards: Fix CEU buffer size passed to dma_declare_coherent_memory() 2023-09-19 12:28:04 +02:00
sparc Merge 6.1.44 into android14-6.1-lts 2023-09-12 15:09:42 +00:00
um um: Fix hostaudio build errors 2023-09-13 09:42:58 +02:00
x86 UPSTREAM: bpf: Fix prog_array_map_poke_run map poke update 2024-01-08 17:00:17 +00:00
xtensa xtensa: boot/lib: fix function prototypes 2023-10-06 14:56:49 +02:00
.gitignore
Kconfig Merge 6.1.44 into android14-6.1-lts 2023-09-12 15:09:42 +00:00