Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2173086iof; Tue, 7 Jun 2022 22:09:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy12J2XZOM5O2Hw9U48BZzOahKAk648J6KqWg+i7oYyPGpcO36jCSdcrb+kHHscD7CZQQ3p X-Received: by 2002:a17:90a:17c9:b0:1e8:5e58:f658 with SMTP id q67-20020a17090a17c900b001e85e58f658mr21339430pja.239.1654664953116; Tue, 07 Jun 2022 22:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654664953; cv=none; d=google.com; s=arc-20160816; b=G7LryBZM2PRSU5J/oqrC01kATLf/53IgmZ/NajToqGzoTZ7cQ2NqWWJ2rK0rfvoLu/ 7Hykydj5l7X3E7o4Mk8bBJ4pDUxfyntluatXvgmZnfM9gjRQCxQHQIbkc79ky+qrtk7J IIQU0+Zg1qbsxWii09tQAgjbuOpbjKio+qZBg4N1DBsBbgsXuPXoj4wBkANznXds0VYR VPHVPUmxWgEz+bymamoQw+ayKkvGXM6YphY6STq48+UP6ejeDA6RZJLeAM1krs8UwBWW oNwdi6egbrguXcaXs4Es8vCPxY42gkFZj5E6JDeZiyrw3EV5+IFqQrCqNVTGeTkWq/jl J75g== 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=p1HZmaVb0zVVUixoGsl4mMYwkxwrFLZ1BsQcxddoopw=; b=RngeG+0+k+Wwy/9uYlI58y7aJsEVVnvQoMKbGeSho1u8t/j21amU5qW+r9C6yu37Kz qNYIHXDnFNxjShC6lx6tpp595HWNRaLLKa/lmPockyCJtuAyjRy6SPJxy8xWSrKp3VqN fMzF0WreizEVyB9H8dMYHnavR6Pd7FdJZI3XDhTtZk2yQKLZGWJo0ytAtgZTnqpaqM94 Lse8hrkIzXDUzl6CDVLLMlpVgPadlpI19x9izz9UFQ1OxTiSUm02Fla5GWx2Gik5EkGG 76ntlOErxk7OL+WxgN3hYPbNVwq/9Z0O5t9dyw8FTEdRM7SRofRRcmIpnWnFqKY8SqHg cCUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=iWaRnVCR; 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 e8-20020a656788000000b003fc57f211c0si27746252pgr.22.2022.06.07.22.09.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 22:09:13 -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=iWaRnVCR; 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 534BD2D89B2; Tue, 7 Jun 2022 21:40:25 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350195AbiFGRv5 (ORCPT + 99 others); Tue, 7 Jun 2022 13:51:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347584AbiFGRf0 (ORCPT ); Tue, 7 Jun 2022 13:35:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A5AD189; Tue, 7 Jun 2022 10:30:56 -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 0F068B822B4; Tue, 7 Jun 2022 17:30:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 698C7C385A5; Tue, 7 Jun 2022 17:30:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654623038; bh=QKHbAsvs05ymoaBVxoMJKqmHZ8l5en3w076iT945xkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iWaRnVCRxoLTKfCBZlk3LbrPjHfyJiITIBI+yr1f01ONy+F//jPwqngN4PU01r73a jFacV2BFwDPAasD0I9v7cPe/TflzUb+hP5ownL9D1xq/c8r+BtGI46ayE3U2Oryk82 8FZl/EZlbFt3ZlvEv4UIcewdgnURwPVRHAv2gOhI= 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.10 246/452] ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv() Date: Tue, 7 Jun 2022 19:01:43 +0200 Message-Id: <20220607164915.889662759@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@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 5b6405392f08..0c73979cad4a 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