lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190320173332.18105-5-alban@kinvolk.io>
Date:   Wed, 20 Mar 2019 18:33:30 +0100
From:   Alban Crequy <alban.crequy@...il.com>
To:     ast@...nel.org, daniel@...earbox.net
Cc:     netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
        alban@...volk.io, iago@...volk.io
Subject: [PATCH bpf-next v1 5/7] tools: bpftool: support loading map by fd from parent process

From: Alban Crequy <alban@...volk.io>

Using a file descriptor passed by the parent process enables
applications to fork a bpftool command to inspect a map they know by
file descriptor even when they don't support bpffs or map ids.

Documentation and bash completion updated as well.

Signed-off-by: Alban Crequy <alban@...volk.io>
---
 tools/bpf/bpftool/Documentation/bpftool-map.rst |  8 ++++++++
 tools/bpf/bpftool/bash-completion/bpftool       | 10 +++++-----
 tools/bpf/bpftool/map.c                         | 13 +++++++++++++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst
index dfd8352fa453..658fe2fb8ecf 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-map.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -265,6 +265,14 @@ would be lost as soon as bpftool exits).
 
   anon_inode:bpf-map
 
+**# bpftool map exec pinned /sys/fs/bpf/foo fd 99 cmd -- bpftool map show fd 99**
+
+::
+
+  10: hash  name some_map  flags 0x0
+	key 4B  value 8B  max_entries 2048  memlock 167936B
+
+
 SEE ALSO
 ========
 	**bpf**\ (2),
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index 63cd53c4d3a7..9ec1833bda1e 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -253,7 +253,7 @@ _bpftool()
             esac
 
             local PROG_TYPE='id pinned tag'
-            local MAP_TYPE='id pinned'
+            local MAP_TYPE='id pinned fd'
             case $command in
                 show|list)
                     [[ $prev != "$command" ]] && return 0
@@ -343,7 +343,7 @@ _bpftool()
                     obj=${words[3]}
 
                     if [[ ${words[-4]} == "map" ]]; then
-                        COMPREPLY=( $( compgen -W "id pinned" -- "$cur" ) )
+                        COMPREPLY=( $( compgen -W "id pinned fd" -- "$cur" ) )
                         return 0
                     fi
                     if [[ ${words[-3]} == "map" ]]; then
@@ -406,7 +406,7 @@ _bpftool()
             esac
             ;;
         map)
-            local MAP_TYPE='id pinned'
+            local MAP_TYPE='id pinned fd'
             case $command in
                 show|list|dump|peek|pop|dequeue)
                     case $prev in
@@ -462,7 +462,7 @@ _bpftool()
                             return 0
                             ;;
                         innermap)
-                            COMPREPLY+=( $( compgen -W "id pinned" -- "$cur" ) )
+                            COMPREPLY+=( $( compgen -W "id pinned fd" -- "$cur" ) )
                             return 0
                             ;;
                         id)
@@ -525,7 +525,7 @@ _bpftool()
                             # map, depending on the type of the map to update.
                             case "$(_bpftool_map_guess_map_type)" in
                                 array_of_maps|hash_of_maps)
-                                    local MAP_TYPE='id pinned'
+                                    local MAP_TYPE='id pinned fd'
                                     COMPREPLY+=( $( compgen -W "$MAP_TYPE" \
                                         -- "$cur" ) )
                                     return 0
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 768497364cee..9befcabc299d 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -125,6 +125,19 @@ int map_parse_fd(int *argc, char ***argv)
 		NEXT_ARGP();
 
 		return open_obj_pinned_any(path, BPF_OBJ_MAP);
+	} else if (is_prefix(**argv, "fd")) {
+		char *endptr;
+
+		NEXT_ARGP();
+
+		fd = strtoul(**argv, &endptr, 0);
+		if (*endptr) {
+			p_err("can't parse %s as fd", **argv);
+			return -1;
+		}
+		NEXT_ARGP();
+
+		return dup(fd);
 	}
 
 	p_err("expected 'id' or 'pinned', got: '%s'?", **argv);
-- 
2.20.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