Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3402978rwa; Tue, 23 Aug 2022 04:18:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR6KDOv/IfNYBHBAfQFWnsa7ic37JPibDNs0ZoBASmagYtclZWNoux0CXtDCwVuddt0z1PNR X-Received: by 2002:a65:4d48:0:b0:421:5af6:9278 with SMTP id j8-20020a654d48000000b004215af69278mr20453529pgt.1.1661253529504; Tue, 23 Aug 2022 04:18:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253529; cv=none; d=google.com; s=arc-20160816; b=zmilxIqK2Kav/GV0EPY8yhr5bfqyP/ejNYoECzzSXBni6atRUKzy6F2zB9zalKW7hJ 1/C+4EygBRH6K/BFBJWT70fbJDAwTLoO9J9CIFXKiQLCl7CEUbVAfvV/zmKFXbp4YsMC 5ZbcB8QXpWEhXXV2EdxCu4nKwLqPfDgyD7wNnPl7341L6qg6G/nCaWsItVAgHGnvptxF 8EwZNKU6CVR2v3V4f9tQvb/dKt8ZHQ8rC/MR0RrlXo2ch53o9CL7Ac790EN9pv/Oy9Oz 66AFxE8RpsurRdo4PKvfA9L8HLhbaDI9z2kpLXdRd22KQUmAwSUfMqTgX/c0Njf10N5N MnmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k7iIc6BPelehJ3Putn0Tgav/h6bAH2fTbUKA19Y1fNw=; b=AcSaCR08cGQVNhum+CN0IbifZXsRcrgv+dz2LmH7y27KaNgA2TWho+6Fhw5auQdS7q nxnMsPioS5BpfgbD6QRckdKGW20KrNC7M35vcxlKIlA7bUJtz5LUW9wwBeO5Y85QF60I bWbiSODvq6bbIws3j9kbqlfnEkEBpABaqIL3KlBNBAiO9jzm/pm2e3t2jJQtAq5Vk1gY ByCPEcklO8TrTTi7nmNtG239gZJwtUHzFN5RrqdUCUzt0Zl5IHlQxp5e+hhnjd5EMrjO z9Sgt3wZKefes2Y1NHHp6UnQUp32T0q59Apy4C4JGuKv/YIvlYHzn3Z3HRHIuxz7yUto Kcog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HZVGWGz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g67-20020a636b46000000b0042ad28ace95si516802pgc.832.2022.08.23.04.18.38; Tue, 23 Aug 2022 04:18:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HZVGWGz+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348936AbiHWJXZ (ORCPT + 99 others); Tue, 23 Aug 2022 05:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349933AbiHWJVO (ORCPT ); Tue, 23 Aug 2022 05:21:14 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F4C08A7E4; Tue, 23 Aug 2022 01:34:17 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id 28301B81C4C; Tue, 23 Aug 2022 08:33:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7945AC433D6; Tue, 23 Aug 2022 08:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243604; bh=mwmDbCfw/ao0izZKovfnIvnOORITV54RWHghuELPKFg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HZVGWGz+ehC/nk/FSVG6XcBEX9vW2svqCJf89hZ/dn5ugJx+jrCRKIIeRlTZnx+t8 nLGC/k6Qh2vIIBsdTFs5nOsBPaiePxU7oEyfGF4jRUhGPGE9ckiBfMdNrs1GR0+R2f BePyXx2BHIO1A5P7HBT+NBrTSWWMGcPZKCLvhtbE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kai Vehmanen , Peter Ujfalusi , Ranjani Sridharan , Pierre-Louis Bossart , Mark Brown , Sasha Levin Subject: [PATCH 5.19 328/365] ASoC: SOF: Intel: cnl: Do not process IPC reply before firmware boot Date: Tue, 23 Aug 2022 10:03:49 +0200 Message-Id: <20220823080131.919228424@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Ujfalusi [ Upstream commit acacd9eefd0def5a83244d88e5483b5f38ee7287 ] It is not yet clear, but it is possible to create a firmware so broken that it will send a reply message before a FW_READY message (it is not yet clear if FW_READY will arrive later). Since the reply_data is allocated only after the FW_READY message, this will lead to a NULL pointer dereference if not filtered out. The issue was reported with IPC4 firmware but the same condition is present for IPC3. Reported-by: Kai Vehmanen Signed-off-by: Peter Ujfalusi Reviewed-by: Ranjani Sridharan Reviewed-by: Pierre-Louis Bossart Link: https://lore.kernel.org/r/20220712122357.31282-2-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/intel/cnl.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/sound/soc/sof/intel/cnl.c b/sound/soc/sof/intel/cnl.c index cd6e5f8a5eb4..6c98f65635fc 100644 --- a/sound/soc/sof/intel/cnl.c +++ b/sound/soc/sof/intel/cnl.c @@ -60,17 +60,23 @@ irqreturn_t cnl_ipc4_irq_thread(int irq, void *context) if (primary & SOF_IPC4_MSG_DIR_MASK) { /* Reply received */ - struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data; + if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) { + struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data; - data->primary = primary; - data->extension = extension; + data->primary = primary; + data->extension = extension; - spin_lock_irq(&sdev->ipc_lock); + spin_lock_irq(&sdev->ipc_lock); - snd_sof_ipc_get_reply(sdev); - snd_sof_ipc_reply(sdev, data->primary); + snd_sof_ipc_get_reply(sdev); + snd_sof_ipc_reply(sdev, data->primary); - spin_unlock_irq(&sdev->ipc_lock); + spin_unlock_irq(&sdev->ipc_lock); + } else { + dev_dbg_ratelimited(sdev->dev, + "IPC reply before FW_READY: %#x|%#x\n", + primary, extension); + } } else { /* Notification received */ notification_data.primary = primary; @@ -124,15 +130,20 @@ irqreturn_t cnl_ipc_irq_thread(int irq, void *context) CNL_DSP_REG_HIPCCTL, CNL_DSP_REG_HIPCCTL_DONE, 0); - spin_lock_irq(&sdev->ipc_lock); + if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) { + spin_lock_irq(&sdev->ipc_lock); - /* handle immediate reply from DSP core */ - hda_dsp_ipc_get_reply(sdev); - snd_sof_ipc_reply(sdev, msg); + /* handle immediate reply from DSP core */ + hda_dsp_ipc_get_reply(sdev); + snd_sof_ipc_reply(sdev, msg); - cnl_ipc_dsp_done(sdev); + cnl_ipc_dsp_done(sdev); - spin_unlock_irq(&sdev->ipc_lock); + spin_unlock_irq(&sdev->ipc_lock); + } else { + dev_dbg_ratelimited(sdev->dev, "IPC reply before FW_READY: %#x\n", + msg); + } ipc_irq = true; } -- 2.35.1