Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3117858pxm; Mon, 28 Feb 2022 12:23:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCs1eCZiBAroZ9x/JNRk8Sw+VqTf/TcloIw1fSWh5/6Vzsy/rcIvnS4DpJK+YdVECmIY9P X-Received: by 2002:a63:4d60:0:b0:36c:8803:b92d with SMTP id n32-20020a634d60000000b0036c8803b92dmr18704139pgl.179.1646079827808; Mon, 28 Feb 2022 12:23:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079827; cv=none; d=google.com; s=arc-20160816; b=i+18al8Kx3dBnUsdh1k4RK1qfIBAp/WKfp0sVw0GB65uM4PZIH3/uLkrECH21QaFK2 195i9q4asMX/7/IBjFlM+T3iHo6FmoehkCudkecq98nOcU3qvqHUdUcKwSSbk3vu1AsE DeaTJXlZC1paC8NPIUlJt9jmYhXVFlE0ODyBDzr3xmVXuHoYBD7NkfSNtyCvdIKczqxk /FN+/BvhKI06xE9wvjIwt82SfVbfuMNPCOXvWgeYvddrz/cGY3UhzR71C1RCCfx2V+Ey s/Fnnb380JlfgEdwDGmZ4r5cCqjJzeptTVmLu5G8iqgCt9RotCwmQ4zUvoxvKUJ5N0/t Fivg== 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=vTMFSWxFdIbzgvjVJYJpCUpNpED6cfw3Y7HgKQu/1ls=; b=zdbv/yuBpD81Jwsa9bLFTmU6NwWkjaLtcHNrm8AHn6kxzaj0t/p91P5UFblxpkiB8d W4r1gezeW9mZd85kFsTYSn5/rYhB6yL10BLKjsFxcw4R08hXNORYxagngfxkj+6eKGOQ +G0mg5jPcrwkzoFwBitHYg6URz6Tt74fz5L+euGtbFmCnKA4Iq4+gU25geFNJsp0IST7 ZyBfxceBGekmbbqG3djfVD0XA4v81WeCKECc+Ua0CJmHVrfAu+uxaqLnXpMYf01wlQV+ mYEgzRhHR/U5LHn9KKiPqcuTH/eOAUA+8VTZbiOVUdSq+p7X4NKC7nHRaS82NEC7FJau cQsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vEKpcRkY; 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 b14-20020a170902d50e00b00150948d9c1esi10906598plg.109.2022.02.28.12.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:23:47 -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=vEKpcRkY; 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 A4CAB1D638B; Mon, 28 Feb 2022 11:42:49 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240786AbiB1SED (ORCPT + 99 others); Mon, 28 Feb 2022 13:04:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239468AbiB1RxF (ORCPT ); Mon, 28 Feb 2022 12:53:05 -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 9DB8DA996B; Mon, 28 Feb 2022 09:40:23 -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 0FFB26154F; Mon, 28 Feb 2022 17:40:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 187C8C340E7; Mon, 28 Feb 2022 17:40:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070022; bh=kcKxsW8Q8xpBHWLZSMDqe7m3Do9CkKyNlANTKWSkuSE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vEKpcRkYJWsIklHQxRVDeHOXXg0DlbIAmkQ6e30SFDHEm9d5tpTwCWOnglEBkaVRw IGnxbLYNFONushT/QUGQ9f7wssKQCFjrZhc59+S2q7xAtgNWZZc/mob8lstb6w8P8V lEA8xKr2vqDBbeAebEaQ5Q9OeTHEJhByaO2EXrwM= 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.15 098/139] iio: adc: tsc2046: fix memory corruption by preventing array overflow Date: Mon, 28 Feb 2022 18:24:32 +0100 Message-Id: <20220228172357.946505749@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172347.614588246@linuxfoundation.org> References: <20220228172347.614588246@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(-) diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c index d84ae6b008c1..e8fc4d01f30b 100644 --- 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(struct iio_dev *indio_dev, 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(struct tsc2046_adc_priv *priv) * 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); -- 2.35.1