All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] smb: client: fix ALIGN() overflow in symlink_data() error context loop
@ 2026-08-17 17:16 Frank Sorenson
  2026-08-17 18:33 ` Paulo Alcantara
  2026-08-18  7:32 ` Namjae Jeon
  0 siblings, 2 replies; 3+ messages in thread
From: Frank Sorenson @ 2026-08-17 17:16 UTC (permalink / raw)
  To: linux-cifs, stfrench; +Cc: stable

The check added by commit 7d9a7f1f96cd compared the post-ALIGN length
against the remaining buffer, but ALIGN() itself can overflow: for
ErrorDataLength near UINT32_MAX (e.g. 0xFFFFFFF9), ALIGN(x, 8) wraps
to 0, so the subsequent bounds check passes, and the loop advances by
zero bytes leaving 'p' pointing into stale data.

Fix by checking the raw ErrorDataLength against the remaining space
before applying ALIGN(), then checking again after.  Since raw_len is
bounded by the buffer, raw_len + 7 cannot overflow, so the second check
is an exact post-alignment bounds guard.

Fixes: 76894f3e2f71 ("cifs: improve symlink handling for smb2+")
Cc: stable@vger.kernel.org
Signed-off-by: Frank Sorenson <sorenson@redhat.com>
---
 fs/smb/client/smb2file.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/smb/client/smb2file.c b/fs/smb/client/smb2file.c
index f35b6488d810..fb2fccbe8667 100644
--- a/fs/smb/client/smb2file.c
+++ b/fs/smb/client/smb2file.c
@@ -61,7 +61,10 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)
 			cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n",
 				 __func__, le32_to_cpu(p->ErrorId));
 
-			len = ALIGN(le32_to_cpu(p->ErrorDataLength), 8);
+			len = le32_to_cpu(p->ErrorDataLength);
+			if (len > end - ((u8 *)p + sizeof(*p)))
+				return ERR_PTR(-EINVAL);
+			len = ALIGN(len, 8);
 			if (len > end - ((u8 *)p + sizeof(*p)))
 				return ERR_PTR(-EINVAL);
 
-- 
2.55.0


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

end of thread, other threads:[~2026-08-18  7:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 17:16 [PATCH] smb: client: fix ALIGN() overflow in symlink_data() error context loop Frank Sorenson
2026-08-17 18:33 ` Paulo Alcantara
2026-08-18  7:32 ` Namjae Jeon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.