Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3342576iob; Mon, 16 May 2022 20:04:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK5tKxmEzgfFYIPtUpzHJdAA2jc2ZEgJlvLq4LfcNVY4CphVJYVzBQH9AUQoLH4rBXf3vf X-Received: by 2002:a17:90a:7e94:b0:1da:3b47:b00e with SMTP id j20-20020a17090a7e9400b001da3b47b00emr34661993pjl.222.1652756649246; Mon, 16 May 2022 20:04:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652756649; cv=none; d=google.com; s=arc-20160816; b=BnhTIeauPuNIIjz3sQ8St9OpxvLNciUqOJUc9d2G2nl2r9/7t7sesuyPKMcA/FxZJH avEESNMJ1BTsyAvp2PC3nAbGakKgvaFl7gnvDz+1jY5XNK7brexS1eayi66jk5KTeapO FUUBhcuocqUkTjZWXQHnhDrqC6unVMQbtDpZE1ryR9jwq0IcbWkLjBa8tDeCO0EM1kNc +xem9/olJvcH/21evV4LW5rlJnojfg7fV/sHTqfCQbqC8IJ6Pg1S/sDVu1MJRBrKUEZ0 B6kYx2O9g8PpHYMwI/qDvVeGRUE4TUZ4q1CDeD9XXWxgZ6tSNMG9hMWVLCRXoJYPwVqD vuZA== 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=JY7e/HKhTcrbLTw8RsYEVL5NsHlFHgwT54s46KWm9VI=; b=XVew/JLOx+hPTXkJEP6RiFYf2wWSX0BlrASDQHzbr/XgkK/LqVXo9tIqea1Ci8AK3v jYAqvrF0eynQt3HthGbehXUMIOGROUGfDQFvVSbWfMoQFuEo5Wb32R2xRnGx+C+I8DmL jd9vqsqoDfEOb8DZD3GIKDicxSBXHIHM0bXJkL66rs5qpXGMS9bv2E4WxhWcAFdsMdeY 87eJ4JyMP8D6/Pvl4ISjwFD4IZWz5Q6+pNNjpLJc3OHP2+qtvrO/nKBfKiuJJ/AJ5elp lSlUMpWvQW8nHnP7KQzAlRo2V3/SH+KmgdqslUHboauUW1yeap/Wuuq+jxs7BhPPUcLI FQZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wSnePpry; 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 gw19-20020a17090b0a5300b001d653c53a03si1491029pjb.11.2022.05.16.20.03.56; Mon, 16 May 2022 20:04:09 -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=wSnePpry; 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 S233061AbiEPToM (ORCPT + 99 others); Mon, 16 May 2022 15:44:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245560AbiEPTmp (ORCPT ); Mon, 16 May 2022 15:42:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1325F3E0DC; Mon, 16 May 2022 12:40:59 -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 9F3B36153A; Mon, 16 May 2022 19:40:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC341C385AA; Mon, 16 May 2022 19:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652730058; bh=FMJRUB1SG20TwFoKGF+M7aS86FGVewsJIqlGua4wN/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wSnePpryiouj0/Qz9rIFQOxjDfgKbGkh4Uq0dDkZXT26qQcTzCtKbMqwVteEFCHRd 4l8X6TjbXWAK3IjWmSVVWUKTzLolY8jZ1ncTHAIvH8TQwolG7rk6htZj9jvcZXtAS/ sVaS7cnd7nZKtRPAzP/i6JPmwt8Peezl67E/XUGc= 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.19 18/32] ASoC: ops: Validate input values in snd_soc_put_volsw_range() Date: Mon, 16 May 2022 21:36:32 +0200 Message-Id: <20220516193615.314822286@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220516193614.773450018@linuxfoundation.org> References: <20220516193614.773450018@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 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