tools: bpftool: fix infinite loop in map create [Linux 5.1]

tools: bpftool: fix infinite loop in map create [Linux 5.1]

This Linux kernel change "tools: bpftool: fix infinite loop in map create" is included in the Linux 5.1 release. This change is authored by Alban Crequy <alban [at] kinvolk.io> on Fri Apr 12 14:40:50 2019 +0200. The commit for this change in Linux stable tree is 8694d8c (patch).

tools: bpftool: fix infinite loop in map create

"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 <[email protected]>
Reviewed-by: Quentin Monnet <[email protected]>
Acked-by: Song Liu <[email protected]>
Reviewed-by: Jakub Kicinski <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Signed-off-by: Alexei Starovoitov <[email protected]>

There are 3 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 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 e0c650d..994a7e0 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;
        }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *