Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4480403ivc; Tue, 3 Nov 2020 13:08:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwHCUoY58QjY4P9ALuZdEH+vNQG/hk9cJ6MEg/J28QbSlfBIRoxXuFoiktRg1xqQYjtNOF X-Received: by 2002:a50:cc86:: with SMTP id q6mr24693507edi.78.1604437715987; Tue, 03 Nov 2020 13:08:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437715; cv=none; d=google.com; s=arc-20160816; b=MRm2u6K0e2OFu7k2HQXOR1oDg9fZil0LBJKFcMZgfbGnEDRocOpGpuTFWINt+J6rG3 CS/seVswYdBen7tpns+nTRrMz/1gkWtPS4tb2k8xS75BWxT1g+kqBmV5gs5Qq24ql1hG HFFRzL+lzjxQ51P7yB5YQh4Ou9/1ph6VqnjhLIEoxEoOlMO9tD8gl29AWzXGCP9Gexez +BxMyfP9Q9CxZjJIU2jkOma5mU3kl/D1VNx9vFquOA8Wy6brMfFXrsftgMPKb8f2pswU 2pjRrEmCRysWPzdG3k3bpgZ7wM9u26sjL7HTIdiIjZAyxncSWZJj2Cl9znAyVJitWfqi jmag== 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=2YZFrCvqhIIiSS+w3QXKMs4/T3FONrCZo6X9GHEf0g4=; b=zEcB1jBiPfkZYl0C6z0iLlRMBQNbi+2btiAibumKHQWxbVEnAJg41a1oLlhPSyFYC0 nJb07QWxUNDt1maif7Cxu2FPpN+4edJhjofMqOK6bxANblHmav9u9lTyo8Iro3H826Uk xFEURlTpQT97tQLur+L1IGOECQiC6WT0acowkp94LbV5bMkwza37TZt5zTxHb74ET5Of 1cvKkqsHGzhJdNuAK4oMxa7SQVvLcsNMTm++w7Tp3wGRzGvgKijRUU9bZeCn8VeR76Lc KrIJ6xzS58T5h7yHcDGbAnGXmqrGOmktAWV+Sg3ggXzcw1d/4MA4+DqxVOBSVNc2Z+Ts XVYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TmrRdwTn; 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 x19si13631105edi.214.2020.11.03.13.08.12; Tue, 03 Nov 2020 13:08:35 -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=TmrRdwTn; 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 S1732105AbgKCVGz (ORCPT + 99 others); Tue, 3 Nov 2020 16:06:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:45910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388221AbgKCVGv (ORCPT ); Tue, 3 Nov 2020 16:06:51 -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 41B0B206B5; Tue, 3 Nov 2020 21:06:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437610; bh=XiOVlSx8Y8OV3R6NNOf+x3pi9FwzEiFGpXqenKISlFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TmrRdwTnkGV2f6Aq9LgT19qDgwBxTmFMldSCJEniTCAVEhXgU1lXHi1h3AZ1/bKKr +KpthjPuPdS9GcHavXjdo2YlRPhbiKpjYe/4e0FrWAkYQwn4Tsr62/D/JlBgjX82Fi BI5ZYdSx+qlhODAsSmrk7Z7r5r1EK21bwMmSC8+k= 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 4.19 150/191] iio:adc:ti-adc0832 Fix alignment issue with timestamp Date: Tue, 3 Nov 2020 21:37:22 +0100 Message-Id: <20201103203246.727251082@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 @@ -31,6 +31,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]; @@ -202,7 +208,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; @@ -220,10 +225,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);