Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3324620iob; Mon, 16 May 2022 19:26:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1q6NAy6i86lI7sTDvFXuAvHQr2ptWAhTfMYc7Nt6ureh01c1+AfOvqkrRs6dJiaAqRKux X-Received: by 2002:a05:6402:268f:b0:427:d90e:86a1 with SMTP id w15-20020a056402268f00b00427d90e86a1mr16158919edd.143.1652754366261; Mon, 16 May 2022 19:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652754366; cv=none; d=google.com; s=arc-20160816; b=0Co9jjQPiy6cWh5uC0GsPFZloeKEPhcwiVHIKBUmVjug6y9K4g+ibTXbD3UkxGVaSe oNg1D7EFeCMmX0Z2ioB7TeTbACaiDpZ7tpZ9iSHCht27ObWVKp0vskSZa5zyql5qKhcR oGABSyn8LaWUPnxXUVTEacJ0qNt21A8JnihOzHNg3ZaleZTxSSaBUrpm507sH7Kr9bQt GqcKunWWKD3OAQ1gOz92nhVBF0ZIhCY7U9fdwjB42U3ROM5ZYa5Mx23AazV1oi+K80pu 6ekHyQDXgbKlF7r9+GgRHhtPRsbPLS7DNQJ39/1YLZ1LMIPsxAvqnpZUPA8fm8dFDegb A09w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/taNGTL0Bk/orbPV53RFeNYRuZyflPl+Jl6z3Lp4A18=; b=GYreuqj/XB8xGyitWUdTtCV/DoXM9s6+i4B+5yidDYdfBrOZlJR9nG+/lkALCEp+HX 93yQXrfz1B7UD7eAY4O44ykMjuyrSlR2x/B8okF3EsfmYRo2PayRUOXWy0v3bDWZ4MuP sY8ZG61t1qMSC313ChXIaRqpyzp8PJuZG+TkqM7OpbvXgAoOhC8qw84xROnZyyRjU3wQ jRMnmxfoEscb+Mlj3r8/J8cx1ICL6e6gNSQoKsK379WMwz5vEsY0Vq8XMXSSNIH1rjQV aaZujupFDbHVBxlcFaCXlMRZ7Wr6rIkXyQvkzjFL6ptFnWvzhnGI9DR8K7k/QFhzB30L n49Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=awBF4OX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn31-20020a1709070d1f00b006e840a5c05csi1364000ejc.918.2022.05.16.19.25.39; Mon, 16 May 2022 19:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=awBF4OX3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345516AbiEPTiT (ORCPT + 99 others); Mon, 16 May 2022 15:38:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345488AbiEPTiG (ORCPT ); Mon, 16 May 2022 15:38:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B4D93ED17; Mon, 16 May 2022 12:38:05 -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 98354614B6; Mon, 16 May 2022 19:38:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3BCFC385AA; Mon, 16 May 2022 19:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652729884; bh=VkPH2GOgvW0jX6lgRUV/1Nazd4OVVZfSwSr6lOBKaK0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awBF4OX3qtQDqYBs5sER4ecyV2/ul5W+kqOfiPyeA2kvZMSHYZcA/GYHPZU/rbsjd HeWR/dk2JOycWRIDrm1Mm8tx1ppXzRmBHA8MyHw1fYvIpYRe02Uw4TDI5u+hdHKDtC w6f3v5NjiPJO85Uk6FBfMLKohdCrwV0CnI/JgESo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Brown , Sasha Levin Subject: [PATCH 4.9 12/19] ASoC: ops: Validate input values in snd_soc_put_volsw_range() Date: Mon, 16 May 2022 21:36:25 +0200 Message-Id: <20220516193613.863630546@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193613.497233635@linuxfoundation.org> References: <20220516193613.497233635@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 74968ddee49f..90ba5521c189 100644 --- a/sound/soc/soc-ops.c +++ b/sound/soc/soc-ops.c @@ -528,7 +528,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; @@ -543,6 +551,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