Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F0886C76196 for ; Wed, 22 Mar 2023 19:59:52 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 26A82EC4; Wed, 22 Mar 2023 20:59:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 26A82EC4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679515191; bh=QHiqBaDd7TKi3Fgb4EqKzNbkcwRu76OmI/eB7btnxU4=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uPZrRuRTU/7KzvV1FziQxw43EDzlPiH/sPSo7RmpBtsXA7EeAfF1l+u/BEQOiEtLp thaMhfCYwO81Sf8HlN70/Ss+bNLrRt5SEfu92WOm9bIOMmOgtsCL6Ws8bDjl/cl6NE WnaQExJNL3bXibs4fRiGu3uCBr7EZicSWKO8K+es= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id F3628F80553; Wed, 22 Mar 2023 20:58:14 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 15BB2F80557; Wed, 22 Mar 2023 20:58:11 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7F12CF80549; Wed, 22 Mar 2023 20:58:06 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7F12CF80549 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=stl1Dk4j Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 314BC622B2; Wed, 22 Mar 2023 19:58:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28A9CC4339E; Wed, 22 Mar 2023 19:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679515084; bh=QHiqBaDd7TKi3Fgb4EqKzNbkcwRu76OmI/eB7btnxU4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=stl1Dk4j4cHTIZS18wpnhtdl4ZA5BQeWyYOS5OWLcDPF5vjzo5kEzmoDsL66xyCZW Vm48bfnkc4xkJNd1B4AUoLdXBrUtGIyyDNL75027egR+mMGixuZqyoslfajPKu1TmT MbDknoImBln26ObRFhndFKQ1QIcOYOWzfvkTNTkqN3GZphOLzgt0hoQ9v99NWUVd0/ kXlug8aHRfA4NwUWID3wobo11dwRcF9PnzXaZRpjhczBNSYiBifIYVmjyUdJjiT0MO UT9DUQoRHe99z/GwgZUeC4+1VPULuotrfKPkezDAO1v+Jy0jlrJnX7PF7Zr6MEk58i vOAC8i21KSD3g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 6.2 14/45] ASoC: SOF: ipc3: Check for upper size limit for the received message Date: Wed, 22 Mar 2023 15:56:08 -0400 Message-Id: <20230322195639.1995821-14-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322195639.1995821-1-sashal@kernel.org> References: <20230322195639.1995821-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Message-ID-Hash: VG4MJPAAJC6TKLKDM5IANPJEVQ74E3WX X-Message-ID-Hash: VG4MJPAAJC6TKLKDM5IANPJEVQ74E3WX X-MailFrom: sashal@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Peter Ujfalusi , Curtis Malainey , Pierre-Louis Bossart , Curtis Malainey , Mark Brown , Sasha Levin , lgirdwood@gmail.com, yung-chuan.liao@linux.intel.com, ranjani.sridharan@linux.intel.com, daniel.baluta@nxp.com, tiwai@suse.com, sound-open-firmware@alsa-project.org, alsa-devel@alsa-project.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Ujfalusi [ Upstream commit 989a3e4479177d0f4afab8be1960731bc0ffbbd0 ] The sof_ipc3_rx_msg() checks for minimum size of a new rx message but it is missing the check for upper limit. Corrupted or compromised firmware might be able to take advantage of this to cause out of bounds reads outside of the message area. Reported-by: Curtis Malainey Signed-off-by: Peter Ujfalusi Reviewed-by: Pierre-Louis Bossart Reviewed-by: Curtis Malainey Signed-off-by: Peter Ujfalusi Link: https://lore.kernel.org/r/20230307114917.5124-1-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/ipc3.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/sof/ipc3.c b/sound/soc/sof/ipc3.c index 1fef4dcc09368..fde8af5a1f485 100644 --- a/sound/soc/sof/ipc3.c +++ b/sound/soc/sof/ipc3.c @@ -970,8 +970,9 @@ static void sof_ipc3_rx_msg(struct snd_sof_dev *sdev) return; } - if (hdr.size < sizeof(hdr)) { - dev_err(sdev->dev, "The received message size is invalid\n"); + if (hdr.size < sizeof(hdr) || hdr.size > SOF_IPC_MSG_MAX_SIZE) { + dev_err(sdev->dev, "The received message size is invalid: %u\n", + hdr.size); return; } -- 2.39.2