Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dfd20b2b authored by Brian Behlendorf's avatar Brian Behlendorf Committed by Linus Torvalds
Browse files

drivers/block/brd.c: fix brd_lookup_page() race



The index on the page must be set before it is inserted in the radix
tree.  Otherwise there is a small race which can occur during lookup
where the page can be found with the incorrect index.  This will trigger
the BUG_ON() in brd_lookup_page().

Signed-off-by: default avatarBrian Behlendorf <behlendorf1@llnl.gov>
Reported-by: default avatarChris Wedgwood <cw@f00f.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e5ee7305
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -117,13 +117,13 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)


	spin_lock(&brd->brd_lock);
	spin_lock(&brd->brd_lock);
	idx = sector >> PAGE_SECTORS_SHIFT;
	idx = sector >> PAGE_SECTORS_SHIFT;
	page->index = idx;
	if (radix_tree_insert(&brd->brd_pages, idx, page)) {
	if (radix_tree_insert(&brd->brd_pages, idx, page)) {
		__free_page(page);
		__free_page(page);
		page = radix_tree_lookup(&brd->brd_pages, idx);
		page = radix_tree_lookup(&brd->brd_pages, idx);
		BUG_ON(!page);
		BUG_ON(!page);
		BUG_ON(page->index != idx);
		BUG_ON(page->index != idx);
	} else
	}
		page->index = idx;
	spin_unlock(&brd->brd_lock);
	spin_unlock(&brd->brd_lock);


	radix_tree_preload_end();
	radix_tree_preload_end();