A private stack is hard to support together with an exception cleanup table on x86-64: a landing pad runs on the bpf_throw() walker's stack with its frame's registers put back from a spill area, and carrying the private stack's frame pointer through there as well would cost a register that architecture cannot spare. Force NO_PRIV_STACK in check_max_stack_depth(), where the choice is made, and do it on every architecture for now rather than just x86-64. The program still loads, but more than an optimization can be lost: check_max_stack_depth_subprog() checks a PRIV_STACK_ADAPTIVE subprogram against MAX_BPF_STACK on its own, and adds a NO_PRIV_STACK one to the depth its callers have to fit in -- so a bpf2bpf chain deep enough to need the private stack is now refused with "combined stack size of %d calls is %d. Too large". Signed-off-by: Yonghong Song --- kernel/bpf/verifier.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 7b74dd9b9f48..6462e9f2ffdc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5602,6 +5602,17 @@ static int check_max_stack_depth(struct bpf_verifier_env *env) } } + /* + * A pad rebuilds its frame from a spill area, and on x86-64 a private + * stack's frame pointer lives in r9, which no spill area holds. + * Refused on every arch rather than just that one. The subprograms + * below are then checked against MAX_BPF_STACK together rather than + * one at a time, so this can turn a program that would have loaded + * with a private stack into one that is too deep. + */ + if (env->cleanup_info_cnt) + priv_stack_mode = NO_PRIV_STACK; + if (priv_stack_mode == PRIV_STACK_UNKNOWN) priv_stack_mode = bpf_enable_priv_stack(env->prog); -- 2.53.0-Meta