Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp823957pxb; Tue, 3 Nov 2020 13:34:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjb0g/lF4yQBUhFt+7UJJMxodRNGZqukdLauiwkfTxuYeXeK+vTRMauCR6VJ4cyWMpvK4V X-Received: by 2002:a17:906:2895:: with SMTP id o21mr23026570ejd.332.1604439287574; Tue, 03 Nov 2020 13:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439287; cv=none; d=google.com; s=arc-20160816; b=gLNVoaeDuvbjj97wPxCg7AgVwFwRIARnjXNduYPXFaFboSO9LfhXN8KmOMu1vjVq0e jbXV6b8yhrRQ/S9WTvh7QBu+nnbeAHUGJYTwX3WEEtMNPpUfyZBPu0bqR7pXsIGjm70J gdHcfcEhJ00cqyIDDL6yGP/i71zCNSaOEDUYhF/Xz3TYtutunrqeVrAKqHUQCb8bFcPl OURvxXvFB5Ycbycv5Ax4vegNUW6VmO0iYl3Kow8wCCjGQ35lGIdsfRNn92E0Q77jPkNA OFIYqJNbt/XYS6ZmnYz/pbq2A7YHSTFiIhbUysHB+KmQUontMh7CZdtRCsdsBSCtBlGl 0Tjg== 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=vTEh11DdEXvHcZzWP6sHhL77xiEy0Kg1M6lKSgeibI4=; b=v+YQnHFrdWx1wQOr6t8DPS6DscWwNXjmRlQ5i6jrmO37tA4iUoUuPleTlDKLG9OSm2 kxVBNm7mb0naJ1KgzzsLJJCcnq4lB7n+D4zwQtgXSj2Oa0O11eXwSGavShYgBPewnsl5 ZXSu4WJx9XWPU+19euLW/xwy9An09R0FOWkVY4mqo+YexqIfoFLfXxAQR3Lchy/+FJIC myHI6wlD4jftPpxmsyflu79VtTi/3T3qOES1+nBNZDpzVttRMfj9J8PhEAC/tw9ZxVKU Gh/H+F3rgXe02I61yvA7x7UO5v+Y3uB2+8gphnlvpadztlRQ/u2PbHG0s391gHTQskVH QJGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=S4RetmfZ; 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 u19si36061ejx.98.2020.11.03.13.34.24; Tue, 03 Nov 2020 13:34:47 -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=S4RetmfZ; 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 S1733021AbgKCV3y (ORCPT + 99 others); Tue, 3 Nov 2020 16:29:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:33232 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732239AbgKCU6j (ORCPT ); Tue, 3 Nov 2020 15:58:39 -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 70FE92053B; Tue, 3 Nov 2020 20:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437118; bh=V6YAqLlPazLFt0SqEKR9ID7rLQepHXZAToxSoBQElGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S4RetmfZVo4LvXt8rgXxWQDZBQxQQpzwLlrrW5Iot1MUiwRlyv3A2n8Ry0T9Hhjo4 CYaeAvO3+Pv0BDk5HYpg1YloUU/4BlM6q6coUWIsKiCdr6jqjLVHWpG8NdBxDH79X4 kUkzE0TUhXJGdY90tjmBpbtfcmIqNOHE3/4lN4Gg= 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.4 152/214] iio:adc:ti-adc0832 Fix alignment issue with timestamp Date: Tue, 3 Nov 2020 21:36:40 +0100 Message-Id: <20201103203305.031549466@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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 39e91f3be4cba51c1560bcda3a343ed1f64dc916 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 fix this issues by moving 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 data could leak 'including' previous readings but I don't think it is an issue to potentially leak them like this now does. In this case the postioning of the timestamp is depends on what other channels are enabled. As such we cannot use a structure to make the alignment explicit as it would be missleading by suggesting only one possible location for the timestamp. Fixes: 815bbc87462a ("iio: ti-adc0832: add triggered buffer support") 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-25-jic23@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/ti-adc0832.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/drivers/iio/adc/ti-adc0832.c +++ b/drivers/iio/adc/ti-adc0832.c @@ -28,6 +28,12 @@ struct adc0832 { struct regulator *reg; struct mutex lock; u8 mux_bits; + /* + * Max size needed: 16x 1 byte ADC data + 8 bytes timestamp + * May be shorter if not all channels are enabled subject + * to the timestamp remaining 8 byte aligned. + */ + u8 data[24] __aligned(8); u8 tx_buf[2] ____cacheline_aligned; u8 rx_buf[2]; @@ -199,7 +205,6 @@ static irqreturn_t adc0832_trigger_handl struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct adc0832 *adc = iio_priv(indio_dev); - u8 data[24] = { }; /* 16x 1 byte ADC data + 8 bytes timestamp */ int scan_index; int i = 0; @@ -217,10 +222,10 @@ static irqreturn_t adc0832_trigger_handl goto out; } - data[i] = ret; + adc->data[i] = ret; i++; } - 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);