linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: Jeongjun Park <aha310510@gmail.com>
Cc: linkinjeon@kernel.org, sj1557.seo@samsung.com,
	yuezhang.mo@sony.com, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org,
	syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com
Subject: Re: [PATCH] exfat: fix out-of-bounds in exfat_nls_to_ucs2()
Date: Wed, 8 Oct 2025 19:39:35 +0200	[thread overview]
Message-ID: <20251008173935.4skifawm57zqpsai@pali> (raw)
In-Reply-To: <20251006114507.371788-1-aha310510@gmail.com>

Hello!

On Monday 06 October 2025 20:45:07 Jeongjun Park wrote:
> After the loop that converts characters to ucs2 ends, the variable i 
> may be greater than or equal to len.

It is really possible to have "i" greater than len? Because I do not see
from the code how such thing could happen.

I see only a case when i is equal to len (which is also overflow).

My understanding:
while-loop condition ensures that i cannot be greater than len and i is
increased by exfat_convert_char_to_ucs2() function which has upper bound
of "len-i". So value of i can be increased maximally by (len-i) which
could lead to maximal value of i to be just "len".

> However, when checking whether the
> last byte of p_cstring is NULL, the variable i is used as is, resulting
> in an out-of-bounds read if i >= len.
> 
> Therefore, to prevent this, we need to modify the function to check
> whether i is less than len, and if i is greater than or equal to len,
> to check p_cstring[len - 1] byte.
> 
> 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..a52f3494eb20 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 (p_cstring[min(i, len - 1)] != '\0')

What about "if (i < len)" condition instead?

The p_cstring is the nul term string and my understanding is that the
"p_cstring[i] != '\0'" is checking that i is at position of strlen()+1.
So should not be "if (i < len)" the same check without need to
dereference the p_cstring?

>  		lossy |= NLS_NAME_OVERLEN;
>  
>  	*uniname = '\0';
> --

  parent reply	other threads:[~2025-10-08 17:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-06 11:45 [PATCH] exfat: fix out-of-bounds in exfat_nls_to_ucs2() Jeongjun Park
2025-10-08  6:56 ` Namjae Jeon
2025-10-08  8:52   ` Jeongjun Park
2025-10-08 17:39 ` Pali Rohár [this message]
2025-10-09  9:05   ` Jeongjun Park
2025-10-09 16:28     ` Pali Rohár

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251008173935.4skifawm57zqpsai@pali \
    --to=pali@kernel.org \
    --cc=aha310510@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+98cc76a76de46b3714d4@syzkaller.appspotmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=yuezhang.mo@sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).