Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3409292rwa; Tue, 23 Aug 2022 04:25:09 -0700 (PDT) X-Google-Smtp-Source: AA6agR6H6gwxTMnjEy8GgXySVt4EWyKncuRKDjPaybSyurUKzwQFetPa33cJUVtSnBNCW8uSXX+B X-Received: by 2002:a50:aa82:0:b0:445:dbba:6cb1 with SMTP id q2-20020a50aa82000000b00445dbba6cb1mr3238791edc.267.1661253909027; Tue, 23 Aug 2022 04:25:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253909; cv=none; d=google.com; s=arc-20160816; b=jyKF3nxbbS6sEKAPsnmDgqoarr4PtG56qZmo31f3h6cClB5jYzIZSYV4Yn0uJqM53a McpZmWdpevJIN+htDZ9uqheaEepEbydfoQXpTRi1KJpcultE1yG6M1MsgnSKLrWhXzlQ H+TpetVkcItEKv0ycL6IG/R/buO6lQThodxnDT6n7+aU+cHaihdbxLmw7o/owS+1UAVx ZI/UnxuGEselz57iofwikfQRKkXK/VL2gdAffxkjnVhxql+K1887ckRJNBZ1hI0Rje1r Im9b8Oob21g459Dg8k+5wBc2ZGZZyQiYK+mE0tRN/5NjIA7BhzrdjOzPdquQHAFLygKb 4fRw== 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=w4oP+i7SosaYgtnFe218r6/NGMnvxi9oH0KwzhRxrM0=; b=WAVE4nwd0tTcoEHp5L/PCUV2OAXeucA8uJ8Vq9Ot1ysb/asw/5gyHf/Uqv8H2T5c4T Av2OROeMqWsGouWgSsNm489Bz1kpt/BNlGhmK4NASjkoOgU7NATyramaFblDQlrFvtd/ puSLIf92czJnTpCWnd+tPu40kJQnvnY3NH71slQW6E1cn9VvcHME0OAAXaVbICFLcr7p MX/pVosc4ivq2+uAllA+u6saAC5Dz+eyv3wErhNvBAhv8udHqgubzeXg7gg9AFVeCtly KLJUmCXiAdU6vDNpJYFkp9OWf+jhk+My6rkSim9++yol687vzQAsn4pnnU2TQwa/cu9M 4cGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GObWW9G1; 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 oz10-20020a1709077d8a00b0073056870528si10979843ejc.888.2022.08.23.04.24.42; Tue, 23 Aug 2022 04:25:09 -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=GObWW9G1; 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 S1350486AbiHWJaR (ORCPT + 99 others); Tue, 23 Aug 2022 05:30:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350022AbiHWJ1x (ORCPT ); Tue, 23 Aug 2022 05:27:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D394491D16; Tue, 23 Aug 2022 01:37:24 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9B9C361446; Tue, 23 Aug 2022 08:35:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8C8EC433C1; Tue, 23 Aug 2022 08:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243730; bh=14BEbwuS/9GtFKmOQR6ugEwfl0StUNmna3JofOg1vEc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GObWW9G1aLMD9JW9XcGKZMpUQQco8IiIMg3gqksQ4n0F4pIDmedvbTm7tdnbQz+Ej 3hO62cSuBF06XI1hot6bKOoHxBYIzwnCgz4IEkFtaBsOADO1vCyrkgqHKbfncsZgNf ovw+qj4nttJ1lYj7tK4bToC8ec+njFLEPkhqhjEs= 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 329/365] ASoC: SOF: Intel: hda-ipc: Do not process IPC reply before firmware boot Date: Tue, 23 Aug 2022 10:03:50 +0200 Message-Id: <20220823080131.971138228@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 499cc881b09c8283ab5e75b0d6d21cb427722161 ] 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-3-peter.ujfalusi@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/intel/hda-ipc.c | 39 ++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/sound/soc/sof/intel/hda-ipc.c b/sound/soc/sof/intel/hda-ipc.c index f08011249955..65e688f749ea 100644 --- a/sound/soc/sof/intel/hda-ipc.c +++ b/sound/soc/sof/intel/hda-ipc.c @@ -148,17 +148,23 @@ irqreturn_t hda_dsp_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 */ @@ -225,16 +231,21 @@ irqreturn_t hda_dsp_ipc_irq_thread(int irq, void *context) * place, the message might not yet be marked as expecting a * reply. */ - 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); - /* set the done bit */ - hda_dsp_ipc_dsp_done(sdev); + /* set the done bit */ + hda_dsp_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