Skip to content

Commit 4ca030f

Browse files
kkdwvdmehmetb0
authored andcommitted
bpf: Don't mark STACK_INVALID as STACK_MISC in mark_stack_slot_misc
BugLink: https://bugs.launchpad.net/bugs/2096827 [ 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]> Signed-off-by: Koichiro Den <[email protected]>
1 parent dbefb41 commit 4ca030f

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
@@ -1205,14 +1205,17 @@ static bool is_spilled_scalar_reg64(const struct bpf_stack_state *stack)
12051205
/* Mark stack slot as STACK_MISC, unless it is already STACK_INVALID, in which
12061206
* case they are equivalent, or it's STACK_ZERO, in which case we preserve
12071207
* more precise STACK_ZERO.
1208-
* Note, in uprivileged mode leaving STACK_INVALID is wrong, so we take
1209-
* env->allow_ptr_leaks into account and force STACK_MISC, if necessary.
1208+
* Regardless of allow_ptr_leaks setting (i.e., privileged or unprivileged
1209+
* mode), we won't promote STACK_INVALID to STACK_MISC. In privileged case it is
1210+
* unnecessary as both are considered equivalent when loading data and pruning,
1211+
* in case of unprivileged mode it will be incorrect to allow reads of invalid
1212+
* slots.
12101213
*/
12111214
static void mark_stack_slot_misc(struct bpf_verifier_env *env, u8 *stype)
12121215
{
12131216
if (*stype == STACK_ZERO)
12141217
return;
1215-
if (env->allow_ptr_leaks && *stype == STACK_INVALID)
1218+
if (*stype == STACK_INVALID)
12161219
return;
12171220
*stype = STACK_MISC;
12181221
}

0 commit comments

Comments
 (0)