diff mbox series

[bpf,v2] tools: bpftool: fix infinite loop in map create

Message ID 20190412124050.32120-1-alban@kinvolk.io
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf,v2] tools: bpftool: fix infinite loop in map create | expand

Commit Message

Alban Crequy April 12, 2019, 12:40 p.m. UTC
From: Alban Crequy <alban@kinvolk.io>

"bpftool map create" has an infinite loop on "while (argc)". The error
case is missing.

Symptoms: when forgetting to type the keyword 'type' in front of 'hash':
$ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
(infinite loop, taking all the CPU)
^C

After the patch:
$ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
Error: unknown arg hash

Fixes: 0b592b5a01be ("tools: bpftool: add map create command")
Signed-off-by: Alban Crequy <alban@kinvolk.io>

---

Changes in v2:
- Explain the cause of the bug in commitmsg
- Add the "fixes" line in the commitmsg (Jakub's review)
- Rebase on the bpf tree

v1 was initially based on bpf-next and submitted on
https://marc.info/?l=linux-kernel&m=155310327709613&w=2
---
 tools/bpf/bpftool/map.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Quentin Monnet April 12, 2019, 1:20 p.m. UTC | #1
2019-04-12 14:40 UTC+0200 ~ Alban Crequy <alban.crequy@gmail.com>
> From: Alban Crequy <alban@kinvolk.io>
> 
> "bpftool map create" has an infinite loop on "while (argc)". The error
> case is missing.
> 
> Symptoms: when forgetting to type the keyword 'type' in front of 'hash':
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> (infinite loop, taking all the CPU)
> ^C
> 
> After the patch:
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> Error: unknown arg hash
> 
> Fixes: 0b592b5a01be ("tools: bpftool: add map create command")
> Signed-off-by: Alban Crequy <alban@kinvolk.io>
> 
> ---
> 
> Changes in v2:
> - Explain the cause of the bug in commitmsg
> - Add the "fixes" line in the commitmsg (Jakub's review)
> - Rebase on the bpf tree
> 
> v1 was initially based on bpf-next and submitted on
> https://marc.info/?l=linux-kernel&m=155310327709613&w=2
> ---
>  tools/bpf/bpftool/map.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 05b029b934a6..1ccc38718458 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -1151,6 +1151,9 @@ static int do_create(int argc, char **argv)
>  				return -1;
>  			}
>  			NEXT_ARG();
> +		} else {
> +			p_err("unknown arg %s", *argv);
> +			return -1;
>  		}
>  	}
>  
> 

Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>

Thanks Alban!
Song Liu April 12, 2019, 6:07 p.m. UTC | #2
On Fri, Apr 12, 2019 at 6:21 AM Quentin Monnet
<quentin.monnet@netronome.com> wrote:
>
> 2019-04-12 14:40 UTC+0200 ~ Alban Crequy <alban.crequy@gmail.com>
> > From: Alban Crequy <alban@kinvolk.io>
> >
> > "bpftool map create" has an infinite loop on "while (argc)". The error
> > case is missing.
> >
> > Symptoms: when forgetting to type the keyword 'type' in front of 'hash':
> > $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> > (infinite loop, taking all the CPU)
> > ^C
> >
> > After the patch:
> > $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> > Error: unknown arg hash
> >
> > Fixes: 0b592b5a01be ("tools: bpftool: add map create command")
> > Signed-off-by: Alban Crequy <alban@kinvolk.io>

Acked-by: Song Liu <songliubraving@fb.com>

Thanks for the fix!

> >
> > ---
> >
> > Changes in v2:
> > - Explain the cause of the bug in commitmsg
> > - Add the "fixes" line in the commitmsg (Jakub's review)
> > - Rebase on the bpf tree
> >
> > v1 was initially based on bpf-next and submitted on
> > https://marc.info/?l=linux-kernel&m=155310327709613&w=2
> > ---
> >  tools/bpf/bpftool/map.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> > index 05b029b934a6..1ccc38718458 100644
> > --- a/tools/bpf/bpftool/map.c
> > +++ b/tools/bpf/bpftool/map.c
> > @@ -1151,6 +1151,9 @@ static int do_create(int argc, char **argv)
> >                               return -1;
> >                       }
> >                       NEXT_ARG();
> > +             } else {
> > +                     p_err("unknown arg %s", *argv);
> > +                     return -1;
> >               }
> >       }
> >
> >
>
> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
>
> Thanks Alban!
Jakub Kicinski April 12, 2019, 11:45 p.m. UTC | #3
On Fri, 12 Apr 2019 14:40:50 +0200, Alban Crequy wrote:
> From: Alban Crequy <alban@kinvolk.io>
> 
> "bpftool map create" has an infinite loop on "while (argc)". The error
> case is missing.
> 
> Symptoms: when forgetting to type the keyword 'type' in front of 'hash':
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> (infinite loop, taking all the CPU)
> ^C
> 
> After the patch:
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> Error: unknown arg hash
> 
> Fixes: 0b592b5a01be ("tools: bpftool: add map create command")
> Signed-off-by: Alban Crequy <alban@kinvolk.io>

Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Daniel Borkmann April 16, 2019, 8:52 a.m. UTC | #4
On 04/12/2019 02:40 PM, Alban Crequy wrote:
> From: Alban Crequy <alban@kinvolk.io>
> 
> "bpftool map create" has an infinite loop on "while (argc)". The error
> case is missing.
> 
> Symptoms: when forgetting to type the keyword 'type' in front of 'hash':
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> (infinite loop, taking all the CPU)
> ^C
> 
> After the patch:
> $ sudo bpftool map create /sys/fs/bpf/dir/foobar hash key 8 value 8 entries 128
> Error: unknown arg hash
> 
> Fixes: 0b592b5a01be ("tools: bpftool: add map create command")
> Signed-off-by: Alban Crequy <alban@kinvolk.io>

Applied, thanks!
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 05b029b934a6..1ccc38718458 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -1151,6 +1151,9 @@  static int do_create(int argc, char **argv)
 				return -1;
 			}
 			NEXT_ARG();
+		} else {
+			p_err("unknown arg %s", *argv);
+			return -1;
 		}
 	}