Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2206348iof; Tue, 7 Jun 2022 23:11:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznIHDjjEO52l/Xr0sMrabrzkMQpu6UYf0dRRQ9vUzxZlcOTFn3bNJD+y145V+6r90FMBaI X-Received: by 2002:a17:903:2281:b0:167:56a9:935c with SMTP id b1-20020a170903228100b0016756a9935cmr22874036plh.27.1654668688520; Tue, 07 Jun 2022 23:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654668688; cv=none; d=google.com; s=arc-20160816; b=XY2TPyRVPJLFsHO7kobB0iOA6TDNAn3YQiSpkc3e6bRxSeUHWDhsKPorgDAfIYxPPv SCpri//Rzc+wK8a0xpgI6yMOB4qrSObaCNP6nTjfp7Tq5zBtdT3KqCsaGRB2tHvkZdNv oUmJG2FVDmYYe/nTzNlkMuMP9VSDynvZjGhxwp9bMwkc2K57EHwc9V9qHagYbO34WGjm lVeHCdrwKP9SPJvHGebj/VXPgw/BqErVYpOnCSSohjNs/dy1rhxg1sz7uPpSRGhxTxTt AhX2wsl3CFoBPjmNaSGvsJFcelkU5DVAEqtab6likJM0KPmnFVtVNEGCKp6z5I165n84 lKmA== 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=tck0fKnFuZKwbdsH4OzsJkFphYPp2o/IpCdq6/0248T9nJyjOl7AFmBxZB3xEKsTxQ zAW/3pIIklM+lEy6Qh1CaEg2EHKvBX1K76jshdQwYTwKld3KW1EeHA3V16mHQu0ejuV/ hIKmnRVd2ihwpjc/xHTxO5TSTh5KJRrWT+Kkz1hiB39kuo2xBGfaH5CXwhXCqwLoS2cT 0wQ8LxiLNRkj9jj3mapF53PPtS76vu0YEYjy8rWBk2lBCNsvcIRI36XYzEmnuibApizX dEV0sZ5/0sZuMoGudMZVYp5tMHZ34hKe9wvNlCFCvg3eiP4VU0LjiKIVnEgqDkagWEPb BiPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pEZlM2ce; 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 j70-20020a638b49000000b003fe2ae26681si1970058pge.109.2022.06.07.23.11.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 23:11:28 -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=pEZlM2ce; 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 396471E224E; Tue, 7 Jun 2022 22:33:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351286AbiFHBjx (ORCPT + 99 others); Tue, 7 Jun 2022 21:39:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383220AbiFGVwr (ORCPT ); Tue, 7 Jun 2022 17:52:47 -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 B39B32431A6; Tue, 7 Jun 2022 12:10:45 -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 3A410617D0; Tue, 7 Jun 2022 19:10:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 391A9C385A2; Tue, 7 Jun 2022 19:10:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654629044; bh=dJUCVa4nIa8YINdSoor1J/gc2l6XzUX9TFZT4NQvPgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEZlM2ceI6LteJexpDSdLlLsOGVjeB3ihvjUlu+opqlWiCFPgUsXzbtRss2an3463 +QcbTI5pgFTHkqctoH6nlwEKbzMTs+rffO//NQxMh+E8BuCSjzAt+65K9zVd19ucYB MTe3JTwCuGme+eKHGu8j2UF0kWL2+g75xUyX0igA= 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.18 508/879] ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv() Date: Tue, 7 Jun 2022 19:00:26 +0200 Message-Id: <20220607165017.620148269@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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