diff mbox series

[1/2] tools, bpftool: Avoid array index warnings.

Message ID 20201027233646.3434896-1-irogers@google.com
State New
Headers show
Series [1/2] tools, bpftool: Avoid array index warnings. | expand

Commit Message

Ian Rogers Oct. 27, 2020, 11:36 p.m. UTC
The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads
if this isn't defined. Working around this avoids -Wno-array-bounds with
clang.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/bpf/bpftool/feature.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Andrii Nakryiko Oct. 28, 2020, 3:40 a.m. UTC | #1
On Tue, Oct 27, 2020 at 4:37 PM Ian Rogers <irogers@google.com> wrote:
>

> The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads

> if this isn't defined. Working around this avoids -Wno-array-bounds with

> clang.

>

> Signed-off-by: Ian Rogers <irogers@google.com>

> ---


Acked-by: Andrii Nakryiko <andrii@kernel.org>


>  tools/bpf/bpftool/feature.c | 7 ++++++-

>  1 file changed, 6 insertions(+), 1 deletion(-)

>

> diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c

> index a43a6f10b564..359960a8f1de 100644

> --- a/tools/bpf/bpftool/feature.c

> +++ b/tools/bpf/bpftool/feature.c

> @@ -843,9 +843,14 @@ static int handle_perms(void)

>                 else

>                         p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'",

>                               capability_msg(bpf_caps, 0),

> +#ifdef CAP_BPF

>                               capability_msg(bpf_caps, 1),

>                               capability_msg(bpf_caps, 2),

> -                             capability_msg(bpf_caps, 3));

> +                             capability_msg(bpf_caps, 3)

> +#else

> +                               "", "", "", "", "", ""

> +#endif /* CAP_BPF */

> +                               );

>                 goto exit_free;

>         }

>

> --

> 2.29.0.rc2.309.g374f81d7ae-goog

>
Tobias Klauser Oct. 28, 2020, 1:44 p.m. UTC | #2
On 2020-10-28 at 00:36:45 +0100, Ian Rogers <irogers@google.com> wrote:
> The bpf_caps array is shorter without CAP_BPF, avoid out of bounds reads

> if this isn't defined. Working around this avoids -Wno-array-bounds with

> clang.

> 

> Signed-off-by: Ian Rogers <irogers@google.com>


Reviewed-by: Tobias Klauser <tklauser@distanz.ch>
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/feature.c b/tools/bpf/bpftool/feature.c
index a43a6f10b564..359960a8f1de 100644
--- a/tools/bpf/bpftool/feature.c
+++ b/tools/bpf/bpftool/feature.c
@@ -843,9 +843,14 @@  static int handle_perms(void)
 		else
 			p_err("missing %s%s%s%s%s%s%s%srequired for full feature probing; run as root or use 'unprivileged'",
 			      capability_msg(bpf_caps, 0),
+#ifdef CAP_BPF
 			      capability_msg(bpf_caps, 1),
 			      capability_msg(bpf_caps, 2),
-			      capability_msg(bpf_caps, 3));
+			      capability_msg(bpf_caps, 3)
+#else
+				"", "", "", "", "", ""
+#endif /* CAP_BPF */
+				);
 		goto exit_free;
 	}