* [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2()
@ 2025-10-10 5:03 Jeongjun Park
2025-10-10 16:09 ` Pali Rohár
2025-10-11 5:40 ` Namjae Jeon
0 siblings, 2 replies; 3+ messages in thread
From: Jeongjun Park @ 2025-10-10 5:03 UTC (permalink / raw)
To: Namjae Jeon, Sungjong Seo
Cc: Yuezhang Mo, Al Viro, pali, linux-fsdevel, linux-kernel, stable,
syzbot+98cc76a76de46b3714d4, Jeongjun Park
In exfat_nls_to_ucs2(), if there is no NLS loss and the char-to-ucs2
conversion is successfully completed, the variable "i" will have the same
value as len.
However, exfat_nls_to_ucs2() checks p_cstring[i] to determine whether nls
is lost immediately after the while loop ends, so if len is FSLABEL_MAX,
"i" will also be FSLABEL_MAX immediately after the while loop ends,
resulting in an out-of-bounds read of 1 byte from the p_cstring stack
memory.
Therefore, to prevent this and properly determine whether nls has been
lost, it should be modified to check if "i" and len are equal, rather than
dereferencing p_cstring.
Cc: <stable@vger.kernel.org>
Reported-by: syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=98cc76a76de46b3714d4
Fixes: 370e812b3ec1 ("exfat: add nls operations")
Signed-off-by: Jeongjun Park <aha310510@gmail.com>
---
fs/exfat/nls.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/exfat/nls.c b/fs/exfat/nls.c
index 8243d94ceaf4..de06abe426d7 100644
--- a/fs/exfat/nls.c
+++ b/fs/exfat/nls.c
@@ -616,7 +616,7 @@ static int exfat_nls_to_ucs2(struct super_block *sb,
unilen++;
}
- if (p_cstring[i] != '\0')
+ if (i != len)
lossy |= NLS_NAME_OVERLEN;
*uniname = '\0';
--
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2()
2025-10-10 5:03 [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2() Jeongjun Park
@ 2025-10-10 16:09 ` Pali Rohár
2025-10-11 5:40 ` Namjae Jeon
1 sibling, 0 replies; 3+ messages in thread
From: Pali Rohár @ 2025-10-10 16:09 UTC (permalink / raw)
To: Jeongjun Park
Cc: Namjae Jeon, Sungjong Seo, Yuezhang Mo, Al Viro, linux-fsdevel,
linux-kernel, stable, syzbot+98cc76a76de46b3714d4
On Friday 10 October 2025 14:03:29 Jeongjun Park wrote:
> In exfat_nls_to_ucs2(), if there is no NLS loss and the char-to-ucs2
> conversion is successfully completed, the variable "i" will have the same
> value as len.
>
> However, exfat_nls_to_ucs2() checks p_cstring[i] to determine whether nls
> is lost immediately after the while loop ends, so if len is FSLABEL_MAX,
> "i" will also be FSLABEL_MAX immediately after the while loop ends,
> resulting in an out-of-bounds read of 1 byte from the p_cstring stack
> memory.
>
> Therefore, to prevent this and properly determine whether nls has been
> lost, it should be modified to check if "i" and len are equal, rather than
> dereferencing p_cstring.
>
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=98cc76a76de46b3714d4
> Fixes: 370e812b3ec1 ("exfat: add nls operations")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> ---
> fs/exfat/nls.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/exfat/nls.c b/fs/exfat/nls.c
> index 8243d94ceaf4..de06abe426d7 100644
> --- a/fs/exfat/nls.c
> +++ b/fs/exfat/nls.c
> @@ -616,7 +616,7 @@ static int exfat_nls_to_ucs2(struct super_block *sb,
> unilen++;
> }
>
> - if (p_cstring[i] != '\0')
> + if (i != len)
> lossy |= NLS_NAME_OVERLEN;
>
> *uniname = '\0';
> --
Looks good for me,
Reviewed-by: Pali Rohár <pali@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2()
2025-10-10 5:03 [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2() Jeongjun Park
2025-10-10 16:09 ` Pali Rohár
@ 2025-10-11 5:40 ` Namjae Jeon
1 sibling, 0 replies; 3+ messages in thread
From: Namjae Jeon @ 2025-10-11 5:40 UTC (permalink / raw)
To: Jeongjun Park
Cc: Sungjong Seo, Yuezhang Mo, Al Viro, pali, linux-fsdevel,
linux-kernel, stable, syzbot+98cc76a76de46b3714d4
On Fri, Oct 10, 2025 at 2:04 PM Jeongjun Park <aha310510@gmail.com> wrote:
>
> In exfat_nls_to_ucs2(), if there is no NLS loss and the char-to-ucs2
> conversion is successfully completed, the variable "i" will have the same
> value as len.
>
> However, exfat_nls_to_ucs2() checks p_cstring[i] to determine whether nls
> is lost immediately after the while loop ends, so if len is FSLABEL_MAX,
> "i" will also be FSLABEL_MAX immediately after the while loop ends,
> resulting in an out-of-bounds read of 1 byte from the p_cstring stack
> memory.
>
> Therefore, to prevent this and properly determine whether nls has been
> lost, it should be modified to check if "i" and len are equal, rather than
> dereferencing p_cstring.
>
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=98cc76a76de46b3714d4
> Fixes: 370e812b3ec1 ("exfat: add nls operations")
> Signed-off-by: Jeongjun Park <aha310510@gmail.com>
> ---
> fs/exfat/nls.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/exfat/nls.c b/fs/exfat/nls.c
> index 8243d94ceaf4..de06abe426d7 100644
> --- a/fs/exfat/nls.c
> +++ b/fs/exfat/nls.c
> @@ -616,7 +616,7 @@ static int exfat_nls_to_ucs2(struct super_block *sb,
> unilen++;
> }
>
> - if (p_cstring[i] != '\0')
> + if (i != len)
> lossy |= NLS_NAME_OVERLEN;
As I said before, the core problem is passing an incorrect length in the ioctl
FS_IOC_SETFSLABEL call. While your change may fix the symptom,
it doesn't fix the root cause.
Furthermore, NLS_NAME_OVERLEN macro is unnecessary.
That will result in different errors when creating a file with trailing periods
with utf8 and the other iocharset.
Please remove it and make the same error handling for maximum length
consistent with exfat_utf8_to_utf16().
>
> *uniname = '\0';
> --
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-11 5:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-10 5:03 [PATCH v2] exfat: fix out-of-bounds in exfat_nls_to_ucs2() Jeongjun Park
2025-10-10 16:09 ` Pali Rohár
2025-10-11 5:40 ` Namjae Jeon
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®