Re: [PATCH] Fix mmap_kmem (was: [question] What's the differencebetween /dev/kmem and /dev/mem)

From: Hugh Dickins
Date: Fri Aug 12 2005 - 09:23:45 EST


On Thu, 11 Aug 2005, Steven Rostedt wrote:
>
> Found the problem. It is a bug with mmap_kmem. The order of checks is
> wrong, so here's the patch.
> - if (!pfn_valid(vma->vm_pgoff))
> - return -EIO;
> val = (u64)vma->vm_pgoff << PAGE_SHIFT;
> vma->vm_pgoff = __pa(val) >> PAGE_SHIFT;
> + if (!pfn_valid(vma->vm_pgoff))
> + return -EIO;
> return mmap_mem(file, vma);

Good find, looks right to me, so far as it goes (why does this check
pfn_valid just on the first? and remap_pfn_range will not behave as
you'd expect on most of kmem, not before Nick kills PageReserved;
and there's the red-penned issue of vmalloc'ed areas too).

Perhaps you're the first to mmap /dev/kmem: before those 2.6.11 changes,
going back beyond 2.4.0, it seems to have expected to caller to subtract
PAGE_OFFSET from the virtual address to give the file offset (when doing
mmap, but not when doing read/write - senseless, especially given the
variable behaviour of lseek to negative offset before the read/write).

Hugh
-
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/