WSL2-Linux-Kernel/arch/s390
Ilya Leoshkevich c730fce7c7 s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL
Thomas Richter reported a crash in linux-next with a backtrace similar
to the following one:

	 [<0000000000000000>] 0x0
	([<000000000031a182>] bpf_trace_run4+0xc2/0x218)
	 [<00000000001d59f4>] __bpf_trace_sched_switch+0x1c/0x28
	 [<0000000000c44a3a>] __schedule+0x43a/0x890
	 [<0000000000c44ef8>] schedule+0x68/0x110
	 [<0000000000c4e5ca>] do_nanosleep+0xa2/0x168
	 [<000000000026e7fe>] hrtimer_nanosleep+0xf6/0x1c0
	 [<000000000026eb6e>] __s390x_sys_nanosleep+0xb6/0xf0
	 [<0000000000c3b81c>] __do_syscall+0x1e4/0x208
	 [<0000000000c50510>] system_call+0x70/0x98
	Last Breaking-Event-Address:
	 [<000003ff7fda1814>] bpf_prog_65e887c70a835bbf_on_switch+0x1a4/0x1f0

The problem is that bpf_arch_text_poke() with new_addr == NULL is
susceptible to the following race condition:

	T1                 T2
        -----------------  -------------------
	plt.target = NULL
	                   entry: brcl 0xf,plt
	entry.mask = 0
	                   lgrl %r1,plt.target
	                   br %r1

Fix by setting PLT target to the instruction following `brcl 0xf,plt`
instead of 0. This way T2 will simply resume the execution of the eBPF
program, which is the desired effect of passing new_addr == NULL.

Fixes: f1d5df84cd ("s390/bpf: Implement bpf_arch_text_poke()")
Reported-by: Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Link: https://lore.kernel.org/bpf/20230414154755.184502-1-iii@linux.ibm.com
2023-04-14 18:28:52 +02:00
..
appldata
boot s390/ipl: add missing intersection check to ipl_report handling 2023-03-13 09:15:11 +01:00
configs s390: update defconfigs 2023-03-13 09:15:11 +01:00
crypto
hypfs
include s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
kernel s390/ptrace: fix PTRACE_GET_LAST_BREAK error handling 2023-03-27 17:23:08 +02:00
kvm KVM: PPC: Make KVM_CAP_IRQFD_RESAMPLE platform dependent 2023-03-31 11:19:05 -04:00
lib s390/uaccess: add missing earlyclobber annotations to __clear_user() 2023-03-27 17:23:08 +02:00
mm s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
net s390/bpf: Fix bpf_arch_text_poke() with new_addr == NULL 2023-04-14 18:28:52 +02:00
pci PCI: s390: Fix use-after-free of PCI resources with per-function hotplug 2023-03-13 09:15:11 +01:00
purgatory
tools
Kbuild
Kconfig s390 updates for 6.3 merge window part 2 2023-03-03 09:38:01 -08:00
Kconfig.debug
Makefile s390: reintroduce expoline dependence to scripts 2023-03-27 17:23:08 +02:00