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 10AA9C433EF for ; Tue, 10 May 2022 15:51:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346749AbiEJPy7 (ORCPT ); Tue, 10 May 2022 11:54:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346995AbiEJPvs (ORCPT ); Tue, 10 May 2022 11:51:48 -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 EE066227CD8; Tue, 10 May 2022 08:46:31 -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 A7E5BB81DFB; Tue, 10 May 2022 15:46:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E9AEC385C9; Tue, 10 May 2022 15:46:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652197589; bh=FMJRUB1SG20TwFoKGF+M7aS86FGVewsJIqlGua4wN/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P03ygrp+7dSKJAUOpzdSf3yIzeUO8TgWjOPeVxYju3bbvyeSldCZsYhV4VXBymJVN H0lKLPtYx3v46VBwgmZmcGbFQVsy+nNTLmmq9Sh3fc48AVXxPcbJkmcDJjDGEyBmYy NxD1C1cBsomCOcFsx7LEzrEy7HQcF/Dc70lurrB7mMq5Rvy72C3CF5iYuJd80QWAZM TNtgd3W2C+BRD/ROh90eqnbPCUHSTL8DD8VWE/tQBGYIcQinoSON3Z+fBwZdhomRht pBm/JuVzbPL3yKFe+umE6bIBak4BeIkn3Bv19Q4VvFGOSRI4UEx4XsZGY5pshYeZUR rQ5Ox1Z/IhiPQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Mark Brown , Sasha Levin , lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 4.19 4/6] ASoC: ops: Validate input values in snd_soc_put_volsw_range() Date: Tue, 10 May 2022 11:46:12 -0400 Message-Id: <20220510154614.154187-4-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220510154614.154187-1-sashal@kernel.org> References: <20220510154614.154187-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: Mark Brown [ Upstream commit aa22125c57f9e577f0a667e4fa07fc3fa8ca1e60 ] Check that values written via snd_soc_put_volsw_range() are within the range advertised by the control, ensuring that we don't write out of spec values to the hardware. Signed-off-by: Mark Brown Link: https://lore.kernel.org/r/20220423131239.3375261-1-broonie@kernel.org Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/soc-ops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c index c88bc6bb41cf..7a37312c8e0c 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -523,7 +523,15 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert; unsigned int val, val_mask; - int err, ret; + int err, ret, tmp; + + tmp = ucontrol->value.integer.value[0]; + if (tmp < 0) + return -EINVAL; + if (mc->platform_max && tmp > mc->platform_max) + return -EINVAL; + if (tmp > mc->max - mc->min + 1) + return -EINVAL; if (invert) val = (max - ucontrol->value.integer.value[0]) & mask; @@ -538,6 +546,14 @@ int snd_soc_put_volsw_range(struct snd_kcontrol *kcontrol, ret = err; if (snd_soc_volsw_is_stereo(mc)) { + tmp = ucontrol->value.integer.value[1]; + if (tmp < 0) + return -EINVAL; + if (mc->platform_max && tmp > mc->platform_max) + return -EINVAL; + if (tmp > mc->max - mc->min + 1) + return -EINVAL; + if (invert) val = (max - ucontrol->value.integer.value[1]) & mask; else -- 2.35.1