Re: RFC: mmap(PROT_READ, MAP_SHARED) fails if !writepage.

Linus Torvalds (torvalds@transmeta.com)
Fri, 8 Nov 2002 23:31:09 +0000 (UTC)


In article <24305.1036795742@passion.cambridge.redhat.com>,
David Woodhouse <dwmw2@infradead.org> wrote:
>Why does a _readonly_ mapping fail if the file system has no writepage
>method?
>
>do_mmap_pgoff() sets VM_MAYWRITE on the vma and then generic_file_mmap()
>refuses to allow it.
>
>Suggested patch below.... or should I just hack fsx-linux to use
>MAP_PRIVATE for its readonly mappings and ignore it?

This is broken. Since it has VM_MAYWRITE, a subsequent mprotect() may
mark it writable, and you you went boom.

If you really want a shared mapping, you'd better open with O_RDONLY, at
which point the existing code should be perfectly happy and does the
right thing.

In other words: the code is correct as-is.

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