Skip to contentSkip to conversation

mmap01: initialize buffer in check_file()

PATCH In review Sven Schnelle 4 participants 7 messages Jan 22, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmap01: initialize buffer in check_file()

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

---
 testcases/kernel/syscalls/mmap/mmap01.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/syscalls/mmap/mmap01.c +1 -0
index c93c37ceda52..ff09bc635c74 100644
@@ -36,6 +36,7 @@ static void check_file(void)
 	int i, fildes, buf_len = sizeof(STRING) + 3;
 	char buf[buf_len];
 
+	memset(buf, 0, sizeof(buf));
 	fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
 	SAFE_READ(0, fildes, buf, sizeof(buf));
 
Signature · 5 lines
2.47.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v1 1/1
#1 lore raw

Hi Sven,

Quoted 5 lines

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Looks reasonable to me.

@Cyril a candidate for merge before the release.

Kind regards,
Petr

Quoted 16 lines
---
 testcases/kernel/syscalls/mmap/mmap01.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/syscalls/mmap/mmap01.c +1 -0
index c93c37ceda52..ff09bc635c74 100644
@@ -36,6 +36,7 @@ static void check_file(void)
 	int i, fildes, buf_len = sizeof(STRING) + 3;
 	char buf[buf_len];
 
+	memset(buf, 0, sizeof(buf));
 	fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
 	SAFE_READ(0, fildes, buf, sizeof(buf));
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi!

Quoted 10 lines
Quoted 5 lines

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Looks reasonable to me.

@Cyril a candidate for merge before the release.

Alternatively we could use the return value from the SAFE_READ() instead of the buf_len. Also I suppose that we could check that we read at least something.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 7 lines · Cyril Hrubis

Hi!

Quoted 6 lines
Quoted 5 lines

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Quoted 8 lines
Quoted 4 lines

Looks reasonable to me.

@Cyril a candidate for merge before the release.

Alternatively we could use the return value from the SAFE_READ() instead of the buf_len. Also I suppose that we could check that we read at least something.

I wonder whether a check that strlen(STRING) bytes was read is sufficient, and if it's more just FAIL the test? My understanding of the test is that the data written beyond file's end isn't yet synced, so if we can read more bytes that would already be an error?

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Looks reasonable to me.

@Cyril a candidate for merge before the release.

Quoted 8 lines
Quoted 3 lines

Alternatively we could use the return value from the SAFE_READ() instead of the buf_len. Also I suppose that we could check that we read at least something.

I wonder whether a check that strlen(STRING) bytes was read is sufficient, and if it's more just FAIL the test? My understanding of the test is that the data written beyond file's end isn't yet synced, so if we can read more bytes that would already be an error?

I would say yes, but it does not hurt to keep the check that the file data were not corrupted by the write after the file end. So maybe we just need to:

1. check that we read right size
2. check that the buffer has correct bytes

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 21 lines · Cyril Hrubis

Hi!

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Looks reasonable to me.

@Cyril a candidate for merge before the release.

Quoted 8 lines
Quoted 3 lines

Alternatively we could use the return value from the SAFE_READ() instead of the buf_len. Also I suppose that we could check that we read at least something.

I wonder whether a check that strlen(STRING) bytes was read is sufficient, and if it's more just FAIL the test? My understanding of the test is that the data written beyond file's end isn't yet synced, so if we can read more bytes that would already be an error?

Quoted 6 lines

I would say yes, but it does not hurt to keep the check that the file data were not corrupted by the write after the file end. So maybe we just need to:

1. check that we read right size
2. check that the buffer has correct bytes

Ok. I'll change the patch and send a V2 later.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Ricardo B. Marliere on v1 1/1
#6 lore raw
In reply to Sven Schnelle
Quoted 7 lines · Sven Schnelle

mmap01 reported random test failures. Turns out the the temporary buffer in check_file() isn't initialized. The SAFE_READ reads less then sizeof(buf) bytes so the rest stays initialized and might contain bytes check_file() is looking for.

Quoted 16 lines
---
 testcases/kernel/syscalls/mmap/mmap01.c | 1 +
 1 file changed, 1 insertion(+)
testcases/kernel/syscalls/mmap/mmap01.c +1 -0
index c93c37ceda52..ff09bc635c74 100644
@@ -36,6 +36,7 @@ static void check_file(void)
 	int i, fildes, buf_len = sizeof(STRING) + 3;
 	char buf[buf_len];
 
+	memset(buf, 0, sizeof(buf));
 	fildes = SAFE_OPEN(TEMPFILE, O_RDONLY);
 	SAFE_READ(0, fildes, buf, sizeof(buf));
 
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp