* [PATCH] ext4: don't read past the UAPI struct in EXT4_IOC_GROUP_ADD
@ 2026-09-17 15:14 MarkLee131
2026-09-18 11:17 ` [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD MarkLee131
0 siblings, 1 reply; 6+ messages in thread
From: MarkLee131 @ 2026-09-17 15:14 UTC (permalink / raw)
To: kaixuanli0131, linux-ext4; +Cc: Theodore Ts'o, linux-kernel
From: Kaixuan Li <kaixuanli0131@gmail.com>
EXT4_IOC_GROUP_ADD casts the user pointer to struct ext4_new_group_input,
its UAPI type, but sizes the copy by struct ext4_new_group_data, the
internal type:
struct ext4_new_group_data input;
if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
sizeof(input)))
The UAPI struct is 40 bytes, the internal one 48. A caller that follows
the UAPI and allocates 40 bytes gets 8 bytes read past its object, and the
ioctl returns EFAULT when those bytes are unmapped. The internal struct
has carried the extra fields since ext4 was split from ext3, so the copy
has always over-read the UAPI object.
The two extra fields are not used from this path: free_clusters_count is
overwritten by verify_group_input(), and mdata_blocks is used only by
ext4_resize_fs(), which builds its own group_data array. The compat path
already copies the six UAPI fields individually; the native path does not.
Copy the UAPI struct, then set the internal fields from it.
Reproducible on v6.12.9 and v7.2.4 by placing a 40-byte struct at the end
of a mapped page whose successor is unmapped: the ioctl returns EFAULT.
Signed-off-by: Kaixuan Li <kaixuanli0131@gmail.com>
---
Built fs/ext4/ioctl.o warning-free (W=1, x86_64 defconfig) and checkpatch-clean.
The bug (EFAULT on a conforming 40-byte object) was reproduced under QEMU on
v6.12.9 and v7.2.4; the fix itself was not runtime-tested.
fs/ext4/ioctl.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index c8387e6a2c6e..ea3cd8cdae25 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1674,12 +1674,22 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case EXT4_IOC_GROUP_ADD: {
+ struct ext4_new_group_input uinput;
struct ext4_new_group_data input;
- if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
- sizeof(input)))
+ if (copy_from_user(&uinput,
+ (struct ext4_new_group_input __user *)arg,
+ sizeof(uinput)))
return -EFAULT;
+ memset(&input, 0, sizeof(input));
+ input.group = uinput.group;
+ input.block_bitmap = uinput.block_bitmap;
+ input.inode_bitmap = uinput.inode_bitmap;
+ input.inode_table = uinput.inode_table;
+ input.blocks_count = uinput.blocks_count;
+ input.reserved_blocks = uinput.reserved_blocks;
+
return ext4_ioctl_group_add(filp, &input);
}
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD
2026-09-17 15:14 [PATCH] ext4: don't read past the UAPI struct in EXT4_IOC_GROUP_ADD MarkLee131
@ 2026-09-18 11:17 ` MarkLee131
2026-09-22 10:07 ` Jan Kara
2026-10-19 13:16 ` [PATCH v3] " Kaixuan Li
0 siblings, 2 replies; 6+ messages in thread
From: MarkLee131 @ 2026-09-18 11:17 UTC (permalink / raw)
To: linux-ext4
Cc: Kaixuan Li, Andreas Dilger, Theodore Ts'o, Jan Kara, linux-kernel
From: Kaixuan Li <kaixuanli0131@gmail.com>
EXT4_IOC_GROUP_ADD casts the user pointer to struct ext4_new_group_input,
its UAPI type, but sizes the copy by struct ext4_new_group_data, the
internal type:
struct ext4_new_group_data input;
if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
sizeof(input)))
The UAPI struct is 40 bytes, the internal one 48. A caller that follows
the UAPI and allocates 40 bytes gets 8 bytes read past its object, and the
ioctl returns EFAULT when those bytes are unmapped. The two structs have
differed in size for as long as I can see back -- v6.12.9, v7.2.4 and
current master all have 40 against 48 -- so the copy has been over-reading
the UAPI object throughout.
The first 40 bytes of the two structs have identical layout, so copying
that much fills every field the UAPI defines. Zero the rest:
free_clusters_count is overwritten by verify_group_input() anyway, and
mdata_blocks is read only by ext4_resize_fs(), which builds its own
group_data array.
Reproducible on v6.12.9 and v7.2.4 by placing a 40-byte struct at the end
of a mapped page whose successor is unmapped: the ioctl returns EFAULT.
Signed-off-by: Kaixuan Li <kaixuanli0131@gmail.com>
---
v2: done the way you suggested -- one struct on the stack, one copy, and a
memset of the tail, rather than v1's second struct and six field
assignments. The only change from your sketch is the cast in the memset
address: &input is a struct ext4_new_group_data *, so &input +
sizeof(*uinput) would advance by 40 * 48 bytes.
Built fs/ext4/ioctl.o warning-free with W=1 on x86_64 (clang 21), and
checkpatch-clean. The EFAULT reproducer behaves as before on v6.12.9 and
v7.2.4; the fix itself was not runtime-tested.
fs/ext4/ioctl.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1674,12 +1674,15 @@
}
case EXT4_IOC_GROUP_ADD: {
+ struct ext4_new_group_input __user *uinput = (void __user *)arg;
struct ext4_new_group_data input;
- if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
- sizeof(input)))
+ if (copy_from_user(&input, uinput, sizeof(*uinput)))
return -EFAULT;
+ memset((char *)&input + sizeof(*uinput), 0,
+ sizeof(input) - sizeof(*uinput));
+
return ext4_ioctl_group_add(filp, &input);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD
2026-09-18 11:17 ` [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD MarkLee131
@ 2026-09-22 10:07 ` Jan Kara
2026-10-19 13:16 ` [PATCH v3] " Kaixuan Li
1 sibling, 0 replies; 6+ messages in thread
From: Jan Kara @ 2026-09-22 10:07 UTC (permalink / raw)
To: MarkLee131
Cc: linux-ext4, Andreas Dilger, Theodore Ts'o, Jan Kara, linux-kernel
On Fri 18-09-26 19:17:42, MarkLee131 wrote:
> From: Kaixuan Li <kaixuanli0131@gmail.com>
>
> EXT4_IOC_GROUP_ADD casts the user pointer to struct ext4_new_group_input,
> its UAPI type, but sizes the copy by struct ext4_new_group_data, the
> internal type:
>
> struct ext4_new_group_data input;
>
> if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
> sizeof(input)))
>
> The UAPI struct is 40 bytes, the internal one 48. A caller that follows
> the UAPI and allocates 40 bytes gets 8 bytes read past its object, and the
> ioctl returns EFAULT when those bytes are unmapped. The two structs have
> differed in size for as long as I can see back -- v6.12.9, v7.2.4 and
> current master all have 40 against 48 -- so the copy has been over-reading
> the UAPI object throughout.
>
> The first 40 bytes of the two structs have identical layout, so copying
> that much fills every field the UAPI defines. Zero the rest:
> free_clusters_count is overwritten by verify_group_input() anyway, and
> mdata_blocks is read only by ext4_resize_fs(), which builds its own
> group_data array.
>
> Reproducible on v6.12.9 and v7.2.4 by placing a 40-byte struct at the end
> of a mapped page whose successor is unmapped: the ioctl returns EFAULT.
>
> Signed-off-by: Kaixuan Li <kaixuanli0131@gmail.com>
> ---
> v2: done the way you suggested -- one struct on the stack, one copy, and a
> memset of the tail, rather than v1's second struct and six field
> assignments. The only change from your sketch is the cast in the memset
> address: &input is a struct ext4_new_group_data *, so &input +
> sizeof(*uinput) would advance by 40 * 48 bytes.
>
> Built fs/ext4/ioctl.o warning-free with W=1 on x86_64 (clang 21), and
> checkpatch-clean. The EFAULT reproducer behaves as before on v6.12.9 and
> v7.2.4; the fix itself was not runtime-tested.
One nit below, otherwise looks good.
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1674,12 +1674,15 @@
> }
>
> case EXT4_IOC_GROUP_ADD: {
> + struct ext4_new_group_input __user *uinput = (void __user *)arg;
> struct ext4_new_group_data input;
>
> - if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
> - sizeof(input)))
> + if (copy_from_user(&input, uinput, sizeof(*uinput)))
> return -EFAULT;
>
> + memset((char *)&input + sizeof(*uinput), 0,
> + sizeof(input) - sizeof(*uinput));
> +
I just would not bother with this complex memset. This is not performance
critical at all. Just initialize the whole 'input' to 0 (with = {} at
declaration) and be done with it.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3] ext4: don't read past the UAPI struct in GROUP_ADD
2026-09-18 11:17 ` [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD MarkLee131
2026-09-22 10:07 ` Jan Kara
@ 2026-10-19 13:16 ` Kaixuan Li
2026-10-19 14:02 ` Jan Kara
1 sibling, 1 reply; 6+ messages in thread
From: Kaixuan Li @ 2026-10-19 13:16 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Andreas Dilger, Jan Kara, linux-ext4, linux-kernel
EXT4_IOC_GROUP_ADD casts the user pointer to struct ext4_new_group_input,
its UAPI type, but sizes the copy by struct ext4_new_group_data, the
internal type:
struct ext4_new_group_data input;
if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
sizeof(input)))
The UAPI struct is 40 bytes, the internal one 48. A caller that follows
the UAPI and allocates 40 bytes gets 8 bytes read past its object, and the
ioctl returns EFAULT when those bytes are unmapped. The two structs have
differed in size for as long as I can see back -- v6.12.9, v7.2.4 and
current master all have 40 against 48 -- so the copy has been over-reading
the UAPI object throughout.
The first 40 bytes of the two structs have the same layout, with the UAPI
'unused' in the slot of mdata_blocks, so copying that much fills every
field the UAPI defines. free_clusters_count, the one field past it, is
overwritten by verify_group_input(), and mdata_blocks is read only on the
ext4_resize_fs() path, which builds its own group_data array. Copy the
UAPI size into a zero-initialised struct.
Reproducible on v6.12.9 and v7.2.4 by placing a 40-byte struct at the end
of a mapped page whose successor is unmapped: the ioctl returns EFAULT.
Signed-off-by: Kaixuan Li <kaixuanli0131@gmail.com>
---
v3: initialise input with = {} and drop the tail memset (Jan Kara).
Correct the description: the UAPI 'unused' shares its slot with
mdata_blocks, so only free_clusters_count lies past the copy.
v2: https://lore.kernel.org/linux-ext4/20260918111742.827428-1-kaixuan.li@ntu.edu.sg/
v1: https://lore.kernel.org/linux-ext4/20260917151441.413135-1-kaixuan.li@ntu.edu.sg/
Built fs/ext4/ioctl.o warning-free with W=1 on x86_64 (gcc 11.4), and
checkpatch-clean. The EFAULT reproducer behaves as before on v6.12.9 and
v7.2.4; the fix itself was not runtime-tested.
fs/ext4/ioctl.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index c8387e6a2c6e..aab02575d90a 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1674,10 +1674,10 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
case EXT4_IOC_GROUP_ADD: {
- struct ext4_new_group_data input;
+ struct ext4_new_group_input __user *uinput = (void __user *)arg;
+ struct ext4_new_group_data input = {};
- if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
- sizeof(input)))
+ if (copy_from_user(&input, uinput, sizeof(*uinput)))
return -EFAULT;
return ext4_ioctl_group_add(filp, &input);
--
2.34.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ext4: don't read past the UAPI struct in GROUP_ADD
2026-10-19 13:16 ` [PATCH v3] " Kaixuan Li
@ 2026-10-19 14:02 ` Jan Kara
2026-11-16 7:46 ` Kaixuan Li
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2026-10-19 14:02 UTC (permalink / raw)
To: Kaixuan Li
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, linux-ext4, linux-kernel
On Mon 19-10-26 21:16:55, Kaixuan Li wrote:
> EXT4_IOC_GROUP_ADD casts the user pointer to struct ext4_new_group_input,
> its UAPI type, but sizes the copy by struct ext4_new_group_data, the
> internal type:
>
> struct ext4_new_group_data input;
>
> if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
> sizeof(input)))
>
> The UAPI struct is 40 bytes, the internal one 48. A caller that follows
> the UAPI and allocates 40 bytes gets 8 bytes read past its object, and the
> ioctl returns EFAULT when those bytes are unmapped. The two structs have
> differed in size for as long as I can see back -- v6.12.9, v7.2.4 and
> current master all have 40 against 48 -- so the copy has been over-reading
> the UAPI object throughout.
>
> The first 40 bytes of the two structs have the same layout, with the UAPI
> 'unused' in the slot of mdata_blocks, so copying that much fills every
> field the UAPI defines. free_clusters_count, the one field past it, is
> overwritten by verify_group_input(), and mdata_blocks is read only on the
> ext4_resize_fs() path, which builds its own group_data array. Copy the
> UAPI size into a zero-initialised struct.
>
> Reproducible on v6.12.9 and v7.2.4 by placing a 40-byte struct at the end
> of a mapped page whose successor is unmapped: the ioctl returns EFAULT.
>
> Signed-off-by: Kaixuan Li <kaixuanli0131@gmail.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> v3: initialise input with = {} and drop the tail memset (Jan Kara).
> Correct the description: the UAPI 'unused' shares its slot with
> mdata_blocks, so only free_clusters_count lies past the copy.
>
> v2: https://lore.kernel.org/linux-ext4/20260918111742.827428-1-kaixuan.li@ntu.edu.sg/
> v1: https://lore.kernel.org/linux-ext4/20260917151441.413135-1-kaixuan.li@ntu.edu.sg/
>
> Built fs/ext4/ioctl.o warning-free with W=1 on x86_64 (gcc 11.4), and
> checkpatch-clean. The EFAULT reproducer behaves as before on v6.12.9 and
> v7.2.4; the fix itself was not runtime-tested.
>
> fs/ext4/ioctl.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index c8387e6a2c6e..aab02575d90a 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1674,10 +1674,10 @@ static long __ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
> }
>
> case EXT4_IOC_GROUP_ADD: {
> - struct ext4_new_group_data input;
> + struct ext4_new_group_input __user *uinput = (void __user *)arg;
> + struct ext4_new_group_data input = {};
>
> - if (copy_from_user(&input, (struct ext4_new_group_input __user *)arg,
> - sizeof(input)))
> + if (copy_from_user(&input, uinput, sizeof(*uinput)))
> return -EFAULT;
>
> return ext4_ioctl_group_add(filp, &input);
> --
> 2.34.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v3] ext4: don't read past the UAPI struct in GROUP_ADD
2026-10-19 14:02 ` Jan Kara
@ 2026-11-16 7:46 ` Kaixuan Li
0 siblings, 0 replies; 6+ messages in thread
From: Kaixuan Li @ 2026-11-16 7:46 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Jan Kara, Andreas Dilger, linux-ext4, linux-kernel
Hi Ted,
Gentle ping on v3. Jan reviewed it on Oct 19:
Reviewed-by: Jan Kara <jack@suse.cz>
It still applies cleanly to v7.4-rc3. Would you take it through the
ext4 tree, or should I resend it with the tag folded in?
Thanks,
Kaixuan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-16 7:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 15:14 [PATCH] ext4: don't read past the UAPI struct in EXT4_IOC_GROUP_ADD MarkLee131
2026-09-18 11:17 ` [PATCH v2] ext4: don't read past the UAPI struct in GROUP_ADD MarkLee131
2026-09-22 10:07 ` Jan Kara
2026-10-19 13:16 ` [PATCH v3] " Kaixuan Li
2026-10-19 14:02 ` Jan Kara
2026-11-16 7:46 ` Kaixuan Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®