Centos-kernel-stream-9/kernel
Artem Savkov fb0a7b0e48 bpf: Fix prog_array_map_poke_run map poke update
JIRA: https://issues.redhat.com/browse/RHEL-23643

Conflicts: already backported fd5d27b701883 ("arch/x86: Implement
           arch_bpf_stack_walk")

commit 4b7de801606e504e69689df71475d27e35336fb3
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Wed Dec 6 09:30:40 2023 +0100

    bpf: Fix prog_array_map_poke_run map poke update

    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: Artem Savkov <asavkov@redhat.com>
2024-03-27 10:33:51 +01:00
..
bpf bpf: Fix prog_array_map_poke_run map poke update 2024-03-27 10:33:51 +01:00
cgroup cgroup: Prepare for using css_task_iter_*() in BPF 2024-03-27 10:27:54 +01:00
configs hardening: Provide Kconfig fragments for basic options 2024-03-20 09:43:30 -04:00
debug
dma Reapply "dma-mapping: reject __GFP_COMP in dma_alloc_attrs" 2024-02-19 10:00:36 -08:00
entry entry: kmsan: introduce kmsan_unpoison_entry_regs() 2023-10-20 06:14:42 -04:00
events mmu_notifiers: don't invalidate secondary TLBs as part of mmu_notifier_invalidate_range_end() 2024-02-26 15:49:51 -07:00
futex futex: Don't include process MM in futex key on no-MMU 2024-01-15 10:10:44 -05:00
gcov
irq x86/pci/xen: populate MSI sysfs entries 2024-03-20 09:43:03 -04:00
kcsan treewide: use get_random_u32() when possible 2023-10-20 06:15:03 -04:00
livepatch Merge: livepatch: selected fixes for rhel-9.4 2023-11-13 10:15:36 +01:00
locking x86/qspinlock-paravirt: Fix missing-prototype warning 2024-03-20 09:43:15 -04:00
power PM: sleep: Remove "select SRCU" 2023-12-05 17:57:45 -07:00
printk Merge: arch/x86: backport 2024-03-26 11:25:15 -04:00
rcu rcu: Remove rcu_is_idle_cpu() 2024-03-20 09:42:38 -04:00
sched Merge: arch/x86: backport 2024-03-26 11:25:15 -04:00
time vdso/timens: Refactor copy-pasted find_timens_vvar_page() helper into one copy 2024-03-20 09:42:49 -04:00
trace bpf: Count missed stats in trace_call_bpf 2024-03-27 10:27:51 +01:00
.gitignore
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
Makefile kernel: add platform_has() infrastructure 2024-03-20 09:42:37 -04:00
acct.c audit: add space before parenthesis and around '=', "==", and '<' 2023-12-08 13:36:14 -03:00
async.c
audit.c audit: move trailing statements to next line 2023-12-08 13:36:23 -03:00
audit.h audit: correct audit_filter_inodes() definition 2023-12-08 13:36:03 -03:00
audit_fsnotify.c
audit_tree.c
audit_watch.c audit: don't WARN_ON_ONCE(!current->mm) in audit_exe_compare() 2023-11-21 10:44:01 +01:00
auditfilter.c audit: move trailing statements to next line 2023-12-08 13:36:23 -03:00
auditsc.c netfilter: nf_tables: Audit log rule reset 2023-12-08 13:39:15 -03:00
backtracetest.c
bounds.c mm: multi-gen LRU: minimal implementation 2023-10-20 06:13:45 -04:00
capability.c
cfi.c
compat.c sched_getaffinity: don't assume 'cpumask_size()' is fully initialized 2023-09-07 14:26:06 -04:00
configs.c
context_tracking.c
cpu.c cpu/hotplug: Remove dependancy against cpu_primary_thread_mask 2024-02-06 10:17:15 -05:00
cpu_pm.c cpuidle, cpu_pm: Remove RCU fiddling from cpu_pm_{enter,exit}() 2023-06-09 13:20:30 -04:00
crash_core.c mm, treewide: redefine MAX_ORDER sanely 2023-10-30 09:12:37 +01:00
crash_dump.c
cred.c
delayacct.c delayacct: support re-entrance detection of thrashing accounting 2023-06-14 15:11:00 -06:00
dma.c
exec_domain.c
exit.c kernel: exit: cleanup release_thread() 2024-03-20 09:42:40 -04:00
extable.c sections: move and rename core_kernel_data() to is_kernel_core_data() 2024-03-20 09:43:21 -04:00
fail_function.c
fork.c stackprotector: move get_random_canary() into stackprotector.h 2024-03-20 09:43:05 -04:00
freezer.c
gen_kheaders.sh
groups.c
hung_task.c
iomem.c
irq_work.c trace: Add trace_ipi_send_cpu() 2023-09-14 15:36:30 +02:00
jump_label.c jump_label: make initial NOP patching the special case 2024-03-20 09:43:04 -04:00
kallsyms.c kallsyms: Revert "Take callthunks into account" 2023-05-18 15:09:34 -04:00
kallsyms_internal.h
kcmp.c
kcov.c kcov: kmsan: unpoison area->list in kcov_remote_area_put() 2023-10-20 06:14:40 -04:00
kexec.c
kexec_core.c kexec: do syscore_shutdown() in kernel_kexec 2024-01-23 06:06:00 -05:00
kexec_elf.c
kexec_file.c kexec: remove unnecessary arch_kexec_kernel_image_load() 2023-05-24 16:00:21 +08:00
kexec_internal.h
kheaders.c
kmod.c
kprobes.c x86/kprobes: Fix arch_check_optimized_kprobe check within optimized_kprobe range 2024-03-20 09:42:59 -04:00
ksysfs.c
kthread.c sched/wait: Fix a kthread_park race with wait_woken() 2023-09-07 14:30:59 -04:00
latencytop.c
module-internal.h
module.c Merge: treewide: Implement new Red Hat driver and device status infrastructure 2023-11-29 14:08:05 -05:00
module_signature.c
module_signing.c
notifier.c notifier: Add atomic_notifier_call_chain_is_empty() 2024-03-20 09:42:36 -04:00
nsproxy.c Revert "fs/exec: allow to unshare a time namespace on vfork+exec" 2023-10-20 06:13:08 -04:00
padata.c padata: Fix refcnt handling in padata_free_shell() 2023-12-06 16:23:46 -03:00
panic.c cpu: Mark nmi_panic_self_stop() __noreturn 2024-03-20 09:43:02 -04:00
params.c kobject: kset_uevent_ops: make filter() callback take a const * 2023-10-23 10:35:56 -05:00
pid.c
pid_namespace.c rcu-tasks: Fix synchronize_rcu_tasks() VS zap_pid_ns_processes() 2023-09-22 13:21:34 -04:00
platform-feature.c kernel: add platform_has() infrastructure 2024-03-20 09:42:37 -04:00
profile.c profile: setup_profiling_timer() is moslty not implemented 2024-03-20 09:42:39 -04:00
ptrace.c ptrace: fix clearing of JOBCTL_TRACED in ptrace_unfreeze_traced() 2023-07-06 15:55:32 +02:00
range.c
reboot.c kernel/reboot: Add do_kernel_power_off() 2024-03-20 09:42:36 -04:00
regset.c
relay.c relayfs: fix out-of-bounds access in relay_file_read 2023-07-10 12:16:49 -05:00
resource.c
resource_kunit.c
rh_messages.c kernel/rh_messages.c: Mark functions as possibly unused 2023-11-09 19:58:08 -05:00
rh_messages.h Deprecate qla4xxx in RHEL-9 2024-03-06 14:06:57 -08:00
rh_shadowman.c
rseq.c
scftorture.c
scs.c
seccomp.c
signal.c signal: Add proper comment about the preempt-disable in ptrace_stop(). 2023-11-06 12:29:40 +01:00
smp.c smp: don't declare nr_cpu_ids if NR_CPUS == 1 2024-03-20 09:42:41 -04:00
smpboot.c cpu/hotplug: Remove unused state functions 2024-02-06 10:17:13 -05:00
smpboot.h
softirq.c Revert "softirq: Let ksoftirqd do its job" 2023-05-24 12:07:54 +02:00
stackleak.c
stacktrace.c
static_call.c static_call: Don't make __static_call_return0 static 2023-06-30 19:59:53 -04:00
static_call_inline.c static_call: Add call depth tracking support 2023-06-30 20:31:53 -04:00
stop_machine.c stop_machine: Add stop_core_cpuslocked() for per-core operations 2023-05-06 07:48:51 -04:00
sys.c prlimit: do_prlimit needs to have a speculation check 2023-05-09 13:46:37 +02:00
sys_ni.c syscalls: Cleanup references to sys_lookup_dcookie() 2024-03-20 09:43:26 -04:00
sysctl-test.c
sysctl.c memory tiering: rate limit NUMA migration throughput 2023-10-20 06:13:30 -04:00
task_work.c
taskstats.c
test_kprobes.c test_kprobes: Add recursed kprobe test case 2023-11-02 15:26:56 -06:00
torture.c
tracepoint.c
tsacct.c
ucount.c
uid16.c
uid16.h
umh.c freezer,umh: Clean up freezer/initrd interaction 2023-10-20 06:13:12 -04:00
up.c
user-return-notifier.c
user.c
user_namespace.c
usermode_driver.c
utsname.c
utsname_sysctl.c
watch_queue.c watch_queue: Free the page array when watch_queue is dismantled 2023-08-17 14:10:34 +02:00
watchdog.c
watchdog_hld.c
workqueue.c workqueue: Avoid using isolated cpus' timers on queue_delayed_work 2024-02-22 16:47:15 -03:00
workqueue_internal.h