Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp834107pxb; Tue, 3 Nov 2020 13:54:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJyJIwBFKtVjiizyTiQuuTY2fDC+n7DmcVkcx+cLsWLKWNfPfIJfImoO6cnibsv0p5/irViM X-Received: by 2002:a17:906:c43:: with SMTP id t3mr21483738ejf.219.1604440453018; Tue, 03 Nov 2020 13:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604440453; cv=none; d=google.com; s=arc-20160816; b=VeprTIBxBZokJyivBHMXuVNqApih0fsK40LwM6yoCKbUGrVtxDfIPYM2oVdrzO2r8H 9ql/lbFq6ahgue2jgp0XixW7d69iKaVLQA746y6Q5zelC2bGYZmDbbht3/Z+BrBXRLr7 LpRRXz1xYxebIm8vvGd5IoRWidUFFia/DDgCkRZ3dNhF6N95THOxZrKVZkaI3UqHodwr oPu6/NyWhzrFK9pDc3dIw9eep6E9G2jMy2fxVLzXhBDVFnKW8f+58cpPVNzlqSmm5/wd 4h1gmGf4cizufgyseG8F6141W0FLqe6EmRmd43XlYxTVYcv7YwKfI1ADKreroNfnpJV8 Q8hg== 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=6nw8xFIk5vFvt5YOTaK3X+v6PnG0arCAN7ymVPn1j/I=; b=eSd1MQPKKd7P+eCwPvA+t8NQKNJbEcWV33UO2xfQj98XhqCT3B0yKTsn5opzza5GND C/dTBv2wf9MfO+FNvNvnzrC1JtDiHG9AMxWzOwN/dnBbkyEqQox1hsvAu8v3Yr6ZA3lR WnCBWDShAeoO8q+M2U7zdpaXkG4p0tFsNYa0UOy6QMx/loyJ7Cm9B3nhkguUnyc1Fsjf 1JhKSnrz2Bvhd4zLIcpLaS/5erSyej3mjnFZ/8bmsIKPHx0esOwmiVmmkRO+LRQzrs0e OBtO6je5G68RtZFqEXtnAQ9rvQVIs2G7hwt3/ka9V42DpOyH8tN1AEnx353BSuUyhTvS 8O5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="CZfqkT/d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si43296eje.464.2020.11.03.13.53.49; Tue, 03 Nov 2020 13:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="CZfqkT/d"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731449AbgKCVvq (ORCPT + 99 others); Tue, 3 Nov 2020 16:51:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:39592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731429AbgKCUsR (ORCPT ); Tue, 3 Nov 2020 15:48:17 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 01F75223FD; Tue, 3 Nov 2020 20:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436496; bh=3iK3aVReR0jqP67eQryy4jne8FcaTAU+6QLhdiub758=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZfqkT/dRNvjBjhKZCauEZ7tJKphRoS73N9OhhtzflKQhpnYqK+8MtUIEHvRPGlC2 hSuf2mdR0EokkOrnllysIZdmkYnZaTcojQY/ucJgemJXfiPGDCV464S0u5UIhsAIYA 5/2v6mBFA/GDG34ryXRJTyQK2lh4jmI99s/Hf/xY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lars-Peter Clausen , Jonathan Cameron , Andy Shevchenko , Akinobu Mita , Stable@vger.kernel.org Subject: [PATCH 5.9 276/391] iio:adc:ti-adc12138 Fix alignment issue with timestamp Date: Tue, 3 Nov 2020 21:35:27 +0100 Message-Id: <20201103203405.656037560@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jonathan Cameron commit 293e809b2e8e608b65a949101aaf7c0bd1224247 upstream. One of a class of bugs pointed out by Lars in a recent review. iio_push_to_buffers_with_timestamp assumes the buffer used is aligned to the size of the timestamp (8 bytes). This is not guaranteed in this driver which uses an array of smaller elements on the stack. We move to a suitable structure in the iio_priv() data with alignment explicitly requested. This data is allocated with kzalloc so no data can leak apart from previous readings. Note that previously no leak at all could occur, but previous readings should never be a problem. In this case the timestamp location depends on what other channels are enabled. As such we can't use a structure without misleading by suggesting only one possible timestamp location. Fixes: 50a6edb1b6e0 ("iio: adc: add ADC12130/ADC12132/ADC12138 ADC driver") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Akinobu Mita Cc: Link: https://lore.kernel.org/r/20200722155103.979802-26-jic23@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ti-adc12138.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/drivers/iio/adc/ti-adc12138.c +++ b/drivers/iio/adc/ti-adc12138.c @@ -47,6 +47,12 @@ struct adc12138 { struct completion complete; /* The number of cclk periods for the S/H's acquisition time */ unsigned int acquisition_time; + /* + * Maximum size needed: 16x 2 bytes ADC data + 8 bytes timestamp. + * Less may be need if not all channels are enabled, as long as + * the 8 byte alignment of the timestamp is maintained. + */ + __be16 data[20] __aligned(8); u8 tx_buf[2] ____cacheline_aligned; u8 rx_buf[2]; @@ -329,7 +335,6 @@ static irqreturn_t adc12138_trigger_hand struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adc12138 *adc = iio_priv(indio_dev); - __be16 data[20] = { }; /* 16x 2 bytes ADC data + 8 bytes timestamp */ __be16 trash; int ret; int scan_index; @@ -345,7 +350,7 @@ static irqreturn_t adc12138_trigger_hand reinit_completion(&adc->complete); ret = adc12138_start_and_read_conv(adc, scan_chan, - i ? &data[i - 1] : &trash); + i ? &adc->data[i - 1] : &trash); if (ret) { dev_warn(&adc->spi->dev, "failed to start conversion\n"); @@ -362,7 +367,7 @@ static irqreturn_t adc12138_trigger_hand } if (i) { - ret = adc12138_read_conv_data(adc, &data[i - 1]); + ret = adc12138_read_conv_data(adc, &adc->data[i - 1]); if (ret) { dev_warn(&adc->spi->dev, "failed to get conversion data\n"); @@ -370,7 +375,7 @@ static irqreturn_t adc12138_trigger_hand } } - iio_push_to_buffers_with_timestamp(indio_dev, data, + iio_push_to_buffers_with_timestamp(indio_dev, adc->data, iio_get_time_ns(indio_dev)); out: mutex_unlock(&adc->lock);