Skip to contentSkip to conversation

mm/shmem: handle integer underflow in shmem_fallocate

PATCH In review yahia 1 participant 2 messages Jun 26 – Jun 27

Subsystems (2)
lore
Share & tools
lore

yahia

author
#0 lore raw

PATCH 1/1 mm/shmem: handle integer underflow in shmem_fallocate

From: yahia ahmed <[email protected]>

In shmem_fallocate(), The calculation of unmap_end is done via round_down(offset + len, PAGE_SIZE) - 1, so for any value less than PAGE_SIZE, round_down will produce the value -1, which is handled because unmap_end is a signed integer (loff_t), but later the condition (u64)unmap_end > (u64)unmap_start is evaluated, which would mean that unmap_end would be equal to the maximum value because u64 can't handle negative values, thus making the evaluation always true and calling unmap_mapping_range function which would perform a TLB shootdown of the file, but will be kept by page cache, Fixing it would require removing casting the integers to u64.

---
 mm/shmem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/shmem.c +1 -1
index b51f83c970bb..33829f296f1c 100644
@@ -3633,7 +3633,7 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
 		inode->i_private = &shmem_falloc;
 		spin_unlock(&inode->i_lock);
 
-		if ((u64)unmap_end > (u64)unmap_start)
+		if (unmap_end > unmap_start)
 			unmap_mapping_range(mapping, unmap_start,
 					    1 + unmap_end - unmap_start, 0);
 		shmem_truncate_range(inode, offset, offset + len - 1);
Signature · 1 line
2.54.0
author
#1 lore raw

Re [PATCH] mm/shmem: handle integer underflow in shmem_fallocate

Hi,

Please drop this patch as i found
out that it introduces a bug because
it voids an intentional EOF.

Best regards,
yahia