Skip to content

Commit 09d49eb

Browse files
arndbakpm00
authored andcommitted
ocfs2: reduce ioctl stack usage
On 32-bit architectures with KASAN_STACK enabled, the total stack usage of the ocfs2_ioctl function grows beyond the warning limit: fs/ocfs2/ioctl.c: In function 'ocfs2_ioctl': fs/ocfs2/ioctl.c:934:1: error: the frame size of 1448 bytes is larger than 1400 bytes [-Werror=frame-larger-than=] Move each of the variables into a basic block, and mark ocfs2_info_handle() as noinline_for_stack, in order to have the variable share stack slots. Link: https://lkml.kernel.org/r/20230417205631.1956027-1-arnd@kernel.org Signed-off-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Reviewed-by: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Gang He <ghe@suse.com> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 522dc4e commit 09d49eb

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

fs/ocfs2/ioctl.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ static int ocfs2_get_request_ptr(struct ocfs2_info *info, int idx,
803803
* a better backward&forward compatibility, since a small piece of
804804
* request will be less likely to be broken if disk layout get changed.
805805
*/
806-
static int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info,
807-
int compat_flag)
806+
static noinline_for_stack int
807+
ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info, int compat_flag)
808808
{
809809
int i, status = 0;
810810
u64 req_addr;
@@ -840,27 +840,26 @@ static int ocfs2_info_handle(struct inode *inode, struct ocfs2_info *info,
840840
long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
841841
{
842842
struct inode *inode = file_inode(filp);
843-
int new_clusters;
844-
int status;
845-
struct ocfs2_space_resv sr;
846-
struct ocfs2_new_group_input input;
847-
struct reflink_arguments args;
848-
const char __user *old_path;
849-
const char __user *new_path;
850-
bool preserve;
851-
struct ocfs2_info info;
852843
void __user *argp = (void __user *)arg;
844+
int status;
853845

854846
switch (cmd) {
855847
case OCFS2_IOC_RESVSP:
856848
case OCFS2_IOC_RESVSP64:
857849
case OCFS2_IOC_UNRESVSP:
858850
case OCFS2_IOC_UNRESVSP64:
851+
{
852+
struct ocfs2_space_resv sr;
853+
859854
if (copy_from_user(&sr, (int __user *) arg, sizeof(sr)))
860855
return -EFAULT;
861856

862857
return ocfs2_change_file_space(filp, cmd, &sr);
858+
}
863859
case OCFS2_IOC_GROUP_EXTEND:
860+
{
861+
int new_clusters;
862+
864863
if (!capable(CAP_SYS_RESOURCE))
865864
return -EPERM;
866865

@@ -873,8 +872,12 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
873872
status = ocfs2_group_extend(inode, new_clusters);
874873
mnt_drop_write_file(filp);
875874
return status;
875+
}
876876
case OCFS2_IOC_GROUP_ADD:
877877
case OCFS2_IOC_GROUP_ADD64:
878+
{
879+
struct ocfs2_new_group_input input;
880+
878881
if (!capable(CAP_SYS_RESOURCE))
879882
return -EPERM;
880883

@@ -887,19 +890,31 @@ long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
887890
status = ocfs2_group_add(inode, &input);
888891
mnt_drop_write_file(filp);
889892
return status;
893+
}
890894
case OCFS2_IOC_REFLINK:
895+
{
896+
struct reflink_arguments args;
897+
const char __user *old_path;
898+
const char __user *new_path;
899+
bool preserve;
900+
891901
if (copy_from_user(&args, argp, sizeof(args)))
892902
return -EFAULT;
893903
old_path = (const char __user *)(unsigned long)args.old_path;
894904
new_path = (const char __user *)(unsigned long)args.new_path;
895905
preserve = (args.preserve != 0);
896906

897907
return ocfs2_reflink_ioctl(inode, old_path, new_path, preserve);
908+
}
898909
case OCFS2_IOC_INFO:
910+
{
911+
struct ocfs2_info info;
912+
899913
if (copy_from_user(&info, argp, sizeof(struct ocfs2_info)))
900914
return -EFAULT;
901915

902916
return ocfs2_info_handle(inode, &info, 0);
917+
}
903918
case FITRIM:
904919
{
905920
struct super_block *sb = inode->i_sb;

0 commit comments

Comments
 (0)