Skip to content

Commit a11ca29

Browse files
borkmanngregkh
authored andcommitted
bpf: Remove superfluous aux sanitation on subprog rejection
commit 59089a1 upstream. Follow-up to fe9a5ca ("bpf: Do not mark insn as seen under speculative path verification"). The sanitize_insn_aux_data() helper does not serve a particular purpose in today's code. The original intention for the helper was that if function-by-function verification fails, a given program would be cleared from temporary insn_aux_data[], and then its verification would be re-attempted in the context of the main program a second time. However, a failure in do_check_subprogs() will skip do_check_main() and propagate the error to the user instead, thus such situation can never occur. Given its interaction is not compatible to the Spectre v1 mitigation (due to comparing aux->seen with env->pass_cnt), just remove sanitize_insn_aux_data() to avoid future bugs in this area. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 0e92806 commit a11ca29

File tree

1 file changed

+0
-34
lines changed

1 file changed

+0
-34
lines changed

kernel/bpf/verifier.c

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11707,37 +11707,6 @@ static void free_states(struct bpf_verifier_env *env)
1170711707
}
1170811708
}
1170911709

11710-
/* The verifier is using insn_aux_data[] to store temporary data during
11711-
* verification and to store information for passes that run after the
11712-
* verification like dead code sanitization. do_check_common() for subprogram N
11713-
* may analyze many other subprograms. sanitize_insn_aux_data() clears all
11714-
* temporary data after do_check_common() finds that subprogram N cannot be
11715-
* verified independently. pass_cnt counts the number of times
11716-
* do_check_common() was run and insn->aux->seen tells the pass number
11717-
* insn_aux_data was touched. These variables are compared to clear temporary
11718-
* data from failed pass. For testing and experiments do_check_common() can be
11719-
* run multiple times even when prior attempt to verify is unsuccessful.
11720-
*
11721-
* Note that special handling is needed on !env->bypass_spec_v1 if this is
11722-
* ever called outside of error path with subsequent program rejection.
11723-
*/
11724-
static void sanitize_insn_aux_data(struct bpf_verifier_env *env)
11725-
{
11726-
struct bpf_insn *insn = env->prog->insnsi;
11727-
struct bpf_insn_aux_data *aux;
11728-
int i, class;
11729-
11730-
for (i = 0; i < env->prog->len; i++) {
11731-
class = BPF_CLASS(insn[i].code);
11732-
if (class != BPF_LDX && class != BPF_STX)
11733-
continue;
11734-
aux = &env->insn_aux_data[i];
11735-
if (aux->seen != env->pass_cnt)
11736-
continue;
11737-
memset(aux, 0, offsetof(typeof(*aux), orig_idx));
11738-
}
11739-
}
11740-
1174111710
static int do_check_common(struct bpf_verifier_env *env, int subprog)
1174211711
{
1174311712
bool pop_log = !(env->log.level & BPF_LOG_LEVEL2);
@@ -11807,9 +11776,6 @@ static int do_check_common(struct bpf_verifier_env *env, int subprog)
1180711776
if (!ret && pop_log)
1180811777
bpf_vlog_reset(&env->log, 0);
1180911778
free_states(env);
11810-
if (ret)
11811-
/* clean aux data in case subprog was rejected */
11812-
sanitize_insn_aux_data(env);
1181311779
return ret;
1181411780
}
1181511781

0 commit comments

Comments
 (0)