android_kernel_sony_sdm845/kernel
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Borkmann f8dfc402ee
bpf: fix truncated jump targets on heavy expansions
commit 050fad7c4534c13c8eb1d9c2ba66012e014773cb upstream.

Recently during testing, I ran into the following panic:

  [  207.892422] Internal error: Accessing user space memory outside uaccess.h routines: 96000004 [#1] SMP
  [  207.901637] Modules linked in: binfmt_misc [...]
  [  207.966530] CPU: 45 PID: 2256 Comm: test_verifier Tainted: G        W         4.17.0-rc3+ #7
  [  207.974956] Hardware name: FOXCONN R2-1221R-A4/C2U4N_MB, BIOS G31FB18A 03/31/2017
  [  207.982428] pstate: 60400005 (nZCv daif +PAN -UAO)
  [  207.987214] pc : bpf_skb_load_helper_8_no_cache+0x34/0xc0
  [  207.992603] lr : 0xffff000000bdb754
  [  207.996080] sp : ffff000013703ca0
  [  207.999384] x29: ffff000013703ca0 x28: 0000000000000001
  [  208.004688] x27: 0000000000000001 x26: 0000000000000000
  [  208.009992] x25: ffff000013703ce0 x24: ffff800fb4afcb00
  [  208.015295] x23: ffff00007d2f5038 x22: ffff00007d2f5000
  [  208.020599] x21: fffffffffeff2a6f x20: 000000000000000a
  [  208.025903] x19: ffff000009578000 x18: 0000000000000a03
  [  208.031206] x17: 0000000000000000 x16: 0000000000000000
  [  208.036510] x15: 0000ffff9de83000 x14: 0000000000000000
  [  208.041813] x13: 0000000000000000 x12: 0000000000000000
  [  208.047116] x11: 0000000000000001 x10: ffff0000089e7f18
  [  208.052419] x9 : fffffffffeff2a6f x8 : 0000000000000000
  [  208.057723] x7 : 000000000000000a x6 : 00280c6160000000
  [  208.063026] x5 : 0000000000000018 x4 : 0000000000007db6
  [  208.068329] x3 : 000000000008647a x2 : 19868179b1484500
  [  208.073632] x1 : 0000000000000000 x0 : ffff000009578c08
  [  208.078938] Process test_verifier (pid: 2256, stack limit = 0x0000000049ca7974)
  [  208.086235] Call trace:
  [  208.088672]  bpf_skb_load_helper_8_no_cache+0x34/0xc0
  [  208.093713]  0xffff000000bdb754
  [  208.096845]  bpf_test_run+0x78/0xf8
  [  208.100324]  bpf_prog_test_run_skb+0x148/0x230
  [  208.104758]  sys_bpf+0x314/0x1198
  [  208.108064]  el0_svc_naked+0x30/0x34
  [  208.111632] Code: 91302260 f9400001 f9001fa1 d2800001 (29500680)
  [  208.117717] ---[ end trace 263cb8a59b5bf29f ]---

The program itself which caused this had a long jump over the whole
instruction sequence where all of the inner instructions required
heavy expansions into multiple BPF instructions. Additionally, I also
had BPF hardening enabled which requires once more rewrites of all
constant values in order to blind them. Each time we rewrite insns,
bpf_adj_branches() would need to potentially adjust branch targets
which cross the patchlet boundary to accommodate for the additional
delta. Eventually that lead to the case where the target offset could
not fit into insn->off's upper 0x7fff limit anymore where then offset
wraps around becoming negative (in s16 universe), or vice versa
depending on the jump direction.

Therefore it becomes necessary to detect and reject any such occasions
in a generic way for native eBPF and cBPF to eBPF migrations. For
the latter we can simply check bounds in the bpf_convert_filter()'s
BPF_EMIT_JMP helper macro and bail out once we surpass limits. The
bpf_patch_insn_single() for native eBPF (and cBPF to eBPF in case
of subsequent hardening) is a bit more complex in that we need to
detect such truncations before hitting the bpf_prog_realloc(). Thus
the latter is split into an extra pass to probe problematic offsets
on the original program in order to fail early. With that in place
and carefully tested I no longer hit the panic and the rewrites are
rejected properly. The above example panic I've seen on bpf-next,
though the issue itself is generic in that a guard against this issue
in bpf seems more appropriate in this case.

Change-Id: Icc4913ebc3949ab2de3f28f1637cbcc3fec090c8
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
[ab: Dropped BPF_PSEUDO_CALL hardening, introoduced in 4.16]
Signed-off-by: Alessio Balsini <balsini@android.com>
Acked-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 6824208b59a4727b8a8653f83d8e685584d04606)
2026-02-05 19:45:36 +02:00
..
bpf bpf: fix truncated jump targets on heavy expansions 2026-02-05 19:45:36 +02:00
configs ANDROID: add script to fetch android kernel config fragments 2017-10-03 17:19:26 +00:00
debug UPSTREAM: kdb: use correct pointer when 'btc' calls 'btt' 2022-02-21 16:30:05 +01:00
events Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-20 2023-01-19 15:42:12 +01:00
gcov Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-20 2023-01-19 15:42:12 +01:00
irq Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
livepatch
locking Merge remote-tracking branch 'common/android-4.9-q' into lineage-18.1-caf-sdm845 2021-12-27 02:07:39 +02:00
power Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-20 2023-01-19 15:42:12 +01:00
printk Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-06-12 01:39:01 +03:00
rcu Merge android-4.9.180 (719bdd9) into msm-4.9 2019-08-07 15:49:43 +08:00
sched sched: do not return error when set the same sched_boost value 2024-02-12 18:17:27 +01:00
time Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
trace Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-20 2023-01-19 15:42:12 +01:00
.gitignore BACKPORT: Provide in-kernel headers to make extending kernel easier 2019-07-03 14:30:53 -04:00
acct.c acct: fix potential integer overflow in encode_comp_t() 2023-01-07 12:07:31 +01:00
async.c kernel/async.c: revert "async: simplify lowest_in_progress()" 2018-02-17 13:21:18 +01:00
audit.c Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-18.1-caf-sdm845 2021-04-26 01:27:02 +03:00
audit.h audit: fix a net reference leak in audit_list_rules_send() 2021-04-07 12:05:41 +02:00
audit_fsnotify.c
audit_tree.c
audit_watch.c audit: CONFIG_CHANGE don't log internal bookkeeping as an event 2020-10-01 20:40:07 +02:00
auditfilter.c audit: fix a net reference leak in audit_list_rules_send() 2021-04-07 12:05:41 +02:00
auditsc.c Merge android-4.9.204(72e8598) into msm-4.9 2020-01-06 18:13:26 +08:00
backtracetest.c
bounds.c kbuild: fix kernel/bounds.c 'W=1' warning 2018-11-13 11:16:57 -08:00
capability.c
cfi.c ANDROID: cfi: Remove unused variable in ptr_to_check_fn 2019-03-06 18:27:16 +00:00
cgroup.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
cgroup_freezer.c
cgroup_pids.c cgroup: pids: use atomic64_t for pids->limit 2019-12-21 10:42:02 +01:00
compat.c kernel: Fix build errors due to uninitialized variables 2017-12-05 17:29:24 -08:00
configs.c
context_tracking.c
cpu.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
cpu_pm.c Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into HEAD 2020-06-30 02:33:58 +03:00
cpuset.c Merge android-4.9.183 (a80a7ab) into msm-4.9 2019-08-07 16:30:28 +08:00
crash_dump.c
cred.c memcg: account security cred as well to kmemcg 2020-01-12 11:24:13 +01:00
delayacct.c BACKPORT: delayacct: track delays from thrashing cache pages 2019-03-22 14:08:39 -07:00
dma.c
exec_domain.c
exit.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-09-06 06:20:26 +03:00
extable.c extable: Make init_kernel_text() global 2021-06-06 18:42:18 +03:00
fork.c fork,random: use get_random_canary() to set tsk->stack_canary 2022-09-06 06:15:40 +03:00
freezer.c
futex.c mm, futex: fix shared futex pgoff on shmem huge page 2021-07-11 12:46:40 +02:00
gen_kheaders.sh BACKPORT: kheaders: Do not regenerate archive if config is not changed 2019-07-03 14:31:16 -04:00
groups.c kernel: make groups_sort calling a responsibility group_info allocators 2018-01-10 09:29:52 +01:00
hung_task.c Merge android-4.9.170 (1ef64da) into msm-4.9 2019-05-30 14:15:13 +08:00
irq_work.c
jump_label.c jump_label: Disable jump labels in __exit code 2021-06-06 18:42:18 +03:00
kallsyms.c kallsyms: strip the .cfi postfix from symbols with CONFIG_CFI_CLANG 2018-02-28 15:09:58 -08:00
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks locking/rwsem: for rwsem prio aware enhancement 2019-01-08 16:14:39 +08:00
Kconfig.preempt
kcov.c This is the 4.9.117 stable release 2018-08-03 08:50:05 +02:00
kexec.c
kexec_core.c objtool, x86: Add several functions and files to the objtool whitelist 2018-06-05 10:28:57 +02:00
kexec_file.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-07-18 14:05:31 +03:00
kexec_internal.h
kheaders.c BACKPORT: kheaders: Move from proc to sysfs 2019-07-03 14:31:02 -04:00
kmod.c usermodehelper: reset umask to default before executing user process 2020-10-14 09:48:14 +02:00
kprobes.c This is the 4.9.327 stable release 2022-09-05 14:02:59 +02:00
ksysfs.c
kthread.c Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-18.1-caf-sdm845 2021-07-22 02:11:11 +03:00
latencytop.c
Makefile Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-18.1-caf-sdm845 2021-04-26 01:27:02 +03:00
membarrier.c
memremap.c mm, devm_memremap_pages: kill mapping "System RAM" support 2019-01-13 10:03:51 +01:00
module-internal.h
module.c Merge branch 'android-4.9-q' of https://android.googlesource.com/kernel/common into lineage-18.1-caf-sdm845 2021-04-26 01:27:02 +03:00
module_signing.c
notifier.c x86/mm: split vmalloc_sync_all() 2020-04-02 17:20:26 +02:00
nsproxy.c
padata.c padata: purge get_cpu and reorder_via_wq from padata_do_serial 2020-05-27 16:41:53 +02:00
panic.c Merge android-4.9.197(e9766ef) into msm-4.9 2019-12-06 19:41:21 +08:00
params.c
pid.c UPSTREAM: locking/atomic, kref: Add KREF_INIT() 2021-01-05 16:00:48 +00:00
pid_namespace.c memcg: enable accounting for pids in nested pid namespaces 2021-09-22 11:43:08 +02:00
profile.c profiling: fix shift-out-of-bounds bugs 2021-09-26 13:36:18 +02:00
ptrace.c ptrace: Reimplement PTRACE_KILL by always sending SIGKILL 2022-06-14 16:52:28 +02:00
range.c
reboot.c reboot: fix overflow parsing reboot cpu number 2020-11-18 18:26:32 +01:00
relay.c kernel/relay.c: fix memleak on destroy relay channel 2020-08-26 10:29:03 +02:00
resource.c Merge android-4.9.96 (320d53a) into msm-4.9 2018-05-11 05:38:48 -07:00
seccomp.c seccomp: Add missing return in non-void function 2021-03-03 17:44:43 +01:00
signal.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-09-06 06:20:26 +03:00
smp.c Merge remote-tracking branch 'common/android-4.9-q' into android12-4.9-sdm845 2022-06-12 01:39:01 +03:00
smpboot.c sched/walt: Fix the memory leak of idle task load pointers 2018-09-20 19:00:55 +05:30
smpboot.h
softirq.c Mark HI and TASKLET softirq synchronous 2018-08-15 18:14:42 +02:00
stacktrace.c
stop_machine.c stop_machine: Use raw spinlocks 2018-08-03 07:55:24 +02:00
sys.c Merge remote-tracking branch 'common/android-4.9-q' into lineage-18.1-caf-sdm845 2021-10-19 16:05:50 +03:00
sys_ni.c BACKPORT: signal: support CLONE_PIDFD with pidfd_send_signal 2019-09-03 13:44:59 -07:00
sysctl.c Revert "add toggle for disabling newly added USB devices" 2023-03-01 21:14:36 +02:00
sysctl_binary.c net/ipv6/addrconf: IPv6 tethering enhancement 2018-03-15 11:36:45 -07:00
task_work.c
taskstats.c taskstats: fix data-race 2020-01-12 11:24:12 +01:00
test_kprobes.c
torture.c
tracepoint.c tracepoint: Do not fail unregistering a probe due to memory failure 2021-03-03 17:44:38 +01:00
tsacct.c taskstats: Cleanup the use of task->exit_code 2022-02-23 11:56:40 +01:00
ucount.c
uid16.c kernel: make groups_sort calling a responsibility group_info allocators 2018-01-10 09:29:52 +01:00
up.c
user-return-notifier.c
user.c ANDROID: proc: Add /proc/uid directory 2018-04-03 11:15:30 -07:00
user_namespace.c userns: move user access out of the mutex 2018-09-09 20:01:24 +02:00
utsname.c
utsname_sysctl.c sys: don't hold uts_sem while accessing userspace memory 2018-09-09 20:01:24 +02:00
watchdog.c ANDROID: hardlockup: detect hard lockups without NMIs using secondary cpus 2017-08-28 11:25:03 -07:00
watchdog_hld.c ANDROID: hardlockup: detect hard lockups without NMIs using secondary cpus 2017-08-28 11:25:03 -07:00
workqueue.c workqueue: make workqueue available early during boot 2022-06-25 11:45:09 +02:00
workqueue_internal.h UPSTREAM: psi: fix aggregation idle shut-off 2019-03-22 14:15:01 -07:00