linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: fix kmalloc bug in bpf_check
@ 2021-09-13 11:02 Dongliang Mu
  2021-09-13 15:33 ` Yonghong Song
  0 siblings, 1 reply; 3+ messages in thread
From: Dongliang Mu @ 2021-09-13 11:02 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Willy Tarreau
  Cc: Dongliang Mu, syzbot+f3e749d4c662818ae439, netdev, bpf, linux-kernel

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.

Reported-by: syzbot+f3e749d4c662818ae439@syzkaller.appspotmail.com
Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls")
Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
---
 kernel/bpf/verifier.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 047ac4b4703b..3c5a79f78bc5 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -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 ||
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix kmalloc bug in bpf_check
  2021-09-13 11:02 [PATCH] bpf: fix kmalloc bug in bpf_check Dongliang Mu
@ 2021-09-13 15:33 ` Yonghong Song
  2021-09-13 15:36   ` Dongliang Mu
  0 siblings, 1 reply; 3+ messages in thread
From: Yonghong Song @ 2021-09-13 15:33 UTC (permalink / raw)
  To: Dongliang Mu, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, John Fastabend,
	KP Singh, Willy Tarreau
  Cc: syzbot+f3e749d4c662818ae439, netdev, bpf, linux-kernel



On 9/13/21 4:02 AM, Dongliang Mu wrote:
> 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.
> 
> Reported-by: syzbot+f3e749d4c662818ae439@syzkaller.appspotmail.com
> Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls")
> Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>

Thanks for the fix. A similar patch has been proposed here:
https://lore.kernel.org/bpf/20210911005557.45518-1-cuibixuan@huawei.com/

> ---
>   kernel/bpf/verifier.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 047ac4b4703b..3c5a79f78bc5 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -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 ||
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: fix kmalloc bug in bpf_check
  2021-09-13 15:33 ` Yonghong Song
@ 2021-09-13 15:36   ` Dongliang Mu
  0 siblings, 0 replies; 3+ messages in thread
From: Dongliang Mu @ 2021-09-13 15:36 UTC (permalink / raw)
  To: Yonghong Song
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, John Fastabend, KP Singh,
	Willy Tarreau, syzbot+f3e749d4c662818ae439,
	open list:NETWORKING [GENERAL],
	bpf, linux-kernel

On Mon, Sep 13, 2021 at 11:34 PM Yonghong Song <yhs@fb.com> wrote:
>
>
>
> On 9/13/21 4:02 AM, Dongliang Mu wrote:
> > 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.
> >
> > Reported-by: syzbot+f3e749d4c662818ae439@syzkaller.appspotmail.com
> > Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls")
> > Signed-off-by: Dongliang Mu <mudongliangabcd@gmail.com>
>
> Thanks for the fix. A similar patch has been proposed here:
> https://lore.kernel.org/bpf/20210911005557.45518-1-cuibixuan@huawei.com/

OK, I see. Let's ignore this patch.

>
> > ---
> >   kernel/bpf/verifier.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index 047ac4b4703b..3c5a79f78bc5 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -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 ||
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-13 15:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13 11:02 [PATCH] bpf: fix kmalloc bug in bpf_check Dongliang Mu
2021-09-13 15:33 ` Yonghong Song
2021-09-13 15:36   ` Dongliang Mu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).