Skip to content

smb: client: fix OOB reads and UAFs in SMB2/3 receive paths

Frank Sorenson linux-cifs stable 4 versions – Applied

Status from this message: Applied.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest9 patches 1 replyApplied
  2. v410 patches 6 repliesSuperseded
  3. v311 patches 7 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v111 patches2 repliesSuperseded

Changes in v5 from the cover letter

- patch 2: replace the true/false indication of has_smb2_data_area[] with smb2_min_pdu_len[], which indicates both presence of a data area, and the size of it, if present
- patch 8: dropped; the new check could never be true

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/9smb: client: fix next_buffer UAF and NextCommand bounds in compound PDUsfs/smb/client/smb2ops.c+10 -10 replies
2/9smb: client: validate minimum PDU size before smb2_get_data_area_len()fs/smb/client/smb2misc.c+41 -280 replies
3/9smb: client: fix server->total_read for compound encrypted PDUsfs/smb/client/smb2ops.c+1 -00 replies
4/9smb: client: fix missing lower-bound check on DFS referral string offsetsfs/smb/client/misc.c+10 -20 replies
5/9smb: client: reject short Next offsets in parse_server_interfaces()fs/smb/client/smb2ops.c+3 -30 replies
6/9smb: client: fix OOB struct field reads in move_smb2_ea_to_cifs()fs/smb/client/smb2ops.c fs/smb/client/trace.h+18 -80 replies
7/9smb: client: fix missing iov bounds check in parse_posix_sids()fs/smb/client/smb2inode.c+11 -00 replies
8/9smb: client: fix potential OOB read in smb3_enum_snapshots()fs/smb/client/smb2ops.c+7 -10 replies
9/9smb: client: fix reparse buffer bounds in cifs_query_reparse_point()fs/smb/client/cifssmb.c+1 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/9] smb: client: fix OOB reads and UAFs in SMB2/3 receive paths

This series fixes nine bounds-checking defects in the SMB2/3 client, all of which are reachable from a malicious or compromised server.

Patches 1-3 address the compound encrypted frame processing path:

Patch 1 fixes multiple pointer lifecycle and bounds-checking issues in receive_encrypted_standard(), including a stale next_buffer pointer that causes a UAF on error paths, and an integer overflow that allows malformed trailing slices to bypass length checks.

Patch 2 replaces has_smb2_data_area[] with a table of per-command minimum-response struct sizes, used to reject responses too short for smb2_get_data_area_len() to safely read command-specific struct fields.

Patch 3 fixes server->total_read tracking so that smb2_check_message() validates against the actual per-sub-PDU size, rather than the full remaining compound tail. Without this, a truncated non-last sub-PDU could bypass the guards added in patch 2.

Note for stable: although patch 3 carries a Fixes: tag and Cc: stable, I am not sure whether patch 2 should, since it is hardening rather than a fix for a specific regression.

The remaining patches fix lower-bound gaps and OOB reads in DFS referral parsing, server interface list traversal, EA list traversal, posix SID bounds, snapshot enumeration, and SMB1 reparse point validation.

The create-context patch carried through v3 as patch 11 has been dropped from this series. Zihan Xi's recent series:

[PATCH v4 0/6] smb: client: fix create context out-of-bounds reads
https://lore.kernel.org/r/[email protected]

covers the same defects, arrives with a PoC, and fixes parse_query_id_ctxt() in a better way. Rather than post two overlapping/competing fixes, I will help with reviewing and improving that series instead. If it stalls, I'll re-post my version.

Testing compared cifs-next (7.3-rc2+) with and without this patchset:

samba - v3.1.1, v3.1.1+sign, v3.1.1+seal, v2.1, v2.1+sign, v1:
- no new failures attributable to this series.
- found netfs bug causing generic/759 with signing to fail (resolved by David Howells--now succeeds).

Windows Server 2022 - v3.1.1, v3.1.1+sign, v3.1.1+seal,
v3.1.1+multichannel:
- no failures.

v5 changes:
- patch 2: replace the true/false indication of has_smb2_data_area[] with smb2_min_pdu_len[], which indicates both presence of a data area, and the size of it, if present
- patch 8: dropped; the new check could never be true

v4 changes:
https://lore.kernel.org/linux-cifs/[email protected]
- patch 2: dropped the smb2_check_min_pdu_len_table() BUILD_BUG_ON helper.
- dropped patch 11
("smb: client: fix OOB reads in smb2_parse_contexts()")
in favor of Zihan Xi's series, as described above.
- patch 9: corrected a bogus Fixes: tag. Explained bound choice of sizeof(struct smb_snapshot_array) vs the 16-byte MIN_SNAPSHOT_ARRAY_SIZE of MS-SMB2 3.3.5.15.1.
- testing details: 7.2+ with samba & Windows Server 2022
- commit subjects and messages tightened throughout.

v3 changes:
https://lore.kernel.org/linux-cifs/[email protected]
- respin entire series

v2 changes:
- patch 6: reject next_entry_offset values that leave fewer than sizeof(*src) bytes remaining after advancing.

Frank Sorenson (9):
smb: client: fix next_buffer UAF and NextCommand bounds in compound
PDUs
smb: client: validate minimum PDU size before smb2_get_data_area_len()
smb: client: fix server->total_read for compound encrypted PDUs
smb: client: fix missing lower-bound check on DFS referral string
offsets
smb: client: reject short Next offsets in parse_server_interfaces()
smb: client: fix OOB struct field reads in move_smb2_ea_to_cifs()
smb: client: fix missing iov bounds check in parse_posix_sids()
smb: client: fix potential OOB read in smb3_enum_snapshots()
smb: client: fix reparse buffer bounds in cifs_query_reparse_point()

 fs/smb/client/cifssmb.c   |  2 +-
 fs/smb/client/misc.c      | 12 +++++--
 fs/smb/client/smb2inode.c | 11 +++++++
 fs/smb/client/smb2misc.c  | 69 +++++++++++++++++++++++----------------
 fs/smb/client/smb2ops.c   | 51 +++++++++++++++++++++--------
 fs/smb/client/trace.h     |  1 +
 6 files changed, 102 insertions(+), 44 deletions(-)
Signature · 1 line
2.55.0