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 D5D44C7619A for ; Wed, 22 Mar 2023 20:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231995AbjCVUKm (ORCPT ); Wed, 22 Mar 2023 16:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232103AbjCVUKE (ORCPT ); Wed, 22 Mar 2023 16:10:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 056A160A8C; Wed, 22 Mar 2023 13:03:20 -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 DA698622D2; Wed, 22 Mar 2023 20:03:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49586C433A0; Wed, 22 Mar 2023 20:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1679515399; bh=2d7wGBrkNTLru+WOroZkrHtfsI3EP5FJyFrurt62Y9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=niw0k1aK5L10h1Yle4tB/8IVadcuJdc7Wxru0jEat6fw9kzf7ZCQMoXeW8za4TVg9 EJBOQfTDZuxlJnydcrDJwfw0iUSEUE/eB6AMqVVPm2uEsWsYcaNRvgxFvgihALX/Pa RKkii+l2xWzco2KYF67gcajbGKm09EqJh9E/uzfFINR8q2GzAOhznFSi3JHvrEeky9 3eYq36s+QtGxM4qVxPEM9n2XvEGfZq/ZqeMPtMZlUJDNtpy+2RyMIJejQ6SOHZfrGm YmZAmARdYQ3KG3OoIu9JJqdr7O2sfCO+fMYT23afIDgHR1oQUnrRPaS83VJ0D1Tu5C 9fNx3NiMdr8qA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kuninori Morimoto , Takashi Iwai , Sasha Levin , perex@perex.cz, tiwai@suse.com, dev@xianwang.io, ye.xingchen@zte.com.cn, gremlin@altlinux.org, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.19 3/9] ALSA: hda/ca0132: fixup buffer overrun at tuning_ctl_set() Date: Wed, 22 Mar 2023 16:03:03 -0400 Message-Id: <20230322200309.1997651-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230322200309.1997651-1-sashal@kernel.org> References: <20230322200309.1997651-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ca8a37388d565..9f0e6bbc523c3 100644 --- a/sound/pci/hda/patch_ca0132.c +++ b/sound/pci/hda/patch_ca0132.c @@ -3620,8 +3620,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