Btrfs: use rcu to protect device->name
Al pointed out that we can just toss out the old name on a device and add a new one arbitrarily, so anybody who uses device->name in printk could possibly use free'd memory. Instead of adding locking around all of this he suggested doing it with RCU, so I've introduced a struct rcu_string that does just that and have gone through and protected all accesses to device->name that aren't under the uuid_mutex with rcu_read_lock(). This protects us and I will use it for dealing with removing the device that we used to mount the file system in a later patch. Thanks, Reviewed-by: David Sterba <dsterba@suse.cz> Signed-off-by: Josef Bacik <josef@redhat.com>
This commit is contained in:
@@ -93,6 +93,7 @@
|
||||
#include "print-tree.h"
|
||||
#include "locking.h"
|
||||
#include "check-integrity.h"
|
||||
#include "rcu-string.h"
|
||||
|
||||
#define BTRFSIC_BLOCK_HASHTABLE_SIZE 0x10000
|
||||
#define BTRFSIC_BLOCK_LINK_HASHTABLE_SIZE 0x10000
|
||||
@@ -843,13 +844,14 @@ static int btrfsic_process_superblock_dev_mirror(
|
||||
superblock_tmp->never_written = 0;
|
||||
superblock_tmp->mirror_num = 1 + superblock_mirror_num;
|
||||
if (state->print_mask & BTRFSIC_PRINT_MASK_SUPERBLOCK_WRITE)
|
||||
printk(KERN_INFO "New initial S-block (bdev %p, %s)"
|
||||
" @%llu (%s/%llu/%d)\n",
|
||||
superblock_bdev, device->name,
|
||||
(unsigned long long)dev_bytenr,
|
||||
dev_state->name,
|
||||
(unsigned long long)dev_bytenr,
|
||||
superblock_mirror_num);
|
||||
printk_in_rcu(KERN_INFO "New initial S-block (bdev %p, %s)"
|
||||
" @%llu (%s/%llu/%d)\n",
|
||||
superblock_bdev,
|
||||
rcu_str_deref(device->name),
|
||||
(unsigned long long)dev_bytenr,
|
||||
dev_state->name,
|
||||
(unsigned long long)dev_bytenr,
|
||||
superblock_mirror_num);
|
||||
list_add(&superblock_tmp->all_blocks_node,
|
||||
&state->all_blocks_list);
|
||||
btrfsic_block_hashtable_add(superblock_tmp,
|
||||
|
Reference in New Issue
Block a user