Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp859576pxb; Wed, 6 Apr 2022 02:15:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzLLnpUw7xtf1Uujt8ctaFKsbZftF8YO4c1iNDb5JgA6EtJqmUGxC5rylGq7wHjRoRwuGfr X-Received: by 2002:a63:7888:0:b0:398:91:7b5e with SMTP id t130-20020a637888000000b0039800917b5emr6428028pgc.212.1649236552008; Wed, 06 Apr 2022 02:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649236552; cv=none; d=google.com; s=arc-20160816; b=zxZEVrkvn1znIF4g6sdkf0AkWK6FkEveGnEG4tpsvQnha5j+BycZT7pDcpLNhugusG vnxou2s2DC98zYx1BQQV73yQw+cz9NY/k1lNfvRUbxFoUakKKqoxPJTnE8+cvWZkcQqa MQ0AWt0NB3y4+jydbfSqTR5mGLn4VeO7MhDnt2OtrUoiOOukMIw9qPcdu4orftB6QXwm 7J0TRK6P0PhchAri67RWioVzu/E7s+zg/kI0R4+Hhnc0hgOTa5P3CZVtprYYUQKAMKSc Kcff61QbipcGXMRdP2b/ffoaKhL8fA2VBc7zDejC/+8QVuYJF9cQd/ObzhMfsRQ5NSsX zVyQ== 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=UBkNrrcO9V/graNYt9wuvCVskUujYtWt7eZj3N9o7bQ=; b=u2PEjw87VwB6LpRYDfChZau5n2KeGz2ssnfE05nwRPyNX9wTKs9iCysIvZbAPeozMq J5d98TA+TesQlQQgD0J9TkDmUqtj5PH43E9uxsZfsd32AGQlq6gtnvVZierGgkPnmLxx CKMsdapj9AgSEAqz4RFD+8BsXysFbABZdLgceQw2AtZm/jPeE5C8KiZanq2H+oGO2XKZ ZZFrt3zE1Q3U9a1cdNhNz1DCzCZ2Ljn9oBb94Uzz2QAkKrcaJOZ9O9Fx1DZB5KdkdUCl SEsBpXMff7Qe7i42rBzFhjAlCsuDmHS8sTY81HV1poDBr91JMRwhUgRkzSvdo6m3qJS9 KsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="S7e/uhRn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id e2-20020a17090a728200b001ca88b83401si258039pjg.184.2022.04.06.02.15.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 02:15:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="S7e/uhRn"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 BC0A2537787; Wed, 6 Apr 2022 01:04:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382206AbiDEUlY (ORCPT + 99 others); Tue, 5 Apr 2022 16:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233184AbiDEJri (ORCPT ); Tue, 5 Apr 2022 05:47:38 -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 776716E35E; Tue, 5 Apr 2022 02:33:52 -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 BF268B81C8B; Tue, 5 Apr 2022 09:33:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EBB4C385A2; Tue, 5 Apr 2022 09:33:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151229; bh=cFO6HgVokv2VEw7zhA3ChtpY/z8hbwaLiKRnodb+Hl4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S7e/uhRn6bXU4HopxZxbCkwBLs8KSzreoNLIEZ4knaE4qnvwktp1pVhn1L7xD/VjW XNfyIeTFz/VrZ/GIzFUecSMf0hFzncMw2mDr5tqcsoVC2/zUqDvd3YULoQrVnwFw9d slSzj3s6ovTKw24mTcmSJsB+WXPDoeVhKvy5jFNg= 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.15 341/913] ASoC: soc-compress: prevent the potentially use of null pointer Date: Tue, 5 Apr 2022 09:23:23 +0200 Message-Id: <20220405070350.069350755@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 36060800e9bd..b3c64f87e054 100644 --- a/sound/soc/soc-compress.c +++ b/sound/soc/soc-compress.c @@ -535,12 +535,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