BUG: mmap(): any driver changing addr ignores MAP_FIXED

From: BlaisorBlade
Date: Fri Aug 20 2004 - 05:13:32 EST


>From 2.6 mm/mmap.c:do_mmap_pgoff, about the address where to install the new
mapping:

/* Can addr have changed??
*
* Answer: Yes, several device drivers can do it in their
* f_op->mmap method. -DaveM
*/
addr = vma->vm_start;

But if I mmaped with MAP_FIXED? MAP_FIXED is accounted for only inside
get_unmapped_area(); so, if the driver changes the addr, MAP_FIXED is
actually ignored. Shouldn't we add something like:

if (flags & MAP_FIXED && addr != vma->vm_start) {
/*fail the mmap() call cleanly*/
error = -EINVAL; /*???*/
goto unmap_and_free_vma; /*add there a check if(file != NULL) before
fput()ing it*/
}

But I also have two questions:
1) I cannot find the "several drivers" DaveM speaks about.

In 2.4, there is just drivers/video/epson1356fb.c, for very crappy reasons
(because the returned address must not be 32 byte aligned, it explains in the
comment); in 2.6, drivers/video/68328fb.c, and only #ifndef MMU (which is a
very different case - i.e. providing the physical address instead of
mmap()'ing). I found them by hand-checking the output of this command:

find drivers/ -type f|xargs grep 'vm_start.*='

Anyway, in both cases the above MAP_FIXED check should be added anyway.
2) Which is a good reason to allow such crap?
--
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/