Skip to contentSkip to conversation

fsx-linux: Fix reference buffer corruption in op_map_read()

PATCH In review Jinseok Kim 2 participants 3 messages Aug 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fsx-linux: Fix reference buffer corruption in op_map_read()

op_map_read() copied mmapped memory to file_buff before comparison, overwriting the reference data. Drop the invalid memcpy().

---
 testcases/kernel/fs/fsx-linux/fsx-linux.c | 2 --
 1 file changed, 2 deletions(-)
testcases/kernel/fs/fsx-linux/fsx-linux.c +0 -2
index 2e0f17a5e..21390c58c 100644
@@ -219,8 +219,6 @@ static int op_map_read(void)
 		file_desc,
 		(off_t)pos.offset);
 
-	memcpy(file_buff + pos.offset, addr, pos.size);
-
 	int ret = memory_compare(
 		addr,
 		file_buff + pos.offset,

--
2.43.0

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

PATCH 2/2 fsx-linux: Fix op_max_size handling in op_file_position()

op_file_position() ignored op_max_size (-o option), causing operation sizes to span up to the entire file size. Cap max_len with op_max_size to honor the user option.

---
 testcases/kernel/fs/fsx-linux/fsx-linux.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
testcases/kernel/fs/fsx-linux/fsx-linux.c +7 -1
index 21390c58c..81aca5dab 100644
@@ -77,9 +77,15 @@ static void op_file_position(
 	struct file_pos_t *pos)
 {
 	long long diff;
+	long long max_len;
 
 	pos->offset = random() % fsize;
-	pos->size = random() % (fsize - pos->offset);
+
+	max_len = fsize - pos->offset;
+	if (max_len > op_max_size)
+		max_len = op_max_size;
+
+	pos->size = random() % max_len;
 
 	diff = pos->offset % align;
 

--
2.43.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Jinseok Kim

Hi Jinseok,

Quoted 1 line · Jinseok Kim

fsx-linux: Fix reference buffer corruption in op_map_read()

--- [PATCH 2/2] ---

Quoted 6 lines
(quoted diff) +5 -0
+	max_len = fsize - pos->offset;
+	if (max_len > op_max_size)
+		max_len = op_max_size;
+
+	pos->size = random() % max_len;
Quoted 6 lines
	diff = pos->offset % align;

	if (diff) {
		pos->offset -= diff;
		pos->size += diff;
	}

Could the offset be aligned before max_len is calculated, or could the final size be capped after alignment?

The new cap bounds pos->size only before offset % align is added back. With -o 1 -w 4096, pos->size starts at zero and can then grow to 4095 bytes, so -o still is not an upper bound. This also affects the existing fsx05 entry, which combines -o 1024 with -w 4096.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

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