Skip to contentSkip to conversation

bpf: ignore expected GCC warning in test_global_func10.c

PATCH Applied Jose E. Marchesi 2 participants 2 messages May 11, 2024 – May 13, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: ignore expected GCC warning in test_global_func10.c

The BPF selftest global_func10 in progs/test_global_func10.c contains:

  struct Small {
  	long x;
  };

  struct Big {
  	long x;
  	long y;
  };

[...]

__noinline int foo(const struct Big *big)

  {
	if (!big)
		return 0;

	return bpf_get_prandom_u32() < big->y;

}

[...]

SEC("cgroup_skb/ingress")
__failure __msg("invalid indirect access to stack") int global_func10(struct __sk_buff *skb)

  {
	const struct Small small = {.x = skb->len };

	return foo((struct Big *)&small) ? 1 : 0;

}

GCC emits a "maybe uninitialized" warning for the code above, because it knows foo' accesses big->y'.

Since the purpose of this selftest is to check that the verifier will fail on this sort of invalid memory access, this patch just silences the compiler warning.

Tested in bpf-next master.
No regressions.

---
 tools/testing/selftests/bpf/progs/test_global_func10.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/bpf/progs/test_global_func10.c +4 -0
index 8fba3f3649e2..5da001ca57a5 100644
@@ -4,6 +4,10 @@
 #include <bpf/bpf_helpers.h>
 #include "bpf_misc.h"
 
+#if !defined(__clang__)
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+#endif
+
 struct Small {
 	long x;
 };
Signature · 1 line
2.30.2
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 11 lines · On Sat, 11 May 2024 23:23:49 +0200 you wrote:

The BPF selftest global_func10 in progs/test_global_func10.c contains:

  struct Small {
  	long x;
  };

  struct Big {
  	long x;
  	long y;
  };
Quoted 1 line

[...]

Here is the summary with links:
- [bpf-next] bpf: ignore expected GCC warning in test_global_func10.c

    https://git.kernel.org/bpf/bpf-next/c/6a2f786e6905

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html