Skip to contentSkip to conversation

cifs: Avoid field over-reading memcpy()

PATCH Applied Kees Cook 2 participants 2 messages Jun 21, 2021 – Jun 22, 2021

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 cifs: Avoid field over-reading memcpy()

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally reading across neighboring fields.

Instead of using memcpy to read across multiple struct members, just perform per-member assignments as already done for other members.

---
 fs/cifs/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +4 -1
index 31784e3fa96f..962826dc3316 100644
@@ -2892,7 +2892,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 #endif /* CIFS_DEBUG2 */
 
 	if (buf) {
-		memcpy(buf, &rsp->CreationTime, 32);
+		buf->CreationTime = rsp->CreationTime;
+		buf->LastAccessTime = rsp->LastAccessTime;
+		buf->LastWriteTime = rsp->LastWriteTime;
+		buf->ChangeTime = rsp->ChangeTime;
 		buf->AllocationSize = rsp->AllocationSize;
 		buf->EndOfFile = rsp->EndofFile;
 		buf->Attributes = rsp->FileAttributes;
Signature · 1 line
2.30.2
Applied
#1 lore raw

merged into cifs-2.6.git for-next

Quoted 32 lines · Kees Cook

In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally reading across neighboring fields.

Instead of using memcpy to read across multiple struct members, just perform per-member assignments as already done for other members.

---
 fs/cifs/smb2pdu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/cifs/smb2pdu.c +4 -2
index 31784e3fa96f..962826dc3316 100644
@@ -2892,7 +2892,10 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
 #endif /* CIFS_DEBUG2 */
 
        if (buf) {
-               memcpy(buf, &rsp->CreationTime, 32);
+               buf->CreationTime = rsp->CreationTime;
+               buf->LastAccessTime = rsp->LastAccessTime;
+               buf->LastWriteTime = rsp->LastWriteTime;
+               buf->ChangeTime = rsp->ChangeTime;
                buf->AllocationSize = rsp->AllocationSize;
                buf->EndOfFile = rsp->EndofFile;
                buf->Attributes = rsp->FileAttributes;
--

2.30.2

Signature · 3 lines
Thanks,

Steve