]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
smb: client: correctly handle ErrorContextData as a flexible array
authorLiang Jie <liangjie@lixiang.com>
Sat, 18 Jan 2025 12:35:28 +0000 (20:35 +0800)
committerSteve French <stfrench@microsoft.com>
Mon, 20 Jan 2025 01:34:00 +0000 (19:34 -0600)
The `smb2_symlink_err_rsp` structure was previously defined with
`ErrorContextData` as a single `__u8` byte. However, the `ErrorContextData`
field is intended to be a variable-length array based on `ErrorDataLength`.
This mismatch leads to incorrect pointer arithmetic and potential memory
access issues when processing error contexts.

Updates the `ErrorContextData` field to be a flexible array
(`__u8 ErrorContextData[]`). Additionally, it modifies the corresponding
casts in the `symlink_data()` function to properly handle the flexible
array, ensuring correct memory calculations and data handling.

These changes improve the robustness of SMB2 symlink error processing.

Signed-off-by: Liang Jie <liangjie@lixiang.com>
Suggested-by: Tom Talpey <tom@talpey.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/smb/client/smb2file.c
fs/smb/client/smb2pdu.h

index e836bc2193ddd30df2d54a5abf791af5343aa4cc..9ec44eab8dbca7ccc976b78a3ac8eb8abdaeed40 100644 (file)
@@ -42,14 +42,14 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)
                end = (struct smb2_error_context_rsp *)((u8 *)err + iov->iov_len);
                do {
                        if (le32_to_cpu(p->ErrorId) == SMB2_ERROR_ID_DEFAULT) {
-                               sym = (struct smb2_symlink_err_rsp *)&p->ErrorContextData;
+                               sym = (struct smb2_symlink_err_rsp *)p->ErrorContextData;
                                break;
                        }
                        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);
-                       p = (struct smb2_error_context_rsp *)((u8 *)&p->ErrorContextData + len);
+                       p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len);
                } while (p < end);
        } else if (le32_to_cpu(err->ByteCount) >= sizeof(*sym) &&
                   iov->iov_len >= SMB2_SYMLINK_STRUCT_SIZE) {
index 076d9e83e1a0448b092fc8e2ab5b5523c88dcfa2..3c09a58dfd073fc87a77fa9a435fee1785f7698b 100644 (file)
@@ -79,7 +79,7 @@ struct smb2_symlink_err_rsp {
 struct smb2_error_context_rsp {
        __le32 ErrorDataLength;
        __le32 ErrorId;
-       __u8  ErrorContextData; /* ErrorDataLength long array */
+       __u8  ErrorContextData[] __counted_by_le(ErrorDataLength);
 } __packed;
 
 /* ErrorId values */