Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination in test_bpffs
@ 2026-03-10 10:21 Sun Jian
  2026-03-10 10:21 ` [PATCH 2/2] selftests/bpf: Skip bpffs debug iter checks when unavailable " Sun Jian
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Sun Jian @ 2026-03-10 10:21 UTC (permalink / raw)
  To: Andrii Nakryiko, Eduard Zingerman, Shuah Khan
  Cc: bpf, linux-kselftest, linux-kernel, Alexei Starovoitov,
	Daniel Borkmann, Sun Jian

read_iter() always NUL-terminated at the end of the buffer, so strstr()
could scan uninitialized stack bytes on short reads. Terminate at len and
use O_RDONLY.

Signed-off-by: Sun Jian <sun.jian.kdev@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/test_bpffs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
index ea933fd151c3..e8021ff0581c 100644
--- a/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpffs.c
@@ -17,11 +17,11 @@ static int read_iter(char *file)
 	char buf[1024];
 	int fd, len;
 
-	fd = open(file, 0);
+	fd = open(file, O_RDONLY);
 	if (fd < 0)
 		return -1;
-	while ((len = read(fd, buf, sizeof(buf))) > 0) {
-		buf[sizeof(buf) - 1] = '\0';
+	while ((len = read(fd, buf, sizeof(buf) - 1)) > 0) {
+		buf[len] = '\0';
 		if (strstr(buf, "iter")) {
 			close(fd);
 			return 0;

base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681
-- 
2.43.0


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

end of thread, other threads:[~2026-03-13  2:50 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 10:21 [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination in test_bpffs Sun Jian
2026-03-10 10:21 ` [PATCH 2/2] selftests/bpf: Skip bpffs debug iter checks when unavailable " Sun Jian
2026-03-10 12:32   ` Viktor Malik
2026-03-11  7:55     ` sun jian
2026-03-11 10:31       ` Viktor Malik
2026-03-12 21:44   ` Yonghong Song
2026-03-13  2:49     ` sun jian
2026-03-10 12:28 ` [PATCH 1/2] selftests/bpf: Fix read_iter buffer termination " Viktor Malik
2026-03-11  6:47   ` sun jian
2026-03-11 10:38     ` Viktor Malik
2026-03-12 21:41 ` Yonghong Song

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