Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3117413pxm; Mon, 28 Feb 2022 12:23:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJydA+CBCyB2F727tCmmfHUFcuXkk8W3OiaFp2b59u/j0QnyPkojTvOSzYgMm8CHuXl5GLnY X-Received: by 2002:a17:902:a982:b0:14f:f55:a09a with SMTP id bh2-20020a170902a98200b0014f0f55a09amr21903469plb.33.1646079792784; Mon, 28 Feb 2022 12:23:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079792; cv=none; d=google.com; s=arc-20160816; b=p9taxGvNsYJKRuEocDKuIZXEVFjz31rON+2UPlFNdo30F2/qmGqRHC72K9y1kBGrAg STgVrWUzlg/INZS4CCJpJMcN+LE7+D5FfYpjl4y9sEbLnNyr+HJjZoe8opudSeonwuLT hawzkvpPYNVtLoizewhqZYqjUdoWYdG459VoZ78NjYqRTpekIekzE2zxKqqshcfyW+AM Cbgs02Cn80+h2+G5QovxBfWbuOWvZagrjrfewkZNl91Wpi8zTGUjWpaPgPYw+B/8nXhQ /BS5qlmignxtU5FvuZLTZwCKW9DjF/JwwkQ+lL+jvc6GMi8NXehLSd+EFv1uiDszj2sh /EZw== 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=j6bXvHaJwyhlaX7R06QXhfDNVGgnbZ5c3Id2JkNCk70=; b=bJXBeQvY6qdeSivMgCiNTmKlzVbp9REqQrBtPdl7lzqmEBYS7LUMopleMWhZ7YTBQF 5w699Y6tj1nidnRCYjByDDj07Fa3TKXFWOZiURo4DxRehNGeOJx9anaSJArWDwqBvfFV 2MTOl3Epy4hVEU821d/CbjaQzqVKqq/QqHRkj2Q9926npJiroBbFM2S5Uxv6zNB1SPwk h8RJnHG+rNULCSBXc6Km72jQo2SRPIrkbEiDasPSspEBlzPe3vkvTizZ3YuQuGHF1DV/ 5cTJA/jeRYCDbIBNA7u5F0sPKS7iIok4nf1ZvU6JzxvuhhOxwwpEK5KKG8Y3lCurrFnq fVsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1a1n9ZGU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id f2-20020a056a00238200b004e19ffcc192si10606536pfc.281.2022.02.28.12.23.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:23:12 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1a1n9ZGU; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 5DB1F1CC7E5; Mon, 28 Feb 2022 11:42:23 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232542AbiB1SKj (ORCPT + 99 others); Mon, 28 Feb 2022 13:10:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240819AbiB1SEH (ORCPT ); Mon, 28 Feb 2022 13:04:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2252AF3; Mon, 28 Feb 2022 09:47:37 -0800 (PST) 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 DCCB260180; Mon, 28 Feb 2022 17:47:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF491C340E7; Mon, 28 Feb 2022 17:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070456; bh=Ig6iiXM5kdjbiATJC7zMaVmkMdHlc7IqYSCKrSrGdak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1a1n9ZGUglSS3Fj9wM3sblfGm2KWvoIAA+/mPeZ2fxgm1ooTzYlVoBTIm7rKiOlZI c1uUNDfffFdqmx65Olnvc7tMdYtHP2pjqlKUhWP8AoAO8OcTyDwvGQCTxCo2H/Yrav WnVHwXSLJey5YpsAAaUiq9U2Dlh5+Ngo+nHWi28I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksij Rempel , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.16 116/164] iio: adc: tsc2046: fix memory corruption by preventing array overflow Date: Mon, 28 Feb 2022 18:24:38 +0100 Message-Id: <20220228172410.894334670@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@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=-2.4 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: Oleksij Rempel commit b7a78a8adaa8849c02f174d707aead0f85dca0da upstream. On one side we have indio_dev->num_channels includes all physical channels + timestamp channel. On other side we have an array allocated only for physical channels. So, fix memory corruption by ARRAY_SIZE() instead of num_channels variable. Note the first case is a cleanup rather than a fix as the software timestamp channel bit in active_scanmask is never set by the IIO core. Fixes: 9374e8f5a38d ("iio: adc: add ADC driver for the TI TSC2046 controller") Signed-off-by: Oleksij Rempel Link: https://lore.kernel.org/r/20220107081401.2816357-1-o.rempel@pengutronix.de Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ti-tsc2046.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/iio/adc/ti-tsc2046.c +++ b/drivers/iio/adc/ti-tsc2046.c @@ -388,7 +388,7 @@ static int tsc2046_adc_update_scan_mode( mutex_lock(&priv->slock); size = 0; - for_each_set_bit(ch_idx, active_scan_mask, indio_dev->num_channels) { + for_each_set_bit(ch_idx, active_scan_mask, ARRAY_SIZE(priv->l)) { size += tsc2046_adc_group_set_layout(priv, group, ch_idx); tsc2046_adc_group_set_cmd(priv, group, ch_idx); group++; @@ -548,7 +548,7 @@ static int tsc2046_adc_setup_spi_msg(str * enabled. */ size = 0; - for (ch_idx = 0; ch_idx < priv->dcfg->num_channels; ch_idx++) + for (ch_idx = 0; ch_idx < ARRAY_SIZE(priv->l); ch_idx++) size += tsc2046_adc_group_set_layout(priv, ch_idx, ch_idx); priv->tx = devm_kzalloc(&priv->spi->dev, size, GFP_KERNEL);