Re: mremap() use is racy

From: Hugh Dickins
Date: Tue Aug 23 2005 - 18:45:02 EST


On Tue, 23 Aug 2005, Ulrich Drepper wrote:
> Linus Torvalds wrote:
> > Actually, it should be pretty much as valid as using mremap - ie it works
> > on Linux.
> >
> > Especially if you use MAP_SHARED, you don't even need to mprotect
> > anything: you'll get a nice SIGBUS if you ever try to access past the last
> > page that maps the file.
>
> If you guarantee this (and test for this) it's fine with me. The POSIX
> spec explicitly leaves this undefined and requiring to use mremap()
> would be a nice way to work around this without allowing the
> introduction of undefined behavior into programs. I probably would
> prefer to use mremap() since this makes it clear what should happen but
> I can live with using the too-large mapping.

I don't have spec to hand to quote, but at least 10 years ago the SIGBUS
beyond end of file was required behaviour, on both MAP_SHARED and more
surprisingly MAP_PRIVATE mappings of a file. Well, you don't get SIGBUS
on any part of the page that covers the end of the file: perhaps what
you read as undefined in the spec is addressing that tail page issue.

We guarantee it: it's a kernel bug if it doesn't work.

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/