Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp760109pxb; Tue, 5 Apr 2022 22:07:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzMFFS8z9c8U0k2IkDs9LiEyW2+wUFC5Qp+dBwsMuOjBG44BIegNr1Zy41WlD2hS6pOZSa4 X-Received: by 2002:a63:6a85:0:b0:398:9e2b:afd6 with SMTP id f127-20020a636a85000000b003989e2bafd6mr5764832pgc.582.1649221651549; Tue, 05 Apr 2022 22:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649221651; cv=none; d=google.com; s=arc-20160816; b=qXDnNkociQIdtNE1QxcWQNrxlMkcexYT9X4FqOPPoyL4Ve+9YojNg+YwYpR5ad5ZGf uksUAWKbgkYrODaLjmyMyAqPcRmSnqpL8UMBqQKW/0WmdIl9uDjZCrL6Qbh/8z4ChexO 5WdZACX60518ehLOK0mti1fmowO2aza/PORDWiKPtuhRdLCU2VDlLy9cKIwVzgBKrH4Y UQVD/l7zXH1KmiRpuvICO+Fhu0xSacz87STrHA7mo6YMGX236MHpGgiyN7R4G5IOI56V QH94SSFRBu5lXuBcyq0hlCfUpkxkKFzLfywckeV8OzQHuPZu4KV5ntLo3th32/qFUbkA WP/A== 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=5k4zCoO98XfYPZZi4QjiAQbareRPRJ+W8UyUWTNZ1Xo=; b=eBygrEbc4HeMn4WKhUV0ykwOmqTZU8RJ72tJjpsAWQZjBaLalR7bCZZAbSQ88s46Ma k4issY8bbjiEqFn7aSVKLa26kh8GfwdtOuBMI1uf9qGGV99EHsYVEwAXStfSYgabd0lv tip/DNV58qSexg7LVelRJsBQdnJCVLxwpBpUBNXo0iwcAh1oFkMGqtKjIpvka0JIKGY6 IV24K1jN0bk6t3s7G3y4cCcJzAcgwcctU2KQa87t+zAfBOEiBWbcPilmB7V8StENu5Pm qIVzmCnLNncmG5yriEPY0xwkE4CtZAuhJzVjEs3hWW6d7CPj2Y1nshEPLbAd96n2NUQu aoyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M5UVloQv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id o4-20020a635a04000000b003816043f06asi16019011pgb.607.2022.04.05.22.07.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 22:07:31 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=M5UVloQv; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B12CF3FD9C; Tue, 5 Apr 2022 20:30:55 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382937AbiDEMR2 (ORCPT + 99 others); Tue, 5 Apr 2022 08:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244951AbiDEIwu (ORCPT ); Tue, 5 Apr 2022 04:52:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 603691BE93; Tue, 5 Apr 2022 01:47:30 -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 F0D31614F9; Tue, 5 Apr 2022 08:47:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01DB8C385A1; Tue, 5 Apr 2022 08:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148449; bh=jnIWHDgOZkh/R09nfdNYG2FZyVhHJZY2eXP9w+iXCQA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M5UVloQvN4UuUMdvT8VB43Ygu/5H33DZDpu1ON8Si1U5f7PHRjFwHlMeX97Amtw9/ C4JYm2AnUotLl3sbXV527N9AG4PGDrtm3eYs6k+lmZ33EdD0POo7eFWDskNhR6dFsG Ahlej+wHvlmSIxYa5gbwaNbhzwv6hgNsHFMHW2/Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiasheng Jiang , kernel test robot , Dan Carpenter , Mark Brown , Sasha Levin Subject: [PATCH 5.16 0362/1017] ASoC: soc-compress: prevent the potentially use of null pointer Date: Tue, 5 Apr 2022 09:21:15 +0200 Message-Id: <20220405070405.030432822@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Jiasheng Jiang [ Upstream commit de2c6f98817fa5decb9b7d3b3a8a3ab864c10588 ] There is one call trace that snd_soc_register_card() ->snd_soc_bind_card()->soc_init_pcm_runtime() ->snd_soc_dai_compress_new()->snd_soc_new_compress(). In the trace the 'codec_dai' transfers from card->dai_link, and we can see from the snd_soc_add_pcm_runtime() in snd_soc_bind_card() that, if value of card->dai_link->num_codecs is 0, then 'codec_dai' could be null pointer caused by index out of bound in 'asoc_rtd_to_codec(rtd, 0)'. And snd_soc_register_card() is called by various platforms. Therefore, it is better to add the check in the case of misusing. And because 'cpu_dai' has already checked in soc_init_pcm_runtime(), there is no need to check again. Adding the check as follow, then if 'codec_dai' is null, snd_soc_new_compress() will not pass through the check 'if (playback + capture != 1)', avoiding the leftover use of 'codec_dai'. Fixes: 467fece ("ASoC: soc-dai: move snd_soc_dai_stream_valid() to soc-dai.c") Signed-off-by: Jiasheng Jiang Reported-by: kernel test robot Reported-by: Dan Carpenter Link: https://lore.kernel.org/r/1634285633-529368-1-git-send-email-jiasheng@iscas.ac.cn Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-compress.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sound/soc/soc-compress.c b/sound/soc/soc-compress.c index 8e2494a9f3a7..f4b376a71be8 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -568,12 +568,14 @@ int snd_soc_new_compress(struct snd_soc_pcm_runtime *rtd, int num) } /* check client and interface hw capabilities */ - if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && - snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK)) - playback = 1; - if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && - snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) - capture = 1; + if (codec_dai) { + if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_PLAYBACK) && + snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK)) + playback = 1; + if (snd_soc_dai_stream_valid(codec_dai, SNDRV_PCM_STREAM_CAPTURE) && + snd_soc_dai_stream_valid(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) + capture = 1; + } /* * Compress devices are unidirectional so only one of the directions -- 2.34.1