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 57AA4CCA47B for ; Tue, 28 Jun 2022 02:30:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244676AbiF1CaW (ORCPT ); Mon, 27 Jun 2022 22:30:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244472AbiF1C0i (ORCPT ); Mon, 27 Jun 2022 22:26:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0078248F4; Mon, 27 Jun 2022 19:24:22 -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 7617AB81C10; Tue, 28 Jun 2022 02:24:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 50729C385A2; Tue, 28 Jun 2022 02:24:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1656383060; bh=hwJBwdalUayAZ8Ey4wibUrKwxJOXcB6iJ1Xwl1XLv/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l/XshtJ0p4DpMzCZj1/uvX0A2Vf9Rz7Xxqj7XtPqc9bkNoR0P5Ot3M1z984f5fmAi eieKPWIZw1KHj/1NIK45sQ68zxeEeb5MofvcMWhFe8C9wO3XFfud/8SC8wSBBzhcp1 WGzSvnlZIqSxfL7n6DsAL5kvTyqn+cUCkju0/3kbU5dx6srCyWRkOCBy3Vx0KJ02lk 2LvC21HI0gXp6BN/zqcuR9iMHwW4ERlGntHdMn/U0xcC8DKwMKdKH1tGHAAZrr3h1p q3E+WXD3s0YZgLZ905Ucwwxr8UL6/5eGDVxgXPGOBhq+56SRM1x8bfA7lEBOtU6LQp rZgQv19Paed+g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Daniil Dementev , Alexey Khoroshilov , Takashi Iwai , Sasha Levin , perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.4 03/27] ALSA: usb-audio: US16x08: Move overflow check before array access Date: Mon, 27 Jun 2022 22:23:49 -0400 Message-Id: <20220628022413.596341-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220628022413.596341-1-sashal@kernel.org> References: <20220628022413.596341-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: Daniil Dementev [ Upstream commit 3ddbe35d9a2ebd4924d458e0246b4ba6c13bb456 ] Buffer overflow could occur in the loop "while", due to accessing an array element before checking the index. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Daniil Dementev Reviewed-by: Alexey Khoroshilov Link: https://lore.kernel.org/r/20220610165732.2904-1-d.dementev@ispras.ru Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/usb/mixer_us16x08.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sound/usb/mixer_us16x08.c b/sound/usb/mixer_us16x08.c index c6c834ac83ac..5e4aa1207c1b 100644 --- a/sound/usb/mixer_us16x08.c +++ b/sound/usb/mixer_us16x08.c @@ -637,10 +637,10 @@ static int snd_get_meter_comp_index(struct snd_us16x08_meter_store *store) } } else { /* skip channels with no compressor active */ - while (!store->comp_store->val[ + while (store->comp_index <= SND_US16X08_MAX_CHANNELS + && !store->comp_store->val[ COMP_STORE_IDX(SND_US16X08_ID_COMP_SWITCH)] - [store->comp_index - 1] - && store->comp_index <= SND_US16X08_MAX_CHANNELS) { + [store->comp_index - 1]) { store->comp_index++; } ret = store->comp_index++; -- 2.35.1