From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/7] btrfs: move user provided string checks outside of volume_mutex
Date: Mon, 6 Nov 2017 16:36:13 +0800 [thread overview]
Message-ID: <20171106083618.7617-3-anand.jain@oracle.com> (raw)
In-Reply-To: <20171106083618.7617-1-anand.jain@oracle.com>
Do string check for the device's new size before volume_mutex is held.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
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
next prev parent reply other threads:[~2017-11-06 8:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-06 8:36 [PATCH 0/8] Misc device cleanup patches: part1 Anand Jain
2017-11-06 8:36 ` [PATCH 1/7] btrfs: optimize use of volume_mutex in btrfs_ioctl_resize() Anand Jain
2017-11-06 16:50 ` David Sterba
2017-11-06 8:36 ` Anand Jain [this message]
2017-11-06 8:36 ` [PATCH 3/7] btrfs: use i_size_read() instead of open code Anand Jain
2017-11-06 16:52 ` David Sterba
2017-11-06 23:44 ` Anand Jain
2017-11-15 16:45 ` David Sterba
2017-11-06 8:36 ` [PATCH 4/7] btrfs: rename btrfs_add_device to btrfs_add_dev_item Anand Jain
2017-11-06 16:53 ` David Sterba
2017-11-06 8:36 ` [PATCH 5/7] btrfs: btrfs_rm_device() does not need uuid_mutex Anand Jain
2017-11-06 17:02 ` David Sterba
2017-11-06 23:59 ` Anand Jain
2017-11-06 8:36 ` [PATCH 6/7] btrfs: move volume_mutex into btrfs_init_new_device() Anand Jain
2017-11-06 8:36 ` [PATCH 7/7] btrfs: rename btrfs_init_new_device() to btrfs_add_device() Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171106083618.7617-3-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).