Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp798723pxb; Tue, 3 Nov 2020 12:51:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzmZfSk4yl+jYTKOsMsWc50m0tkY5rCnwDdXnsCLdek95VathyRvYfX5a6HYTliBomkS0DK X-Received: by 2002:a05:6402:384:: with SMTP id o4mr23692574edv.387.1604436682749; Tue, 03 Nov 2020 12:51:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604436682; cv=none; d=google.com; s=arc-20160816; b=cOZy6gz7w7L+JLqfr6LOTaa/b5mBsU5YNfihlsDi2CV5fpQsZ6cU6bx+eZwazd66IH cLS0k1Mj39P9S2lsIMGNSyawrbb7czFzFqcrhpfEWMujF4jNAfmy0EzGyRTApW5hQ/TS nAI3v18Y3kzA3AF/0R8T1ieLR8oiVrdQsAgsNthSqa9Ss+YNx20cHyjOmBJdhvDxaf61 MKz4ADViviPBeaD/BPPoEwg/2WkdGV6lS9c4qr8r/HU7JAUJuOwA/L6xRHbA9W6O5CQy xuPzzc8L7GQd5vUw6qM+Cp6X41dlFi3aDUxzUTmqnPcYUSmG2AcEn6hq8+tAc+KRpsqR TyLw== 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=s4jLfAgQlpNdzRvXLo6OqOUJOTM+EEJWktN83Ei0xZs=; b=IaT2LpzSlO4GYNUCpIVI5hxX2H5Qm1Q7yeN7UoAe5tSGPle3mgk5PJ1B5ksVIIHduz 7TsWv6klMqAgPYh6mp9ZAU1gD+RkmJmMA0lNdCiQ/95arfaCwG9hPUrU/sYpNOL3F25l DaWE0nnozbqv1OHvER5WZLoqUU9jSzW7AA07EduwDCGQDCUkkAZVnlkrNlcafabsSiWS 0r4JqPzO1Ul4tyyoBVvD6fC8zhrd5/NFqGpFWrEBcF6zIDRGjIj7pUJNmBa07sBtXNzf lNrTBs4aNIPKiEQCts1utmoPHpWrTOiPgHjPrmEe4q9+/oWoQOkqVrTchH6mUezaMzjw 7ndA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dQZ3GZLF; 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 n19si6421409edv.187.2020.11.03.12.50.58; Tue, 03 Nov 2020 12:51:22 -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=dQZ3GZLF; 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 S1730623AbgKCUsX (ORCPT + 99 others); Tue, 3 Nov 2020 15:48:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:39512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730939AbgKCUsP (ORCPT ); Tue, 3 Nov 2020 15:48:15 -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 A657822404; Tue, 3 Nov 2020 20:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436494; bh=6vVmg3mlLxR8JHlkwdguL7E9lQ8xkByZgivSNyoBnTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dQZ3GZLFJPS7f+itK5hcTLK2KkELJHpOOhIhbzFd1BLIU+2AZl14k1PM0xFf8pdu3 suWV39Rx6m2EuC5+F2YZb8NUf1jfyO9gTyCG/IIWM7CWv1LOpYe2Fb3xjUVQWUf8J4 nE7J18kO+6OuyVnBrsOSY85qjt1hNVZ3x5zVIKGA= 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 275/391] iio:adc:ti-adc0832 Fix alignment issue with timestamp Date: Tue, 3 Nov 2020 21:35:26 +0100 Message-Id: <20201103203405.588821771@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 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 @@ -29,6 +29,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]; @@ -200,7 +206,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; @@ -218,10 +223,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);