Re: New bug in patch and existing Linux code - race with install_page()(was: Re: [PATCH] 2.6.14 patch for supporting madvise(MADV_REMOVE))

From: Hugh Dickins
Date: Wed Nov 02 2005 - 15:13:48 EST


On Wed, 2 Nov 2005, Blaisorblade wrote:
> While looking into this, I probably found another problem, a race with
> install_page(), which doesn't use the seqlock-style check we use for
> everything else (aka do_no_page) but simply assumes a page is valid if its
> index is below the current file size.
>
> This is clearly "truncate" specific, and is already racy. Suppose I truncate a
> file and reduce its size, and then re-extend it, the page which I previously
> fetched from the cache is invalid. The current install_page code generates
> corruption.

No, it should be fine as is (unless perhaps some barrier is needed).

The check
size = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
if (!page->mapping || page->index >= size)
goto err_unlock;
handles the case that worries you: page->mapping will be NULL.

do_no_page has to do the more complicated truncate_count business because
it deals with all kinds of ->nopage, some of which leave page->mapping NULL:
so it's unable to distinguish one where the driver left it NULL from one
where truncation has suddenly made it NULL.

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/