Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp364063pxb; Fri, 15 Oct 2021 07:05:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsZ4tWdqFJ1F1vr5L+Q/ort2bc4R4zjha5mLPBvxLCOWm50HgAPm1lRaTxcAqnQ/wu5hVm X-Received: by 2002:a17:90b:3e8d:: with SMTP id rj13mr13825973pjb.183.1634306736146; Fri, 15 Oct 2021 07:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634306736; cv=none; d=google.com; s=arc-20160816; b=cIA0mQ09b8riA0BROC64+PXcgvJJZTIi2lEQvagwSjeiLHvQTGKadUkhIuOsEOa+1Y SEvEc9i4RTj4j2c5W6EQ1yR1C8XwKZXJworgg56Z9DzVefFHmcxzJq6WTc+G/QSz1aiM CDTMN57FgQPP/7cdzGv2wxf8dSabgveFIbeLYYrTazjy0VeKcQ9lcOIoM/mntEvFStFF kzt2n8+IsJnj741nKLAC2CN8gSBAZorP6PIFoF6Ym6hwXEtIbT7g9EOC3HocMX1iYion jmgrysmYM5WeG/uZJJjPeRs/VGVpurT8HpciBZ2ga0trRykpSonr7bOYcLkeTN8aDOs6 u8jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=6dnz4weZR2fV8N9dM9W4ddr9AsyBl1y9Vd98h5r4nIk=; b=DV/nUsGawoCRgzw/mzy4484xieLD2emwJSB+NtD7mp40BW9ZTcaTBR3lqPEWHB4S1I Bhnf7Fpnt67AWH2pSEI7Dsr34TZsViq1pcQbIPkmQgHzjhlBtZBFexXztqODdhyKOXl7 OELivinW5JbwomlOeXpk4KPBgZc2eLaKu9tN5+uVAcXUuYgQV8xn6DVMIO4N8MNYk6tf ePu9yoIatYOFhFaDAIcP6Nm6EcaawPnbhzcaV9Y2Rq7j4hCFhMWkDVgiyfpk1zZ1E3qG cxPccZ0U2K2O3HtCpYZq/HtaBciPKIuqmzvE9CugFGknbv2AurbrchnTZ8PGE9tUh69P pe+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q11si2471906plb.242.2021.10.15.07.05.22; Fri, 15 Oct 2021 07:05:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236164AbhJOIQd (ORCPT + 99 others); Fri, 15 Oct 2021 04:16:33 -0400 Received: from smtp21.cstnet.cn ([159.226.251.21]:60226 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236151AbhJOIQc (ORCPT ); Fri, 15 Oct 2021 04:16:32 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-01 (Coremail) with SMTP id qwCowAAXHAhCOGlhinkUBA--.25093S2; Fri, 15 Oct 2021 16:13:54 +0800 (CST) From: Jiasheng Jiang To: vkoul@kernel.org, lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz, tiwai@suse.com Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jiasheng Jiang Subject: [PATCH v2] ASoC: soc-compress: prevent the potentially use of null pointer Date: Fri, 15 Oct 2021 08:13:53 +0000 Message-Id: <1634285633-529368-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: qwCowAAXHAhCOGlhinkUBA--.25093S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Ww4kKFW8Kr4xAFy3Jr1kZrb_yoW8KF1Upr s7WrZ7tFyfJr4Ivw1rA3yF9F1fGryxuF409w1aq34xAr43XFsxWr1UtrWvyFy7ArZ8t34D X3sFv3y7X3Z8AFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkS14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s 0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xII jxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr 1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8ZwCF 04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r 18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vI r41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr 1lIxAIcVCF04k26cxKx2IYs7xG6rW3Jr0E3s1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUeHUDDUUUU X-Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 b4f5935..67c3df1 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.7.4