From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91FBA18A6A5; Mon, 27 Oct 2025 19:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761592158; cv=none; b=bGLDbrBlvSMzLGFmXOm1MjJdAY8dWU5dy4XeF1Jl9gomyFWBD9w/FfbHseQIrXR9tBIkOswrLjeNmLk1Xv3GF0RKZqvdLUZNOCTdBFcyC31ORIOWUvEDcHLZ8ZJhFYDI7/yLiGOKsrfLsmYpCehYN4qwsRIA/s5N1D3gIZ+oY2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761592158; c=relaxed/simple; bh=Tk3aLbfhwNZaaQEopa5QocGKoQiY+0uRLhZTI8jsIbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SqNc7qeMZm1EexnYAVqRwd4tHueAb8gbhyvjcBivglHAh5uAL54h7vix4AncNuvaA++CboJ49mbixujPTLNyMTmpW0w0J6m04Le3oCFJ7jPQVNve31kikKfixto5ew9AVPjaMHAB0HRYKWMdhzS7xwMflTWN8THitRyNfnCzYEE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bMbOQaL+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bMbOQaL+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28CEFC4CEF1; Mon, 27 Oct 2025 19:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761592158; bh=Tk3aLbfhwNZaaQEopa5QocGKoQiY+0uRLhZTI8jsIbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bMbOQaL+022qimM8muWcWLiLsUmLB3d9egJoDwtNbs/hBe8C9t8QRGYvPZxs9b5W1 ymJUYGQPkuflGCxnSGEnM/sSvLys6r5gjmjaOwYmJIO8ISF1GehRkl4RFnNrkPC5e2 YAB12B8Mu1NlLOcNVLDaZg3Dlh6MOUBpdWmxCWvs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eugene Korenevsky , Nathan Chancellor , "Paulo Alcantara (Red Hat)" , Steve French Subject: [PATCH 6.1 008/157] cifs: parse_dfs_referrals: prevent oob on malformed input Date: Mon, 27 Oct 2025 19:34:29 +0100 Message-ID: <20251027183501.470555055@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183501.227243846@linuxfoundation.org> References: <20251027183501.227243846@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eugene Korenevsky commit 6447b0e355562a1ff748c4a2ffb89aae7e84d2c9 upstream. 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 Cc: stable@vger.kernel.org Suggested-by: Nathan Chancellor Acked-by: Paulo Alcantara (Red Hat) Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/smb/client/misc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) --- a/fs/smb/client/misc.c +++ b/fs/smb/client/misc.c @@ -866,6 +866,14 @@ parse_dfs_referrals(struct get_dfs_refer char *data_end; struct dfs_referral_level_3 *ref; + if (rsp_size < sizeof(*rsp)) { + cifs_dbg(VFS | ONCE, + "%s: header is malformed (size is %u, must be %zu)\n", + __func__, rsp_size, sizeof(*rsp)); + rc = -EINVAL; + goto parse_DFS_referrals_exit; + } + *num_of_nodes = le16_to_cpu(rsp->NumberOfReferrals); if (*num_of_nodes < 1) { @@ -874,6 +882,15 @@ parse_dfs_referrals(struct get_dfs_refer rc = -EINVAL; goto parse_DFS_referrals_exit; } + + if (sizeof(*rsp) + *num_of_nodes * sizeof(REFERRAL3) > rsp_size) { + cifs_dbg(VFS | ONCE, + "%s: malformed buffer (size is %u, must be at least %zu)\n", + __func__, rsp_size, + sizeof(*rsp) + *num_of_nodes * sizeof(REFERRAL3)); + rc = -EINVAL; + goto parse_DFS_referrals_exit; + } ref = (struct dfs_referral_level_3 *) &(rsp->referrals); if (ref->VersionNumber != cpu_to_le16(3)) {