Skip to content

Commit 215b7f9

Browse files
Liang JieSteve French
Liang Jie
authored and
Steve French
committed
smb: client: correctly handle ErrorContextData as a flexible array
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 <[email protected]> Suggested-by: Tom Talpey <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 48aa995 commit 215b7f9

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: fs/smb/client/smb2file.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ static struct smb2_symlink_err_rsp *symlink_data(const struct kvec *iov)
4242
end = (struct smb2_error_context_rsp *)((u8 *)err + iov->iov_len);
4343
do {
4444
if (le32_to_cpu(p->ErrorId) == SMB2_ERROR_ID_DEFAULT) {
45-
sym = (struct smb2_symlink_err_rsp *)&p->ErrorContextData;
45+
sym = (struct smb2_symlink_err_rsp *)p->ErrorContextData;
4646
break;
4747
}
4848
cifs_dbg(FYI, "%s: skipping unhandled error context: 0x%x\n",
4949
__func__, le32_to_cpu(p->ErrorId));
5050

5151
len = ALIGN(le32_to_cpu(p->ErrorDataLength), 8);
52-
p = (struct smb2_error_context_rsp *)((u8 *)&p->ErrorContextData + len);
52+
p = (struct smb2_error_context_rsp *)(p->ErrorContextData + len);
5353
} while (p < end);
5454
} else if (le32_to_cpu(err->ByteCount) >= sizeof(*sym) &&
5555
iov->iov_len >= SMB2_SYMLINK_STRUCT_SIZE) {

Diff for: fs/smb/client/smb2pdu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct smb2_symlink_err_rsp {
7979
struct smb2_error_context_rsp {
8080
__le32 ErrorDataLength;
8181
__le32 ErrorId;
82-
__u8 ErrorContextData; /* ErrorDataLength long array */
82+
__u8 ErrorContextData[] __counted_by_le(ErrorDataLength);
8383
} __packed;
8484

8585
/* ErrorId values */

0 commit comments

Comments
 (0)