Linux-CIFS Archive mirror
 help / color / mirror / Atom feed
From: Yuanfu Xie <yuanfuxie@stu.pku.edu.cn>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Steve French <sfrench@samba.org>,
	Paulo Alcantara <pc@manguebit.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>, Bharath SM <bharathsm@microsoft.com>,
	samba-technical@lists.samba.org, stable <stable@kernel.org>
Subject: Re: [PATCH 1/2] smb: client: fix off-by-8 bounds check in check_wsl_eas()
Date: Wed, 8 Apr 2026 17:39:09 +0800	[thread overview]
Message-ID: <1F39D765-2631-40EB-9B1A-131B5753599A@stu.pku.edu.cn> (raw)
In-Reply-To: <2026040636-unsigned-jackal-e239@gregkh>

[PATCH] smb: client: add bounds checks when iterating SMB1 WSL EAs

Add boundary and overflow checks when traversing extended attribute (EA)
entries for SMB1 WSL reparse points in cifs_query_path_info(), to prevent
out-of-bounds memory accesses from malformed next_entry_offset values.

This is necessary because SMB1 WSL EA iteration does not currently have
any explicit bounds checking, unlike SMB2 path which has check_wsl_eas().
The new checks ensure the current EA pointer plus its size does not
exceed the end of the EA buffer during iteration and before parsing.

Signed-off-by: YuanfuXie <yuanfuxie@stu.pku.edu.cn>
---
 fs/smb/client/smb1ops.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/smb1ops.c b/fs/smb/client/smb1ops.c
