Do string check for the device's new size before volume_mutex is held.
Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
fs/btrfs/ioctl.c | 37 +++++++++++++++++++------------------
1 file changed, 19 insertions(+), 18 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 2eb220213d63..b0465020972a 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1445,7 +1445,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
{
struct inode *inode = file_inode(file);
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
- u64 new_size;
+ u64 new_size = 0;
u64 old_size;
u64 devid = 1;
struct btrfs_root *root = BTRFS_I(inode)->root;
@@ -1494,6 +1494,21 @@ static noinline int btrfs_ioctl_resize(struct file *file,
btrfs_info(fs_info, "resizing devid %llu", devid);
}
+ if (strcmp(sizestr, "max")) {
+ if (sizestr[0] == '-') {
+ mod = -1;
+ sizestr++;
+ } else if (sizestr[0] == '+') {
+ mod = 1;
+ sizestr++;
+ }
+ new_size = memparse(sizestr, &retptr);
+ if (*retptr != '\0' || new_size == 0) {
+ ret = -EINVAL;
+ goto out_free;
+ }
+ }
+
mutex_lock(&fs_info->volume_mutex);
device = btrfs_find_device(fs_info, devid, NULL, NULL);
if (!device) {
@@ -1511,28 +1526,14 @@ static noinline int btrfs_ioctl_resize(struct file *file,
goto out_mutex;
}
- if (!strcmp(sizestr, "max"))
- new_size = device->bdev->bd_inode->i_size;
- else {
- if (sizestr[0] == '-') {
- mod = -1;
- sizestr++;
- } else if (sizestr[0] == '+') {
- mod = 1;
- sizestr++;
- }
- new_size = memparse(sizestr, &retptr);
- if (*retptr != '\0' || new_size == 0) {
- ret = -EINVAL;
- goto out_mutex;
- }
- }
-
if (device->is_tgtdev_for_dev_replace) {
ret = -EPERM;
goto out_mutex;
}
+ if (!new_size)
+ new_size = device->bdev->bd_inode->i_size;
+
old_size = btrfs_device_get_total_bytes(device);
if (mod < 0) {
--
2.13.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html