Skip to contentSkip to conversation

bpf: fix unitialized warning

PATCH In review Stephen Hemminger 2 participants 3 messages Jul 4 – Jul 6

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: fix unitialized warning

Coverity complains unitialized use of structure.

Coverity ID: 504611

Fixes 17509d474226 ("bpf/validate: fix BPF_ADD of pointer to a scalar")
---
 lib/bpf/bpf_validate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bpf/bpf_validate.c +1 -1
index f9960088a2..44db85a5a3 100644
@@ -659,7 +659,7 @@ eval_apply_mask(struct bpf_reg_val *rv, uint64_t mask)
 static void
 eval_add(struct bpf_reg_val *rd, const struct bpf_reg_val *rs, uint64_t msk)
 {
-	struct bpf_reg_val rs_buf;
+	struct bpf_reg_val rs_buf = { 0 };
 	struct bpf_reg_val rv;
 
 	if (RTE_BPF_ARG_PTR_TYPE(rs->v.type) != 0) {
Signature · 1 line
2.53.0
#1 lore raw
Quoted 7 lines · On Fri, 3 Jul 2026 21:03:22 -0700 Stephen Hemminger…

Coverity complains unitialized use of structure.

Coverity ID: 504611

Fixes 17509d474226 ("bpf/validate: fix BPF_ADD of pointer to a scalar")

---

Ignore AI review of this patch. The CI AI review is using weak AI model and no tooling; it ends up hallucinating about code that doesn't exist. Better AI reviewing the reviewer sees...

Coverity 504611 is a true positive. eval_fill_max_bound() sets u, s, v.type, and mask, but not v.size or v.buf_size. In eval_add() the pointer+pointer path does eval_fill_max_bound(&rs_buf, msk); *rd = rs_buf; on a fresh local, so the struct copy propagates the uninitialized v.size/v.buf_size. Zero-init at declaration closes exactly that.

The AI review is quoting code that isn't there. eval_add() has no rs_buf = *rs; and no eval_apply_mask(&rs_buf, ...) call. That snippet looks reconstructed from the diff hunk header (eval_apply_mask, the preceding function) rather than the function actually being patched. Its central claim, that rs_buf is only touched via rs = &rs_buf inside the if, is wrong: the uninitialized read is the *rd = rs_buf copy, and rs then reads it after the block.

#2 lore raw
In reply to Stephen Hemminger
Quoted 32 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Saturday 4 July 2026 05:03
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Konstantin Ananyev <[email protected]>; Marat Khalili <[email protected]>
Subject: [PATCH] bpf: fix unitialized warning

Coverity complains unitialized use of structure.

Coverity ID: 504611

Fixes 17509d474226 ("bpf/validate: fix BPF_ADD of pointer to a scalar")
---
 lib/bpf/bpf_validate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bpf/bpf_validate.c +1 -2
index f9960088a2..44db85a5a3 100644
@@ -659,7 +659,7 @@ eval_apply_mask(struct bpf_reg_val *rv, uint64_t mask)
 static void
 eval_add(struct bpf_reg_val *rd, const struct bpf_reg_val *rs, uint64_t msk)
 {
-	struct bpf_reg_val rs_buf;
+	struct bpf_reg_val rs_buf = { 0 };
 	struct bpf_reg_val rv;
 
 	if (RTE_BPF_ARG_PTR_TYPE(rs->v.type) != 0) {
--
Quoted 1 line

2.53.0

The bug is real. Based on the intended meaning should then be:

	struct bpf_reg_val rs_buf = { .v.type = RTE_BPF_ARG_RAW };

Setting type to 0 (RTE_BPF_ARG_UNDEF) is too harsh disallowing even reading, while we only want to disallow dereferencing the result.

(Unfortunately, this whole dimension is still a massive TODO, this check is not even present on other ALU operations, and neither do sanitized tests pass which would catch this problem earlier.)