]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tools: bpftool: fix infinite loop in map create
authorAlban Crequy <alban@kinvolk.io>
Fri, 12 Apr 2019 12:40:50 +0000 (14:40 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 May 2019 16:22:27 +0000 (18:22 +0200)
[ Upstream commit 8694d8c1f82cccec9380e0d3720b84eee315dfb7 ]

"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: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/bpf/bpftool/map.c

index 1ef1ee2280a28330925acf9aab4bd7dd8ffade3f..227766d9f43b1d09504c957f86393d422a610e20 100644 (file)
@@ -1111,6 +1111,9 @@ static int do_create(int argc, char **argv)
                                return -1;
                        }
                        NEXT_ARG();
+               } else {
+                       p_err("unknown arg %s", *argv);
+                       return -1;
                }
        }