提交 9d1b583d 编写于 作者: D Daniel Borkmann 提交者: Yang Yingliang

bpf: Inherit expanded/patched seen count from old aux data

mainline inclusion
from mainline-v5.13-rc7
commit d203b0fd
category: bugfix
bugzilla: NA
CVE: CVE-2021-33624

--------------------------------

Instead of relying on current env->pass_cnt, use the seen count from the
old aux data in adjust_insn_aux_data(), and expand it to the new range of
patched instructions. This change is valid given we always expand 1:n
with n>=1, so what applies to the old/original instruction needs to apply
for the replacement as well.

Not relying on env->pass_cnt is a prerequisite for a later change where we
want to avoid marking an instruction seen when verified under speculative
execution path.
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: NJohn Fastabend <john.fastabend@gmail.com>
Reviewed-by: NBenedict Schlueter <benedict.schlueter@rub.de>
Reviewed-by: NPiotr Krysiuk <piotras@gmail.com>
Acked-by: NAlexei Starovoitov <ast@kernel.org>

Conflicts:
  kernel/bpf/verifier.c

seen of bpf_insn_aux_data is bool in kernel-4.19.
Signed-off-by: NHe Fengqing <hefengqing@huawei.com>
Reviewed-by: NKuohai Xu <xukuohai@huawei.com>
Reviewed-by: NXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 040bd002
...@@ -5905,6 +5905,7 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len, ...@@ -5905,6 +5905,7 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len,
u32 off, u32 cnt) u32 off, u32 cnt)
{ {
struct bpf_insn_aux_data *new_data, *old_data = env->insn_aux_data; struct bpf_insn_aux_data *new_data, *old_data = env->insn_aux_data;
bool old_seen = old_data[off].seen;
int i; int i;
if (cnt == 1) if (cnt == 1)
...@@ -5916,8 +5917,10 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len, ...@@ -5916,8 +5917,10 @@ static int adjust_insn_aux_data(struct bpf_verifier_env *env, u32 prog_len,
memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off); memcpy(new_data, old_data, sizeof(struct bpf_insn_aux_data) * off);
memcpy(new_data + off + cnt - 1, old_data + off, memcpy(new_data + off + cnt - 1, old_data + off,
sizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1)); sizeof(struct bpf_insn_aux_data) * (prog_len - off - cnt + 1));
for (i = off; i < off + cnt - 1; i++) for (i = off; i < off + cnt - 1; i++) {
new_data[i].seen = true; /* Expand insni[off]'s seen count to the patched range. */
new_data[i].seen = old_seen;
}
env->insn_aux_data = new_data; env->insn_aux_data = new_data;
vfree(old_data); vfree(old_data);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册