Skip to content

Commit 6447b0e

Browse files
ekorenevskysmfrench
authored andcommitted
cifs: parse_dfs_referrals: prevent oob on malformed input
Malicious SMB server can send invalid reply to FSCTL_DFS_GET_REFERRALS - reply smaller than sizeof(struct get_dfs_referral_rsp) - reply with number of referrals smaller than NumberOfReferrals in the header Processing of such replies will cause oob. Return -EINVAL error on such replies to prevent oob-s. Signed-off-by: Eugene Korenevsky <[email protected]> Cc: [email protected] Suggested-by: Nathan Chancellor <[email protected]> Acked-by: Paulo Alcantara (Red Hat) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent c2b77f4 commit 6447b0e

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

fs/smb/client/misc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,14 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size,
916916
char *data_end;
917917
struct dfs_referral_level_3 *ref;
918918

919+
if (rsp_size < sizeof(*rsp)) {
920+
cifs_dbg(VFS | ONCE,
921+
"%s: header is malformed (size is %u, must be %zu)\n",
922+
__func__, rsp_size, sizeof(*rsp));
923+
rc = -EINVAL;
924+
goto parse_DFS_referrals_exit;
925+
}
926+
919927
*num_of_nodes = le16_to_cpu(rsp->NumberOfReferrals);
920928

921929
if (*num_of_nodes < 1) {
@@ -925,6 +933,15 @@ parse_dfs_referrals(struct get_dfs_referral_rsp *rsp, u32 rsp_size,
925933
goto parse_DFS_referrals_exit;
926934
}
927935

936+
if (sizeof(*rsp) + *num_of_nodes * sizeof(REFERRAL3) > rsp_size) {
937+
cifs_dbg(VFS | ONCE,
938+
"%s: malformed buffer (size is %u, must be at least %zu)\n",
939+
__func__, rsp_size,
940+
sizeof(*rsp) + *num_of_nodes * sizeof(REFERRAL3));
941+
rc = -EINVAL;
942+
goto parse_DFS_referrals_exit;
943+
}
944+
928945
ref = (struct dfs_referral_level_3 *) &(rsp->referrals);
929946
if (ref->VersionNumber != cpu_to_le16(3)) {
930947
cifs_dbg(VFS, "Referrals of V%d version are not supported, should be V3\n",

0 commit comments

Comments
 (0)