BPF List
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: add check for invalid name in btf_name_valid_section()
@ 2024-08-23 10:43 Jeongjun Park
  2024-08-29  2:36 ` Alexei Starovoitov
  0 siblings, 1 reply; 9+ messages in thread
From: Jeongjun Park @ 2024-08-23 10:43 UTC (permalink / raw)
  To: martin.lau, ast, daniel, andrii
  Cc: eddyz87, song, yonghong.song, john.fastabend, kpsingh, sdf,
	haoluo, jolsa, bpf, linux-kernel, Jeongjun Park

If the length of the name string is 1 and the value of name[0] is NULL 
byte, an OOB vulnerability occurs in btf_name_valid_section() and the 
return value is true, so the invalid name passes the check. 

To solve this, you need to check if the first position is NULL byte.

Fixes: bd70a8fb7ca4 ("bpf: Allow all printable characters in BTF DATASEC names")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
 kernel/bpf/btf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 520f49f422fe..5c24ea1a65a4 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -823,6 +823,9 @@ static bool btf_name_valid_section(const struct btf *btf, u32 offset)
 	const char *src = btf_str_by_offset(btf, offset);
 	const char *src_limit;
 
+	if (!*src)
+		return false;
+
 	/* set a limit on identifier length */
 	src_limit = src + KSYM_NAME_LEN;
 	src++;
--

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

end of thread, other threads:[~2024-08-30 18:04 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-23 10:43 [PATCH bpf] bpf: add check for invalid name in btf_name_valid_section() Jeongjun Park
2024-08-29  2:36 ` Alexei Starovoitov
2024-08-29  3:45   ` Jeongjun Park
2024-08-29  5:45     ` Eduard Zingerman
2024-08-30  1:26       ` Eduard Zingerman
2024-08-30  2:03         ` Jeongjun Park
2024-08-30  9:42           ` Eduard Zingerman
2024-08-30 11:41             ` Jeongjun Park
2024-08-30 18:04               ` Eduard Zingerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox