bpf: Handle return value of BPF_PROG_TYPE_STRUCT_OPS prog
authorHou Tao <houtao1@huawei.com>
Tue, 14 Sep 2021 02:33:51 +0000 (10:33 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Oct 2021 13:55:50 +0000 (15:55 +0200)
commitd93f65586c59a555dc4ef2fe365d32457bef0fde
treefd918bd1d6478812be44a53621dc14cb8f1b260d
parent12cbdaeeb5d4dfde7a8c2f9eed93bcfa4f4653cd
bpf: Handle return value of BPF_PROG_TYPE_STRUCT_OPS prog

[ Upstream commit 356ed64991c6847a0c4f2e8fa3b1133f7a14f1fc ]

Currently if a function ptr in struct_ops has a return value, its
caller will get a random return value from it, because the return
value of related BPF_PROG_TYPE_STRUCT_OPS prog is just dropped.

So adding a new flag BPF_TRAMP_F_RET_FENTRY_RET to tell bpf trampoline
to save and return the return value of struct_ops prog if ret_size of
the function ptr is greater than 0. Also restricting the flag to be
used alone.

Fixes: 85d33df357b6 ("bpf: Introduce BPF_MAP_TYPE_STRUCT_OPS")
Signed-off-by: Hou Tao <houtao1@huawei.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20210914023351.3664499-1-houtao1@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/x86/net/bpf_jit_comp.c
include/linux/bpf.h
kernel/bpf/bpf_struct_ops.c