Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2082694iob; Fri, 20 May 2022 01:15:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdVClwCeyih2A+KnngK+iWWnf6JROIloVG09NbiuWpuFkYfta2FslFaBcxD/NeytO82LKj X-Received: by 2002:a17:90b:2248:b0:1df:e20f:c63e with SMTP id hk8-20020a17090b224800b001dfe20fc63emr6000645pjb.16.1653034522326; Fri, 20 May 2022 01:15:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653034522; cv=none; d=google.com; s=arc-20160816; b=i1hnGowQAt5VGR1d9dQxjNSNHCqKAzWiKswo4qKpJCbQk0F7qO5cbf2+OYIL4jRM22 neiLq4Q2cT3PzENbsnSPDfIW1+sSh3dZS+y7xB1a3+ymSCxRfkzqVTLPzQEKArut86QJ 96W3rc9brR0n6s9bJ7GOBA0fxIlTRJzQX8OhOW/Ho+uRQ8chYOW4kAC4RmwU1IZaGlUD lJy+1+I88idsbKYum0iNpI77O43QZdCtJpj+SamAeOqJLAGNGfH+J9KRVmk0Sa/WjAof x6jsb0/c2VKEP64VXJA1y5O+z9nEljKFn/mwz9moD8XSnGUG/kFIDr28/LKwLNjo7wCi zvwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:message-id:date:subject:cc:to:from; bh=/kq73kHZQpTiE+yI4OzwUzcuug7jKkdv71P3dTH8XUQ=; b=Ddiia7UWlIzR4ULWxmuCDpmf0TTFwz1X62uaSfqc1ckND3h4bqdELQ6MsSSX43Vscz dHHpurISW4Aw1FiAegmRjr/gScWve9dvUYezSaABJJWBZtq+IdRxVBGblocv+hUv5h7Y S+jXNlRp7VwYKP+d5VgEjCNp9zOwqLX9ArBJwvqJn8mClyJUrB4fMaDDLOpmVttQIYaD QaoijLPML+RMIjUzTmF6UtVvKi5UuLTABO6d8ciobKV1ahzyDbNWA0nGnC7y/AhEt3D+ dV/+dpqeJ45hH8pCvOStDhW5VLXmI6qpYrbIXs8myZHOst1KpFHbK9zvCx7v5pZJAQTQ lRiA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a14-20020a170902ecce00b0015f4370e96fsi3057941plh.588.2022.05.20.01.15.09; Fri, 20 May 2022 01:15:22 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245492AbiESWcD (ORCPT + 99 others); Thu, 19 May 2022 18:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245475AbiESWb7 (ORCPT ); Thu, 19 May 2022 18:31:59 -0400 Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23256B2278 for ; Thu, 19 May 2022 15:31:58 -0700 (PDT) Received: from hednb3.Dlink (unknown [109.252.138.248]) by mail.ispras.ru (Postfix) with ESMTPSA id C7E0C40755E1; Thu, 19 May 2022 22:31:47 +0000 (UTC) From: Alexey Khoroshilov To: Liam Girdwood , Mark Brown Cc: Alexey Khoroshilov , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] ASoC: max98090: Move check for invalid values before casting in max98090_put_enab_tlv() Date: Fri, 20 May 2022 01:31:26 +0300 Message-Id: <1652999486-29653-1-git-send-email-khoroshilov@ispras.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 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()") --- 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.7.4