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:
@@ -52,6 +52,7 @@
|
||||
#include "locking.h"
|
||||
#include "inode-map.h"
|
||||
#include "backref.h"
|
||||
#include "rcu-string.h"
|
||||
|
||||
/* Mask out flags that are inappropriate for the given type of inode. */
|
||||
static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags)
|
||||
@@ -1345,8 +1346,9 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
|
||||
do_div(new_size, root->sectorsize);
|
||||
new_size *= root->sectorsize;
|
||||
|
||||
printk(KERN_INFO "btrfs: new size for %s is %llu\n",
|
||||
device->name, (unsigned long long)new_size);
|
||||
printk_in_rcu(KERN_INFO "btrfs: new size for %s is %llu\n",
|
||||
rcu_str_deref(device->name),
|
||||
(unsigned long long)new_size);
|
||||
|
||||
if (new_size > old_size) {
|
||||
trans = btrfs_start_transaction(root, 0);
|
||||
@@ -2264,7 +2266,12 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
|
||||
di_args->total_bytes = dev->total_bytes;
|
||||
memcpy(di_args->uuid, dev->uuid, sizeof(di_args->uuid));
|
||||
if (dev->name) {
|
||||
strncpy(di_args->path, dev->name, sizeof(di_args->path));
|
||||
struct rcu_string *name;
|
||||
|
||||
rcu_read_lock();
|
||||
name = rcu_dereference(dev->name);
|
||||
strncpy(di_args->path, name->str, sizeof(di_args->path));
|
||||
rcu_read_unlock();
|
||||
di_args->path[sizeof(di_args->path) - 1] = 0;
|
||||
} else {
|
||||
di_args->path[0] = '\0';
|
||||
|
Reference in New Issue
Block a user