Skip to contentSkip to conversation

smb/client: fix possible infinite loop and oob read in symlink_data()

PATCH New Ye Bin 1 participant 1 message May 14

Subsystems (2)
lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH v2 1/1 smb/client: fix possible infinite loop and oob read in symlink_data()

From: Ye Bin <[email protected]>

On 32-bit architectures, the infinite loop is as follows:

len = p->ErrorDataLength == 0xfffffff8
u8 *next = p->ErrorContextData + len
next == p

On 32-bit architectures, the out-of-bounds read is as follows:

len = p->ErrorDataLength == 0xfffffff0
u8 *next = p->ErrorContextData + len
next == (u8 *)p - 8

Fixes 76894f3e2f71 ("cifs: improve symlink handling for smb2+")
---
 fs/smb/client/smb2file.c | 3 +++
 1 file changed, 3 insertions(+)
fs/smb/client/smb2file.c +3 -0
index b292aa94a593..6860eff31693 100644
@@ -49,6 +49,9 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)
 				 __func__, le32_to_cpu(p->ErrorId));
 
 			len = ALIGN(le32_to_cpu(p->ErrorDataLength), 8);
+			if (len > end - ((u8 *)p + sizeof(*p)))
+				return ERR_PTR(-EINVAL);
+
 			p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len);
 		}
 	} else if (le32_to_cpu(err->ByteCount) >= sizeof(*sym) &&
Signature · 1 line
2.34.1