Skip to contentSkip to conversation

mmap.c (do_mmap_pgoff) 'repatched'.

PATCH New DervishD 1 participant 1 message Dec 11, 2002

Subsystems (2)
lore
Share & tools
lore

DervishD

author
#0 lore raw

PATCH 1/1 mmap.c (do_mmap_pgoff) 'repatched'.

Hi Alan :))

The patch I sent you for mmap.c, correcting a corner case,
namely the case where the requested size on a call to 'mmap()' was greater than SIZE_MAX-PAGE_SIZE, because the size was incorrectly page-aligned to size '0', does nothing if TASK_SIZE is the full address space for the task. This happens, for example, under sparc64.

This new patch covers this case and works even if TASK_SIZE is
very huge. My patch was completed by David S. Miller <[email protected]> and now should work for all cases.

The patch is against your 2.4.20-ac1 tree. If you have any doubt,
please tell.

Thanks ;)

Raúl

mm/mmap.c renamed from mm/mmap.c.orig +4 -8
@@ -473,10 +473,6 @@
 }
 
 
-/*
- *	NOTE: in this function we rely on TASK_SIZE being lower than
- *	SIZE_MAX-PAGE_SIZE at least. I'm pretty sure that it is.
- */
 
 unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, unsigned long len,
 	unsigned long prot, unsigned long flags, unsigned long pgoff)
@@ -493,14 +489,14 @@
 	if (file && (!file->f_op || !file->f_op->mmap))
 		return -ENODEV;
 
-	if (!len)
+	if (len == 0)
 		return addr;
+	
+	len = PAGE_ALIGN(len);
 
-	if (len > TASK_SIZE)
+	if (len > TASK_SIZE || len == 0)
 		return -EINVAL;
 
-	len = PAGE_ALIGN(len);  /* This cannot be zero now */
-
 	/* offset overflow? */
 	if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
 		return -EINVAL;