Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Brian Behlendorf and committed by
Linus Torvalds
dfd20b2b e5ee7305

+2 -2
+2 -2
drivers/block/brd.c
··· 117 117 118 118 spin_lock(&brd->brd_lock); 119 119 idx = sector >> PAGE_SECTORS_SHIFT; 120 + page->index = idx; 120 121 if (radix_tree_insert(&brd->brd_pages, idx, page)) { 121 122 __free_page(page); 122 123 page = radix_tree_lookup(&brd->brd_pages, idx); 123 124 BUG_ON(!page); 124 125 BUG_ON(page->index != idx); 125 - } else 126 - page->index = idx; 126 + } 127 127 spin_unlock(&brd->brd_lock); 128 128 129 129 radix_tree_preload_end();