Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2185626iof; Tue, 7 Jun 2022 22:32:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvdMdbLH9QUA0CnSt4ea6L1O4jwwUOF56LgQT3dF9PNTh57QYmqIrUEBvmfACm40M4LZso X-Received: by 2002:a17:90a:bc98:b0:1e8:6895:645e with SMTP id x24-20020a17090abc9800b001e86895645emr19957220pjr.131.1654666324013; Tue, 07 Jun 2022 22:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654666324; cv=none; d=google.com; s=arc-20160816; b=Cc8pUZQj+r06QR4p/D+sWyAK64UMIlky/ldKSxn+VIkL1Jd+ZENjdajCSo0kE4k8jv CALfxn+DvzioZUNDZ0en+L7FgSV/ODxkWf7/mfkFUaY4XSDZu+OFm5TB/X0IE03Z2KF1 oMDqoqMkUjlGZ2wwhhrU6WLYwwQzrMT6rK7a+8lcErwxLTEY4KVPjXzPG2W/h8P3VJnS e3xUZGkUk2hNcJ284hJMt+PZVKM2yuwcbFzOcwcBGzFkeJdk8ULnPXPdlku3G4nqiFGy C+yg2q2S4IsoFfmPwofFyq0x5qrIzNuttE7sqhA3HTDRWHTFz9dIvVQ/WhOp3Si9ywob vrSA== 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=ikSv/udcSBE5HzLYCLlbzADpHTjdMpHin85nse5OSNM=; b=jDKLP3mIWKsigHMqZx/Deh63/PwyiyCVYL0SMjfxpAcNbgI9WyOYfozn2XAhYELioQ r79siXGywiNsqcElG2crBo+RGMls1jjc/INJ6TfQZwPiIpWPAR7NsjhXjPx+1V/9EOLQ +Lq/j8JVC2BzvYpEcH548VM0NrVjC0nXFCyTSyeaZ/VKviAEfVXsT5MTQPQy6GSXnYsC GVS7yS2vKBZBMsMW24Y42abGhrqK6jN9cmUPOfLHuD+EPxwmOz/pR7FwVOpFqec9kJBs 8NWZsjc/6+XjZpbyW0B18+rpdNtJyVRjuguGLT6bzbvG9rDZNpgJVZRYT29ApfMqNSUJ WRvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gGBcaAcT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u144-20020a627996000000b005188ba74699si18319498pfc.196.2022.06.07.22.32.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:32:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gGBcaAcT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 95664259101; Tue, 7 Jun 2022 21:59:08 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376303AbiFGVS3 (ORCPT + 99 others); Tue, 7 Jun 2022 17:18:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359203AbiFGUWL (ORCPT ); Tue, 7 Jun 2022 16:22:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 091AD1451FD; Tue, 7 Jun 2022 11:31:26 -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 97FC461295; Tue, 7 Jun 2022 18:31:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4232C385A5; Tue, 7 Jun 2022 18:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654626685; bh=dJUCVa4nIa8YINdSoor1J/gc2l6XzUX9TFZT4NQvPgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gGBcaAcT52IwaiFpdplmUD7TZPpWKAk3cG7lQtl4qcJ4NkqQq3bqaB5W3r8rvoPzv MHQRNqMwz3jmCNISdT8scqtrRNj6XB6hq1u9+p//p6MUyxrU8eQxEV21iGZ/EjUcA4 r5U667Xv3skpMKnWKoraK855RWJLijqkn+181UGo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexey Khoroshilov , Mark Brown , Sasha Levin Subject: [PATCH 5.17 430/772] ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv() Date: Tue, 7 Jun 2022 19:00:22 +0200 Message-Id: <20220607165001.673831982@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164948.980838585@linuxfoundation.org> References: <20220607164948.980838585@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Alexey Khoroshilov [ Upstream commit f7a344468105ef8c54086dfdc800e6f5a8417d3e ] Validation of signed input should be done before casting to unsigned int. Found by Linux Verification Center (linuxtesting.org) with SVACE. Signed-off-by: Alexey Khoroshilov Suggested-by: Mark Brown Fixes: 2fbe467bcbfc ("ASoC: max98090: Reject invalid values in custom control put()") Link: https://lore.kernel.org/r/1652999486-29653-1-git-send-email-khoroshilov@ispras.ru Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/codecs/max98090.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c index 62b41ca050a2..5513acd360b8 100644 --- a/sound/soc/codecs/max98090.c +++ b/sound/soc/codecs/max98090.c @@ -393,7 +393,8 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *kcontrol, struct soc_mixer_control *mc = (struct soc_mixer_control *)kcontrol->private_value; unsigned int mask = (1 << fls(mc->max)) - 1; - unsigned int sel = ucontrol->value.integer.value[0]; + int sel_unchecked = ucontrol->value.integer.value[0]; + unsigned int sel; unsigned int val = snd_soc_component_read(component, mc->reg); unsigned int *select; @@ -413,8 +414,9 @@ static int max98090_put_enab_tlv(struct snd_kcontrol *kcontrol, val = (val >> mc->shift) & mask; - if (sel < 0 || sel > mc->max) + if (sel_unchecked < 0 || sel_unchecked > mc->max) return -EINVAL; + sel = sel_unchecked; *select = sel; -- 2.35.1