All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH dwarves] btf_encoder: always initialize func_state to 0
@ 2025-01-10  2:31 Ihor Solodrai
  2025-01-10 10:39 ` Alan Maguire
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Ihor Solodrai @ 2025-01-10  2:31 UTC (permalink / raw)
  To: dwarves; +Cc: bpf, acme, alan.maguire, eddyz87, andrii, mykolal, olsajiri

BPF CI caught a segfault on aarch64 and s390x [1] after recent merges
into the master branch.

The segfault happened at free(func_state->annots) in
btf_encoder__delete_saved_funcs().

func_state->annots arrived there uninitialized because after patch [2]
in some cases func_state may be allocated with a realloc, but was not
zeroed out.

Fix this bug by always memset-ing a func_state to zero in
btf_encoder__alloc_func_state().

[1] https://github.com/kernel-patches/bpf/actions/runs/12700574327
[2] https://lore.kernel.org/dwarves/20250109185950.653110-11-ihor.solodrai@pm.me/
---
 btf_encoder.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index 78efd70..511c1ea 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -1083,7 +1083,7 @@ static bool funcs__match(struct btf_encoder_func_state *s1,
 
 static struct btf_encoder_func_state *btf_encoder__alloc_func_state(struct btf_encoder *encoder)
 {
-	struct btf_encoder_func_state *tmp;
+	struct btf_encoder_func_state *state, *tmp;
 
 	if (encoder->func_states.cnt >= encoder->func_states.cap) {
 
@@ -1100,7 +1100,10 @@ static struct btf_encoder_func_state *btf_encoder__alloc_func_state(struct btf_e
 		encoder->func_states.array = tmp;
 	}
 
-	return &encoder->func_states.array[encoder->func_states.cnt++];
+	state = &encoder->func_states.array[encoder->func_states.cnt++];
+	memset(state, 0, sizeof(*state));
+
+	return state;
 }
 
 static int32_t btf_encoder__save_func(struct btf_encoder *encoder, struct function *fn, struct elf_function *func)
-- 
2.47.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-01-17  0:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10  2:31 [PATCH dwarves] btf_encoder: always initialize func_state to 0 Ihor Solodrai
2025-01-10 10:39 ` Alan Maguire
2025-01-10 13:48   ` Arnaldo Carvalho de Melo
2025-01-10 15:46     ` Ihor Solodrai
2025-01-10 13:51 ` Arnaldo Carvalho de Melo
2025-01-10 15:58   ` Ihor Solodrai
2025-01-10 22:13     ` Andrii Nakryiko
2025-01-15 21:06     ` Ihor Solodrai
2025-01-16 23:41       ` Andrii Nakryiko
2025-01-17  0:14         ` Ihor Solodrai
2025-01-10 13:55 ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.