]> git.baikalelectronics.ru Git - kernel.git/commit
bpf, arm: Fix register clobbering in div/mod implementation
authorJohan Almbladh <johan.almbladh@anyfinetworks.com>
Tue, 28 Sep 2021 09:13:10 +0000 (11:13 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 29 Sep 2021 14:04:50 +0000 (16:04 +0200)
commit93f22aeaa9f9bd08094b2edab1f123a3dcd668ed
treef8bd8d2591e0cb36369a8218afb0898b1f9bd765
parent393dc5672f82e596ac3388be6fdff12cdf3d17ea
bpf, arm: Fix register clobbering in div/mod implementation

On ARM CPUs that lack div/mod instructions, ALU32 BPF_DIV and BPF_MOD are
implemented using a call to a helper function. Before, the emitted code
for those function calls failed to preserve caller-saved ARM registers.
Since some of those registers happen to be mapped to BPF registers, it
resulted in eBPF register values being overwritten.

This patch emits code to push and pop the remaining caller-saved ARM
registers r2-r3 into the stack during the div/mod function call. ARM
registers r0-r1 are used as arguments and return value, and those were
already saved and restored correctly.

Fixes: d3c26ea1e931 ("arm: eBPF JIT compiler")
Signed-off-by: Johan Almbladh <johan.almbladh@anyfinetworks.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
arch/arm/net/bpf_jit_32.c