Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Paulo Alcantara <pc@manguebit.org>
To: Ren Wei <n05ec@lzu.edu.cn>,
	linux-cifs@vger.kernel.org, samba-technical@lists.samba.org
Cc: linkinjeon@kernel.org, ronniesahlberg@gmail.com,
	sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com,
	jlayton@kernel.org, smfrench@gmail.com, bird@lzu.edu.cn,
	rakukuip@gmail.com, n05ec@lzu.edu.cn
Subject: Re: [PATCH 1/1] cifs: fix buffer overflow in SMB2_tcon
Date: Wed, 14 Oct 2026 20:06:19 -0300	[thread overview]
Message-ID: <adb08c60bb8da380fe105c5b9aa4331c@manguebit.org> (raw)
In-Reply-To: <0f3d431d65a5f46c0487293d127e748775ca85b8.1791865501.git.rakukuip@gmail.com>

Ren Wei <n05ec@lzu.edu.cn> writes:

> From: Luxiao Xu <rakukuip@gmail.com>
>
> In SMB2_tcon(), unc_path is allocated with a fixed buffer size of
> MAX_SHARENAME_LENGTH * 2 bytes (672 bytes). However, the user-controlled
> UNC path (tree) length is passed to cifs_strtoUTF16(), which assumes the
> destination buffer is large enough and writes strlen(tree) + 1 UTF-16 code
> units.
>
> Commit 62a1a439e0fd ("cifs: clean up handling of unc= option") removed the
> length check on UNC mount options, allowing mount paths to exceed
> MAX_SHARENAME_LENGTH while retaining the fixed-size buffer allocation in
> SMB2_tcon(). Consequently, an oversized UNC string causes cifs_strtoUTF16()
> to write past the end of the heap object, resulting in a slab-out-of-bounds
> write.
>
> Fix this by dynamically allocating unc_path based on the length of tree so
> that it safely accommodates all UTF-16 code units.

I don't think we should allow SMB2_tcon() with a @tree more than
MAX_TREE_SIZE characters.

With your fix, we might end up with a truncated tree name set in
cifs_tcon::tree_name.  It will work in the first tree connect, but if
the client needs to issue another tree connect for some reason
(e.g. reconnect/failover), then it will fail.

Some places rely on the tree name not having more than MAX_TREE_SIZE
characters.  I'd rather return -EINVAL along with an error message in
SMB2_tcon() if @tree exceeds that length.

From another patch, we could also add an early MAX_TREE_SIZE check
against smb3_fs_context::UNC in smb3_parse_devname().

BTW, mount.cifs(8) will not allow an UNC path that has more than 1024
characters.

What do you think?

      parent reply	other threads:[~2026-10-14 23:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 17:16 [PATCH 0/1] cifs: fix buffer overflow in SMB2_tcon Ren Wei
2026-10-13 17:16 ` [PATCH 1/1] " Ren Wei
2026-10-14  1:48   ` Namjae Jeon
2026-10-14 23:06   ` Paulo Alcantara [this message]

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=adb08c60bb8da380fe105c5b9aa4331c@manguebit.org \
    --to=pc@manguebit.org \
    --cc=bharathsm@microsoft.com \
    --cc=bird@lzu.edu.cn \
    --cc=jlayton@kernel.org \
    --cc=linkinjeon@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=n05ec@lzu.edu.cn \
    --cc=rakukuip@gmail.com \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.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