]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commit
bpf: Clear subreg_def for global function return values
authorIlya Leoshkevich <iii@linux.ibm.com>
Fri, 12 Feb 2021 04:04:08 +0000 (05:04 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 15 Mar 2021 14:08:59 +0000 (15:08 +0100)
commit1f0a2930e2d294d632d3a036c255a3e0d92f78b5
treea0536125278eb4629cd6e6a59e16e49d705a5f76
parent922a3eeb906d9c8e56cf38e70c0427c5fbecc06e
bpf: Clear subreg_def for global function return values

[ Upstream commit 45159b27637b0fef6d5ddb86fc7c46b13c77960f ]

test_global_func4 fails on s390 as reported by Yauheni in [1].

The immediate problem is that the zext code includes the instruction,
whose result needs to be zero-extended, into the zero-extension
patchlet, and if this instruction happens to be a branch, then its
delta is not adjusted. As a result, the verifier rejects the program
later.

However, according to [2], as far as the verifier's algorithm is
concerned and as specified by the insn_no_def() function, branching
insns do not define anything. This includes call insns, even though
one might argue that they define %r0.

This means that the real problem is that zero extension kicks in at
all. This happens because clear_caller_saved_regs() sets BPF_REG_0's
subreg_def after global function calls. This can be fixed in many
ways; this patch mimics what helper function call handling already
does.

  [1] https://lore.kernel.org/bpf/20200903140542.156624-1-yauheni.kaliuta@redhat.com/
  [2] https://lore.kernel.org/bpf/CAADnVQ+2RPKcftZw8d+B1UwB35cpBhpF5u3OocNh90D9pETPwg@mail.gmail.com/

Fixes: 51c39bb1d5d1 ("bpf: Introduce function-by-function verification")
Reported-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210212040408.90109-1-iii@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
kernel/bpf/verifier.c