bpf: move arg:ctx type enforcement check inside the main logic loop

JIRA: https://issues.redhat.com/browse/RHEL-23649

commit add9c58cd44e88a15f285945e26bf0d9d81c5890
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Thu Jan 25 12:55:06 2024 -0800

    bpf: move arg:ctx type enforcement check inside the main logic loop

    Now that bpf and bpf-next trees converged and we don't run the risk of
    merge conflicts, move btf_validate_prog_ctx_type() into its most logical
    place inside the main logic loop.

    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20240125205510.3642094-4-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
This commit is contained in:
Jerome Marchand 2024-06-10 15:20:23 +02:00
parent 0333946db5
commit 9cb5a54a05
1 changed files with 4 additions and 17 deletions

View File

@ -7115,6 +7115,10 @@ int btf_prepare_func_args(struct bpf_verifier_env *env, int subprog)
bpf_log(log, "arg#%d has invalid combination of tags\n", i);
return -EINVAL;
}
if ((tags & ARG_TAG_CTX) &&
btf_validate_prog_ctx_type(log, btf, t, i, prog_type,
prog->expected_attach_type))
return -EINVAL;
sub->args[i].arg_type = ARG_PTR_TO_CTX;
continue;
}
@ -7161,23 +7165,6 @@ skip_pointer:
return -EINVAL;
}
for (i = 0; i < nargs; i++) {
const char *tag;
if (sub->args[i].arg_type != ARG_PTR_TO_CTX)
continue;
/* check if arg has "arg:ctx" tag */
t = btf_type_by_id(btf, args[i].type);
tag = btf_find_decl_tag_value(btf, fn_t, i, "arg:");
if (IS_ERR_OR_NULL(tag) || strcmp(tag, "ctx") != 0)
continue;
if (btf_validate_prog_ctx_type(log, btf, t, i, prog_type,
prog->expected_attach_type))
return -EINVAL;
}
sub->arg_cnt = nargs;
sub->args_cached = true;