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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13265C6FD1C for ; Wed, 22 Mar 2023 20:06:22 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8976FF0C; Wed, 22 Mar 2023 21:05:30 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8976FF0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1679515580; bh=2pa5qYOH99HejMlK7P61qqxdiYP9eVCz52UkJjVO/bc=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=XPXnv94e9c2I57ORiyTTYCfRPUgyBMYxyE82s8wELn+rB8tRl+Z0gv0R0j2bJ4CvM 6KszryentKQrxNcuIAjXo8kghJEj1I4ZC6epOqmZ3kgESkrfRE3etGeKK/tL6yoZcq dgqoNEaT7QVJMIXoajIFHWH+eJtKABNd3+5O0KsQ= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E82D6F805B5; Wed, 22 Mar 2023 21:01:51 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 3A198F805AE; Wed, 22 Mar 2023 21:01:49 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 85024F805A1 for ; Wed, 22 Mar 2023 21:01:46 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 85024F805A1 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=BnILllBQ 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 5ADCAB81DF3; Wed, 22 Mar 2023 20:01:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00999C433EF; Wed, 22 Mar 2023 20:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679515305; bh=2pa5qYOH99HejMlK7P61qqxdiYP9eVCz52UkJjVO/bc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BnILllBQIdVJPs+pHlhOz0rwl8Xn6XB159vj13IshiOAuM4IOVr/VFdt0sTRO024/ wmIAvwAqznwFDFCzJOjFI2v3eWwY/BSwlpzOki1wGAezHUR9RrXj821lzRwYOe5oEY 8EZBL6AOLkmxFh6fHZAER/5BUfiivMKX9zwrDJByjitdFKZ8FgTC24bW3vAHJH8+tO rqNf62JJGE5ruD4NivqwRnElKxeoifY8zDYfiC8z7+PNKkyGpguuhc8KzVKmG8ZlbE fWa5GundDI+0K4Jm+ysFl2QNvJUkia2LJFFyGc1wcLgNl2FScWNOHdpncT/6GFOt6t 87kF40aA1F7Zg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 07/16] ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() Date: Wed, 22 Mar 2023 16:01:11 -0400 Message-Id: <20230322200121.1997157-7-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322200121.1997157-1-sashal@kernel.org> References: <20230322200121.1997157-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Message-ID-Hash: MPCOAVOAAUM7H64S7UERV3P5YTC7BWQK X-Message-ID-Hash: MPCOAVOAAUM7H64S7UERV3P5YTC7BWQK X-MailFrom: sashal@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Kuninori Morimoto , Takashi Iwai , Sasha Levin , tiwai@suse.com, dev@xianwang.io, gremlin@altlinux.org, ye.xingchen@zte.com.cn, alsa-devel@alsa-project.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Kuninori Morimoto [ Upstream commit 98e5eb110095ec77cb6d775051d181edbf9cd3cf ] tuning_ctl_set() might have buffer overrun at (X) if it didn't break from loop by matching (A). static int tuning_ctl_set(...) { for (i = 0; i < TUNING_CTLS_COUNT; i++) (A) if (nid == ca0132_tuning_ctls[i].nid) break; snd_hda_power_up(...); (X) dspio_set_param(..., ca0132_tuning_ctls[i].mid, ...); snd_hda_power_down(...); ^ return 1; } We will get below error by cppcheck sound/pci/hda/patch_ca0132.c:4229:2: note: After for loop, i has value 12 for (i = 0; i < TUNING_CTLS_COUNT; i++) ^ sound/pci/hda/patch_ca0132.c:4234:43: note: Array index out of bounds dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20, ^ This patch cares non match case. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87sfe9eap7.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/hda/patch_ca0132.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_ca0132.c b/sound/pci/hda/patch_ca0132.c index c0cb6e49a9b65..2646663e03426 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -4231,8 +4231,10 @@ static int tuning_ctl_set(struct hda_codec *codec, hda_nid_t nid, for (i = 0; i < TUNING_CTLS_COUNT; i++) if (nid == ca0132_tuning_ctls[i].nid) - break; + goto found; + return -EINVAL; +found: snd_hda_power_up(codec); dspio_set_param(codec, ca0132_tuning_ctls[i].mid, 0x20, ca0132_tuning_ctls[i].req, -- 2.39.2