From patchwork Tue Nov 3 20:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 320482 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4926234ilc; Tue, 3 Nov 2020 13:29:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHU0uU19EuDpFBkyU4mZOh8jcwfntZzRL1jJeqyPrt4vLxzCTzK8i4keektCOhag5ofjhN X-Received: by 2002:a50:b023:: with SMTP id i32mr23104869edd.357.1604438998879; Tue, 03 Nov 2020 13:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438998; cv=none; d=google.com; s=arc-20160816; b=PWxnd0hz7u7FDWVJJYY8FB9RqqlmyLTlp9diPfF3CLATwMqhgueCPWtKsz0Kz3EpJZ 0fqjkwq2wtnEFbFX9fVfDV4gwKruOJDf4Ibb58oLdhK24g7BZBtNMob7n91EMKdeBZ8X 6LZ8D0ap1f7a5S1B/TJvAs7THiDWSQK/l7WTnZ4Iqvi+gBIg//0kJu/tO2wVmJSknaAG rItpteDrkyRHGZSugo15dVgMW7yMTR4w+icvXdBCf4vwbnfayoTv7loBJk+iZx0mPibV z0Yzkj4ELavtBpSdmOdf5AuEB69EgyQwaFXWaTW2GYeCoXuRn+rtXZGEJ/q0bwRBMBDq HZWA== 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=M41ftyjQquEEp/roBI4To1EOyqr1XqcyzLkLvsADmL9WioUMStOFE8fgVRc4ifVtM/ tZe8xRiqfGBaefm1MNclwB30RekrA6MsR3BTgZX7T2AlHr6wzgQtgNON82qknwEjRchp R8bnAoPQ0g+FRM+XBmr2EU+oAsrsYn06uAAfcuYXN73CIX0fSbCITK9tE9Zz2W4Coy4s 3LS4YySls2X5IHBKEyQNzdgmUf7gXmyfrKA1X+bFSsZGOj75BAXEP5Ko0Gv7CYHX14BE fHymSos+t/5OKBzSgBznrqfHd8C40LiRwx2G0+asLavT5Ej3VR9OculEAvw4+NgPZ4sG rJZg== 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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 o22si73024ejd.340.2020.11.03.13.29.58; Tue, 03 Nov 2020 13:29:58 -0800 (PST) Received-SPF: pass (google.com: domain of stable-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 stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1730265AbgKCV3x (ORCPT + 15 others); Tue, 3 Nov 2020 16:29:53 -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 Precedence: bulk List-ID: X-Mailing-List: stable@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);