Skip to content

Commit

Permalink
bpf: Forbid trampoline attach for functions with variable arguments
Browse files Browse the repository at this point in the history
[ Upstream commit 3137939 ]

We can't currently allow to attach functions with variable arguments.
The problem is that we should save all the registers for arguments,
which is probably doable, but if caller uses more than 6 arguments,
we need stack data, which will be wrong, because of the extra stack
frame we do in bpf trampoline, so we could crash.

Also currently there's malformed trampoline code generated for such
functions at the moment as described in:

  https://lore.kernel.org/bpf/20210429212834.82621-1-jolsa@kernel.org/

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210505132529.401047-1-jolsa@kernel.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
olsajiri authored and gregkh committed Jun 16, 2021
1 parent fb91ab4 commit 584b2c7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kernel/bpf/btf.c
Expand Up @@ -4960,13 +4960,25 @@ int btf_distill_func_proto(struct bpf_verifier_log *log,
m->ret_size = ret;

for (i = 0; i < nargs; i++) {
if (i == nargs - 1 && args[i].type == 0) {
bpf_log(log,
"The function %s with variable args is unsupported.\n",
tname);
return -EINVAL;
}
ret = __get_type_size(btf, args[i].type, &t);
if (ret < 0) {
bpf_log(log,
"The function %s arg%d type %s is unsupported.\n",
tname, i, btf_kind_str[BTF_INFO_KIND(t->info)]);
return -EINVAL;
}
if (ret == 0) {
bpf_log(log,
"The function %s has malformed void argument.\n",
tname);
return -EINVAL;
}
m->arg_size[i] = ret;
}
m->nr_args = nargs;
Expand Down

0 comments on commit 584b2c7

Please sign in to comment.