bpf: fix kmalloc bug in bpf_check
Subsystems (4)
PATCH 1/1 bpf: fix kmalloc bug in bpf_check
Since 7661809d493b ("mm: don't allow oversized kvmalloc() calls ") does not allow oversized kvmalloc, it triggers a kmalloc bug warning at bpf_check.
Fix it by adding a sanity check in th check_btf_line.
--- kernel/bpf/verifier.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/bpf/verifier.c +3 -0
@@ -9913,6 +9913,9 @@ static int check_btf_line(struct bpf_verifier_env *env,if (!nr_linfo)return 0 ; +if (nr_linfo >INT_MAX /sizeof (struct bpf_line_info )) +return -EINVAL ; + rec_size = attr->line_info_rec_size; if (rec_size < MIN_BPF_LINEINFO_SIZE || rec_size > MAX_LINEINFO_REC_SIZE ||
Signature · 1 line
2.25.1
Quoted 9 lines · Dongliang Mu
Since
7661809d493b("mm: don't allow oversizedkvmalloc()calls ") does not allow oversized kvmalloc, it triggers a kmalloc bug warning atbpf_check.Fix it by adding a sanity check in th
check_btf_line.Reported-by [email protected]Fixes 7661809d493b ("mm: don't allow oversized kvmalloc() calls")Signed-off-by Dongliang Mu <[email protected]>
Thanks for the fix. A similar patch has been proposed here:
https://lore.kernel.org/bpf/[email protected]/
Quoted 19 lines
--- kernel/bpf/verifier.c | 3 +++ 1 file changed, 3 insertions(+)kernel/bpf/verifier.c +3
-0@@ -9913,6 +9913,9 @@ static int check_btf_line(struct bpf_verifier_env *env,if (!nr_linfo)return 0 ; +if (nr_linfo >INT_MAX /sizeof (struct bpf_line_info )) +return -EINVAL ; + rec_size = attr->line_info_rec_size; if (rec_size < MIN_BPF_LINEINFO_SIZE || rec_size > MAX_LINEINFO_REC_SIZE ||
Quoted 8 lines · Yonghong Song
Quoted 4 lines · Dongliang Mu
Since
7661809d493b("mm: don't allow oversizedkvmalloc()calls ") does not allow oversized kvmalloc, it triggers a kmalloc bug warning atbpf_check.
Quoted 8 lines
Quoted 5 lines
Fix it by adding a sanity check in th
check_btf_line.Reported-by [email protected]Fixes 7661809d493b ("mm: don't allow oversized kvmalloc() calls")Signed-off-by Dongliang Mu <[email protected]>Thanks for the fix. A similar patch has been proposed here:
https://lore.kernel.org/bpf/[email protected]/
OK, I see. Let's ignore this patch.
Quoted 20 lines
Quoted 20 lines
--- kernel/bpf/verifier.c | 3 +++ 1 file changed, 3 insertions(+)kernel/bpf/verifier.c +3
-0@@ -9913,6 +9913,9 @@ static int check_btf_line(struct bpf_verifier_env *env,if (!nr_linfo)return 0 ; +if (nr_linfo >INT_MAX /sizeof (struct bpf_line_info )) +return -EINVAL ; + rec_size = attr->line_info_rec_size; if (rec_size < MIN_BPF_LINEINFO_SIZE || rec_size > MAX_LINEINFO_REC_SIZE ||