From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27784C4167D for ; Tue, 7 Nov 2023 16:03:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343584AbjKGQDj (ORCPT ); Tue, 7 Nov 2023 11:03:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344084AbjKGQDF (ORCPT ); Tue, 7 Nov 2023 11:03:05 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A823327C; Tue, 7 Nov 2023 07:54:08 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3FE9C433C7; Tue, 7 Nov 2023 15:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699372448; bh=QyfMn0m+wIc0YqVUhOMA4/o2wNCae2vvJsgWRIbeHIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OfAnUNCtlfyeq5KDTqgqX1RFVuZ/WGEsruPZeFUaPjvnsrzK78VdsT1wvuWi7ZtR7 T8kSVyCSwfajNIe29m2e257q0mTSrLnatbq79RHdVQk4/NmD8vCXCTGn3qwUmKSCDi urhK63jGoZe9e9h9PJIB3z3C/EICt8Ta9c2bVUupMWlkxWD2lvsupgeDVvCE7KCaEo 7zMNyN6ZnztFSuXoUXWWbZKdYkt2dJZJd6/ONRiSVGZ3mSxUDFRV1Eq2rSjLRptpnL 84p8bLB5ezthyjzakBX1N3xZOxxQXbb1TBwBwDyH1W2O+zChX1Zh7oyY0JkkkMn+5h 3PhOsADNCJa+Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cezary Rojewski , Takashi Iwai , Sasha Levin , perex@perex.cz, tiwai@suse.com, broonie@kernel.org, siyanteng@loongson.cn, zhangyiqun@phytium.com.cn, linux-sound@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 08/12] ALSA: hda: Fix possible null-ptr-deref when assigning a stream Date: Tue, 7 Nov 2023 10:53:26 -0500 Message-ID: <20231107155343.3768464-8-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231107155343.3768464-1-sashal@kernel.org> References: <20231107155343.3768464-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.4.259 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Cezary Rojewski [ Upstream commit f93dc90c2e8ed664985e366aa6459ac83cdab236 ] While AudioDSP drivers assign streams exclusively of HOST or LINK type, nothing blocks a user to attempt to assign a COUPLED stream. As supplied substream instance may be a stub, what is the case when code-loading, such scenario ends with null-ptr-deref. Signed-off-by: Cezary Rojewski Link: https://lore.kernel.org/r/20231006102857.749143-2-cezary.rojewski@intel.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/hda/hdac_stream.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/hda/hdac_stream.c b/sound/hda/hdac_stream.c index 2beb94828729d..f810f401c1de8 100644 --- a/sound/hda/hdac_stream.c +++ b/sound/hda/hdac_stream.c @@ -313,8 +313,10 @@ struct hdac_stream *snd_hdac_stream_assign(struct hdac_bus *bus, struct hdac_stream *res = NULL; /* make a non-zero unique key for the substream */ - int key = (substream->pcm->device << 16) | (substream->number << 2) | - (substream->stream + 1); + int key = (substream->number << 2) | (substream->stream + 1); + + if (substream->pcm) + key |= (substream->pcm->device << 16); spin_lock_irq(&bus->reg_lock); list_for_each_entry(azx_dev, &bus->stream_list, list) { -- 2.42.0