aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Behlendorf <behlendorf1@llnl.gov>2013-05-24 18:55:28 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-24 19:22:52 -0400
commitdfd20b2b174d3a9b258ea3b7a35ead33576587b1 (patch)
treeafa033d613e8eca4bdaf6f9be2b990318a886b36
parente5ee7305ae03e43dbe2b0e346232975f793ad0eb (diff)
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: Brian Behlendorf <behlendorf1@llnl.gov> Reported-by: Chris Wedgwood <cw@f00f.org> Cc: Jens Axboe <axboe@kernel.dk> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/brd.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index f1a29f8e9d33..9bf4371755f2 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -117,13 +117,13 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
117 117
118 spin_lock(&brd->brd_lock); 118 spin_lock(&brd->brd_lock);
119 idx = sector >> PAGE_SECTORS_SHIFT; 119 idx = sector >> PAGE_SECTORS_SHIFT;
120 page->index = idx;
120 if (radix_tree_insert(&brd->brd_pages, idx, page)) { 121 if (radix_tree_insert(&brd->brd_pages, idx, page)) {
121 __free_page(page); 122 __free_page(page);
122 page = radix_tree_lookup(&brd->brd_pages, idx); 123 page = radix_tree_lookup(&brd->brd_pages, idx);
123 BUG_ON(!page); 124 BUG_ON(!page);
124 BUG_ON(page->index != idx); 125 BUG_ON(page->index != idx);
125 } else 126 }
126 page->index = idx;
127 spin_unlock(&brd->brd_lock); 127 spin_unlock(&brd->brd_lock);
128 128
129 radix_tree_preload_end(); 129 radix_tree_preload_end();