Skip to content

Commit dfd20b2

Browse files
behlendorftorvalds
authored andcommitted
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>
1 parent e5ee730 commit dfd20b2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎drivers/block/brd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
117117

118118
spin_lock(&brd->brd_lock);
119119
idx = sector >> PAGE_SECTORS_SHIFT;
120+
page->index = idx;
120121
if (radix_tree_insert(&brd->brd_pages, idx, page)) {
121122
__free_page(page);
122123
page = radix_tree_lookup(&brd->brd_pages, idx);
123124
BUG_ON(!page);
124125
BUG_ON(page->index != idx);
125-
} else
126-
page->index = idx;
126+
}
127127
spin_unlock(&brd->brd_lock);
128128

129129
radix_tree_preload_end();

0 commit comments

Comments
 (0)