index 9694117050a6..940bae49b2cc 100644
--- a/fs/smb/client/smb1ops.c
+++ b/fs/smb/client/smb1ops.c
@@ -645,13 +645,17 @@ static int cifs_query_path_info(const unsigned int xid,
 	if (!rc && data->reparse_point) {
 		struct smb2_file_full_ea_info *ea;
 		u32 next = 0;
+		u8 *eas_end = data->wsl.eas + data->wsl.eas_len;
 
 		ea = (struct smb2_file_full_ea_info *)data->wsl.eas;
 		do {
 			ea = (void *)((u8 *)ea + next);
+			if ((u8 *)ea + sizeof(*ea) > eas_end)
+				break;
 			next = le32_to_cpu(ea->next_entry_offset);
 		} while (next);
-		if (le16_to_cpu(ea->ea_value_length)) {
+		if ((u8 *)ea + sizeof(*ea) <= eas_end &&
+		    le16_to_cpu(ea->ea_value_length)) {
 			ea->next_entry_offset = cpu_to_le32(ALIGN(sizeof(*ea) +
 						ea->ea_name_length + 1 +
 						le16_to_cpu(ea->ea_value_length), 4));
@@ -691,13 +695,17 @@ static int cifs_query_path_info(const unsigned int xid,
 	if (!rc && data->reparse_point) {
 		struct smb2_file_full_ea_info *ea;
 		u32 next = 0;
+		u8 *eas_end = data->wsl.eas + data->wsl.eas_len;
 
 		ea = (struct smb2_file_full_ea_info *)data->wsl.eas;
 		do {
 			ea = (void *)((u8 *)ea + next);
+			if ((u8 *)ea + sizeof(*ea) > eas_end)
+				break;
 			next = le32_to_cpu(ea->next_entry_offset);
 		} while (next);
-		if (le16_to_cpu(ea->ea_value_length)) {
+		if ((u8 *)ea + sizeof(*ea) <= eas_end &&
+		    le16_to_cpu(ea->ea_value_length)) {
 			ea->next_entry_offset = cpu_to_le32(ALIGN(sizeof(*ea) +
 						ea->ea_name_length + 1 +
 						le16_to_cpu(ea->ea_value_length), 4));
-- 
2.43.0

> On Apr 6, 2026, at 21:49, Greg Kroah-Hartman <gregkh@linuxfoundation.org> wrote:
> 
> The bounds check uses (u8 *)ea + nlen + 1 + vlen as the end of the EA
> name and value, but ea_data sits at offset sizeof(struct
> smb2_file_full_ea_info) = 8 from ea, not at offset 0.  The strncmp()
> later reads ea->ea_data[0..nlen-1] and the value bytes follow at
> ea_data[nlen+1..nlen+vlen], so the actual end is ea->ea_data + nlen + 1
> + vlen.  Isn't pointer math fun?
> 
> The earlier check (u8 *)ea > end - sizeof(*ea) only guarantees the
> 8-byte header is in bounds, but since the last EA is placed within 8
> bytes of the end of the response, the name and value bytes are read past
> the end of iov.
> 
> Fix this mess all up by using ea->ea_data as the base for the bounds
> check.
> 
> An "untrusted" server can use this to leak up to 8 bytes of kernel heap
> into the EA name comparison and influence which WSL xattr the data is
> interpreted as.
> 
> Cc: Steve French <sfrench@samba.org>
> Cc: Paulo Alcantara <pc@manguebit.org>
> Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>
> Cc: Shyam Prasad N <sprasad@microsoft.com>
> Cc: Tom Talpey <tom@talpey.com>
> Cc: Bharath SM <bharathsm@microsoft.com>
> Cc: linux-cifs@vger.kernel.org
> Cc: samba-technical@lists.samba.org
> Cc: stable <stable@kernel.org>
> Assisted-by: gregkh_clanker_t1000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
> fs/smb/client/smb2inode.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c
> index 364bdcff9c9d..fe1c9d776580 100644
> --- a/fs/smb/client/smb2inode.c
> +++ b/fs/smb/client/smb2inode.c
> @@ -128,7 +128,7 @@ static int check_wsl_eas(struct kvec *rsp_iov)
> 		nlen = ea->ea_name_length;
> 		vlen = le16_to_cpu(ea->ea_value_length);
> 		if (nlen != SMB2_WSL_XATTR_NAME_LEN ||
> -		    (u8 *)ea + nlen + 1 + vlen > end)
> +		    (u8 *)ea->ea_data + nlen + 1 + vlen > end)
> 			return -EINVAL;
> 
> 		switch (vlen) {
> -- 
> 2.53.0
> 
> 
> 
> 


  parent reply	other threads:[~2026-04-08  9:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 13:49 [PATCH 0/2] smb: some potential bugfixes Greg Kroah-Hartman
2026-04-06 13:49 ` [PATCH 1/2] smb: client: fix off-by-8 bounds check in check_wsl_eas() Greg Kroah-Hartman
2026-04-08  2:51   ` ChenXiaoSong
2026-04-08  5:39     ` Greg Kroah-Hartman
2026-04-08  5:58       ` ChenXiaoSong
2026-04-08  6:15         ` Greg Kroah-Hartman
2026-04-08  6:19           ` ChenXiaoSong
2026-04-08  6:40             ` Greg Kroah-Hartman
2026-04-08  6:52               ` ChenXiaoSong
2026-04-08  6:56                 ` Greg Kroah-Hartman
2026-04-09  3:09       ` ChenXiaoSong
2026-04-08  9:39   ` Yuanfu Xie [this message]
2026-04-06 13:49 ` [PATCH 2/2] smb: client: fix OOB reads parsing symlink error response Greg Kroah-Hartman
2026-04-08  9:01   ` ChenXiaoSong
2026-04-07  3:03 ` [PATCH 0/2] smb: some potential bugfixes Paulo Alcantara
     [not found]   ` <CAH2r5mvXFzWxs70Jmg=yWddmcHs+Bpf8eiBUvyc4oOMLzdCY7w@mail.gmail.com>
2026-04-08  5:45     ` Greg Kroah-Hartman

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=1F39D765-2631-40EB-9B1A-131B5753599A@stu.pku.edu.cn \
    --to=yuanfuxie@stu.pku.edu.cn \
    --cc=bharathsm@microsoft.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).