* [PATCH] Btrfs: avoid stack bloat in btrfs_ioctl_fs_info()
@ 2011-06-08 3:58 Li Zefan
2011-06-08 7:10 ` Arne Jansen
0 siblings, 1 reply; 3+ messages in thread
From: Li Zefan @ 2011-06-08 3:58 UTC (permalink / raw)
To: linux-btrfs; +Cc: Arne Jansen
The size of struct btrfs_ioctl_fs_info_args is as big as 1KB, so
don't declare the variable on stack.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
fs/btrfs/ioctl.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index ac37040..9705c5c 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2054,29 +2054,34 @@ static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
static long btrfs_ioctl_fs_info(struct btrfs_root *root, void __user *arg)
{
- struct btrfs_ioctl_fs_info_args fi_args;
+ struct btrfs_ioctl_fs_info_args *fi_args;
struct btrfs_device *device;
struct btrfs_device *next;
struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
+ int ret = 0;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
- fi_args.num_devices = fs_devices->num_devices;
- fi_args.max_id = 0;
- memcpy(&fi_args.fsid, root->fs_info->fsid, sizeof(fi_args.fsid));
+ fi_args = kzalloc(sizeof(*fi_args), GFP_KERNEL);
+ if (!fi_args)
+ return -ENOMEM;
+
+ fi_args->num_devices = fs_devices->num_devices;
+ memcpy(&fi_args->fsid, root->fs_info->fsid, sizeof(fi_args->fsid));
mutex_lock(&fs_devices->device_list_mutex);
list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
- if (device->devid > fi_args.max_id)
- fi_args.max_id = device->devid;
+ if (device->devid > fi_args->max_id)
+ fi_args->max_id = device->devid;
}
mutex_unlock(&fs_devices->device_list_mutex);
- if (copy_to_user(arg, &fi_args, sizeof(fi_args)))
- return -EFAULT;
+ if (copy_to_user(arg, fi_args, sizeof(fi_args)))
+ ret = -EFAULT;
- return 0;
+ kfree(fi_args);
+ return ret;
}
static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
-- 1.7.3.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: avoid stack bloat in btrfs_ioctl_fs_info()
2011-06-08 3:58 [PATCH] Btrfs: avoid stack bloat in btrfs_ioctl_fs_info() Li Zefan
@ 2011-06-08 7:10 ` Arne Jansen
2011-06-08 7:23 ` Li Zefan
0 siblings, 1 reply; 3+ messages in thread
From: Arne Jansen @ 2011-06-08 7:10 UTC (permalink / raw)
To: Li Zefan; +Cc: linux-btrfs
On 08.06.2011 05:58, Li Zefan wrote:
> The size of struct btrfs_ioctl_fs_info_args is as big as 1KB, so
> don't declare the variable on stack.
>
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
> fs/btrfs/ioctl.c | 23 ++++++++++++++---------
> 1 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index ac37040..9705c5c 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -2054,29 +2054,34 @@ static long btrfs_ioctl_rm_dev(struct btrfs_root *root, void __user *arg)
>
> static long btrfs_ioctl_fs_info(struct btrfs_root *root, void __user *arg)
> {
> - struct btrfs_ioctl_fs_info_args fi_args;
> + struct btrfs_ioctl_fs_info_args *fi_args;
> struct btrfs_device *device;
> struct btrfs_device *next;
> struct btrfs_fs_devices *fs_devices = root->fs_info->fs_devices;
> + int ret = 0;
>
> if (!capable(CAP_SYS_ADMIN))
> return -EPERM;
>
> - fi_args.num_devices = fs_devices->num_devices;
> - fi_args.max_id = 0;
> - memcpy(&fi_args.fsid, root->fs_info->fsid, sizeof(fi_args.fsid));
> + fi_args = kzalloc(sizeof(*fi_args), GFP_KERNEL);
> + if (!fi_args)
> + return -ENOMEM;
> +
> + fi_args->num_devices = fs_devices->num_devices;
> + memcpy(&fi_args->fsid, root->fs_info->fsid, sizeof(fi_args->fsid));
>
> mutex_lock(&fs_devices->device_list_mutex);
> list_for_each_entry_safe(device, next, &fs_devices->devices, dev_list) {
> - if (device->devid > fi_args.max_id)
> - fi_args.max_id = device->devid;
> + if (device->devid > fi_args->max_id)
> + fi_args->max_id = device->devid;
> }
> mutex_unlock(&fs_devices->device_list_mutex);
>
> - if (copy_to_user(arg, &fi_args, sizeof(fi_args)))
> - return -EFAULT;
> + if (copy_to_user(arg, fi_args, sizeof(fi_args)))
sizeof(*fi_args)
will integrate that, thanks :)
-Arne
> + ret = -EFAULT;
>
> - return 0;
> + kfree(fi_args);
> + return ret;
> }
>
> static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg)
> -- 1.7.3.1
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: avoid stack bloat in btrfs_ioctl_fs_info()
2011-06-08 7:10 ` Arne Jansen
@ 2011-06-08 7:23 ` Li Zefan
0 siblings, 0 replies; 3+ messages in thread
From: Li Zefan @ 2011-06-08 7:23 UTC (permalink / raw)
To: Arne Jansen; +Cc: linux-btrfs
>> - if (copy_to_user(arg, &fi_args, sizeof(fi_args)))
>> - return -EFAULT;
>> + if (copy_to_user(arg, fi_args, sizeof(fi_args)))
>
> sizeof(*fi_args)
>
> will integrate that, thanks :)
>
Oops, what a silly mistake!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-06-08 7:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-08 3:58 [PATCH] Btrfs: avoid stack bloat in btrfs_ioctl_fs_info() Li Zefan
2011-06-08 7:10 ` Arne Jansen
2011-06-08 7:23 ` Li Zefan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.