Skip to content

Commit 4d92dc0

Browse files
bwhackstytso
authored andcommitted
ext4: Fix compat EXT4_IOC_ADD_GROUP
struct ext4_new_group_input needs to be converted because u64 has only 32-bit alignment on some 32-bit architectures, notably i386. Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
1 parent 899ad0c commit 4d92dc0

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <linux/wait.h>
3030
#include <linux/blockgroup_lock.h>
3131
#include <linux/percpu_counter.h>
32+
#ifdef __KERNEL__
33+
#include <linux/compat.h>
34+
#endif
3235

3336
/*
3437
* The fourth extended filesystem constants/structures
@@ -432,6 +435,18 @@ struct ext4_new_group_input {
432435
__u16 unused;
433436
};
434437

438+
#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
439+
struct compat_ext4_new_group_input {
440+
u32 group;
441+
compat_u64 block_bitmap;
442+
compat_u64 inode_bitmap;
443+
compat_u64 inode_table;
444+
u32 blocks_count;
445+
u16 reserved_blocks;
446+
u16 unused;
447+
};
448+
#endif
449+
435450
/* The struct ext4_new_group_input in kernel space, with free_blocks_count */
436451
struct ext4_new_group_data {
437452
__u32 group;
@@ -509,6 +524,7 @@ struct ext4_new_group_data {
509524
#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
510525
#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
511526
#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
527+
#define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)
512528
#ifdef CONFIG_JBD2_DEBUG
513529
#define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
514530
#endif

‎fs/ext4/ioctl.c‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,29 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
373373
case EXT4_IOC32_SETRSVSZ:
374374
cmd = EXT4_IOC_SETRSVSZ;
375375
break;
376-
case EXT4_IOC_GROUP_ADD:
377-
break;
376+
case EXT4_IOC32_GROUP_ADD: {
377+
struct compat_ext4_new_group_input __user *uinput;
378+
struct ext4_new_group_input input;
379+
mm_segment_t old_fs;
380+
int err;
381+
382+
uinput = compat_ptr(arg);
383+
err = get_user(input.group, &uinput->group);
384+
err |= get_user(input.block_bitmap, &uinput->block_bitmap);
385+
err |= get_user(input.inode_bitmap, &uinput->inode_bitmap);
386+
err |= get_user(input.inode_table, &uinput->inode_table);
387+
err |= get_user(input.blocks_count, &uinput->blocks_count);
388+
err |= get_user(input.reserved_blocks,
389+
&uinput->reserved_blocks);
390+
if (err)
391+
return -EFAULT;
392+
old_fs = get_fs();
393+
set_fs(KERNEL_DS);
394+
err = ext4_ioctl(file, EXT4_IOC_GROUP_ADD,
395+
(unsigned long) &input);
396+
set_fs(old_fs);
397+
return err;
398+
}
378399
case EXT4_IOC_MOVE_EXT:
379400
break;
380401
default:

0 commit comments

Comments
 (0)