Skip to content

Commit d21d9a8

Browse files
kkdwvdSasha Levin
authored andcommitted
bpf: Don't mark STACK_INVALID as STACK_MISC in mark_stack_slot_misc
[ Upstream commit 69772f5 ] Inside mark_stack_slot_misc, we should not upgrade STACK_INVALID to STACK_MISC when allow_ptr_leaks is false, since invalid contents shouldn't be read unless the program has the relevant capabilities. The relaxation only makes sense when env->allow_ptr_leaks is true. However, such conversion in privileged mode becomes unnecessary, as invalid slots can be read without being upgraded to STACK_MISC. Currently, the condition is inverted (i.e. checking for true instead of false), simply remove it to restore correct behavior. Fixes: eaf18fe ("bpf: preserve STACK_ZERO slots on partial reg spills") Acked-by: Andrii Nakryiko <[email protected]> Reported-by: Tao Lyu <[email protected]> Signed-off-by: Kumar Kartikeya Dwivedi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 117ef3f commit d21d9a8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,14 +1200,17 @@ static bool is_spilled_scalar_reg64(const struct bpf_stack_state *stack)
12001200
/* Mark stack slot as STACK_MISC, unless it is already STACK_INVALID, in which
12011201
* case they are equivalent, or it's STACK_ZERO, in which case we preserve
12021202
* more precise STACK_ZERO.
1203-
* Note, in uprivileged mode leaving STACK_INVALID is wrong, so we take
1204-
* env->allow_ptr_leaks into account and force STACK_MISC, if necessary.
1203+
* Regardless of allow_ptr_leaks setting (i.e., privileged or unprivileged
1204+
* mode), we won't promote STACK_INVALID to STACK_MISC. In privileged case it is
1205+
* unnecessary as both are considered equivalent when loading data and pruning,
1206+
* in case of unprivileged mode it will be incorrect to allow reads of invalid
1207+
* slots.
12051208
*/
12061209
static void mark_stack_slot_misc(struct bpf_verifier_env *env, u8 *stype)
12071210
{
12081211
if (*stype == STACK_ZERO)
12091212
return;
1210-
if (env->allow_ptr_leaks && *stype == STACK_INVALID)
1213+
if (*stype == STACK_INVALID)
12111214
return;
12121215
*stype = STACK_MISC;
12131216
}

0 commit comments

Comments
 (0)