public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] Fix WARNING in __ext4_ioctl
@ 2024-07-03  0:07 Pei Li
  2024-07-03  1:24 ` Zhang Yi
  2024-07-11  2:42 ` Theodore Ts'o
  0 siblings, 2 replies; 3+ messages in thread
From: Pei Li @ 2024-07-03  0:07 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger
  Cc: linux-ext4, linux-kernel, skhan, syzkaller-bugs,
	linux-kernel-mentees, syzbot+2cab87506a0e7885f4b9, Pei Li

Specify the size of s_volume_name in strscpy_pad() to avoid buffer
overflow.

strscpy_pad() by default takes the size of destination string as the
size to be read from source string. However, as s_volume_name is only
declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more
than expected.

Reported-by: syzbot+2cab87506a0e7885f4b9@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=2cab87506a0e7885f4b9
Fixes: 744a56389f73 ("ext4: replace deprecated strncpy with alternatives")
Signed-off-by: Pei Li <peili.dev@gmail.com>
---
strscpy_pad() by default takes the size of destination string as the
size to be read from source string. However, as s_volume_name is only
declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more
than expected.

Specify the size of s_volume_name in strscpy_pad() to avoid buffer
overflow.
---
Changes in v2:
- Add fixes label
- Move workaround into commit log
- Link to v1: https://lore.kernel.org/r/20240628-bug8-v1-1-417ef53cca33@gmail.com
---
 fs/ext4/ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index dab7acd49709..0c4fb579757a 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_label
 	BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX);
 
 	lock_buffer(sbi->s_sbh);
-	strscpy_pad(label, sbi->s_es->s_volume_name);
+	strscpy_pad(label, sbi->s_es->s_volume_name, EXT4_LABEL_MAX);
 	unlock_buffer(sbi->s_sbh);
 
 	if (copy_to_user(user_label, label, sizeof(label)))

---
base-commit: 55027e689933ba2e64f3d245fb1ff185b3e7fc81
change-id: 20240628-bug8-7f700a228c4a

Best regards,
-- 
Pei Li <peili.dev@gmail.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Fix WARNING in __ext4_ioctl
  2024-07-03  0:07 [PATCH v2] Fix WARNING in __ext4_ioctl Pei Li
@ 2024-07-03  1:24 ` Zhang Yi
  2024-07-11  2:42 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Zhang Yi @ 2024-07-03  1:24 UTC (permalink / raw)
  To: Pei Li
  Cc: linux-ext4, linux-kernel, skhan, syzkaller-bugs,
	linux-kernel-mentees, syzbot+2cab87506a0e7885f4b9,
	Theodore Ts'o, Andreas Dilger

On 2024/7/3 8:07, Pei Li wrote:
> Specify the size of s_volume_name in strscpy_pad() to avoid buffer
> overflow.
> 
> strscpy_pad() by default takes the size of destination string as the
> size to be read from source string. However, as s_volume_name is only
> declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more
> than expected.
> 
> Reported-by: syzbot+2cab87506a0e7885f4b9@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=2cab87506a0e7885f4b9
> Fixes: 744a56389f73 ("ext4: replace deprecated strncpy with alternatives")
> Signed-off-by: Pei Li <peili.dev@gmail.com>

Thanks for the fix, it looks good to me.

Reviewed-by: Zhang Yi <yi.zhang@huawei.com>

> ---
> strscpy_pad() by default takes the size of destination string as the
> size to be read from source string. However, as s_volume_name is only
> declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more
> than expected.
> 
> Specify the size of s_volume_name in strscpy_pad() to avoid buffer
> overflow.
> ---
> Changes in v2:
> - Add fixes label
> - Move workaround into commit log
> - Link to v1: https://lore.kernel.org/r/20240628-bug8-v1-1-417ef53cca33@gmail.com
> ---
>  fs/ext4/ioctl.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index dab7acd49709..0c4fb579757a 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_label
>  	BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX);
>  
>  	lock_buffer(sbi->s_sbh);
> -	strscpy_pad(label, sbi->s_es->s_volume_name);
> +	strscpy_pad(label, sbi->s_es->s_volume_name, EXT4_LABEL_MAX);
>  	unlock_buffer(sbi->s_sbh);
>  
>  	if (copy_to_user(user_label, label, sizeof(label)))
> 
> ---
> base-commit: 55027e689933ba2e64f3d245fb1ff185b3e7fc81
> change-id: 20240628-bug8-7f700a228c4a
> 
> Best regards,
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] Fix WARNING in __ext4_ioctl
  2024-07-03  0:07 [PATCH v2] Fix WARNING in __ext4_ioctl Pei Li
  2024-07-03  1:24 ` Zhang Yi
@ 2024-07-11  2:42 ` Theodore Ts'o
  1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2024-07-11  2:42 UTC (permalink / raw)
  To: Pei Li
  Cc: Andreas Dilger, linux-ext4, linux-kernel, skhan, syzkaller-bugs,
	linux-kernel-mentees, syzbot+2cab87506a0e7885f4b9

Thanks for the patch; however, the correct fix submitted by Kees with
this commit:

commit be27cd64461c45a6088a91a04eba5cd44e1767ef
Author: Kees Cook <kees@kernel.org>
Date:   Thu May 23 15:54:12 2024 -0700

    ext4: use memtostr_pad() for s_volume_name
    
    As with the other strings in struct ext4_super_block, s_volume_name is
    not NUL terminated. The other strings were marked in commit 072ebb3bffe6
    ("ext4: add nonstring annotations to ext4.h"). Using strscpy() isn't
    the right replacement for strncpy(); it should use memtostr_pad()
    instead.
    
    Reported-by: syzbot+50835f73143cc2905b9e@syzkaller.appspotmail.com
    Closes: https://lore.kernel.org/all/00000000000019f4c00619192c05@google.com/
    Fixes: 744a56389f73 ("ext4: replace deprecated strncpy with alternatives")
    Signed-off-by: Kees Cook <keescook@chromium.org>
    Link: https://patch.msgid.link/20240523225408.work.904-kees@kernel.org
    Signed-off-by: Theodore Ts'o <tytso@mit.edu>

						- Ted

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-07-11  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-03  0:07 [PATCH v2] Fix WARNING in __ext4_ioctl Pei Li
2024-07-03  1:24 ` Zhang Yi
2024-07-11  2:42 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox