From patchwork Mon Nov 9 12:54:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 320908 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1715875ilc; Mon, 9 Nov 2020 05:04:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyjDyFxxrWnIWL67pCFNUPtQtSnJ8KnQGhiNXOxq1ATQeDCdtI+QkeaDHGr6V733gscabjk X-Received: by 2002:aa7:d94c:: with SMTP id l12mr15633663eds.355.1604927045500; Mon, 09 Nov 2020 05:04:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604927045; cv=none; d=google.com; s=arc-20160816; b=lYYHDoaKfeTNqkXs44dH2AF1A9YFDmKTLJiPkyMYoHJcDl6RGUaHfGAWEphRkhr+Sd PWO9BR/co2Lgk39YDkI2i6Ar+iaH3ECEmt25eV4r0AXGLzDYcPD/4pP0QABQ5OU8Ilil fKOeQ4PnwSacqQRaXu5tcnO41p4EObqpq2qJ792E9/s1ARvupslGQSCzM6uRoADzuDvX vscKOR254WaSGMAcwIfw8Bc0DafJvB1vSaHm08FRgvYrxAE72+rgae9ovcayItNH9zyS wSzZ3+5Y3e3V+9laD2VD0OqfQZbttioZOub4ie0+iMf7or1pg/XL05F81M0YS6S6TfW+ 1/Yg== 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=qDDh9dxWaRkQCl0oA00hUg244dO/aVqYgOXaZIUA84I=; b=NZbzbNjoBSNRD88WjBbDJg4fQien9SeydiTprRKKh0Ir3RunPKP/+oRp/VuV2Qrhe/ 97fseIHB+czkXBmbLyg08AgjVOFNe8Uyz1bXeVCVWtISZRdabn4oeADShb1ovXkRsVbA rzIjv2hZ+erw96dGvcso6SIJWtl97pNx0xlGFM1rJk/rUwabTOaIk9qV2GAm+wyCytlu n8O7WEfy+jQ7JUkpPICQw2idiAWRjqsfsEmK9sehDP5uVl0anPHZgueYOOD1bW3Fpolj WnO+3wYZ1w+bgb6PsDQ8MWH6COGB4AWZEzWuUOP24xo/EFCfoTsblOkvKdVzAoe4tPaS 71lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=t1YVHJUM; 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 r11si6925951edi.555.2020.11.09.05.04.05; Mon, 09 Nov 2020 05:04:05 -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=t1YVHJUM; 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 S1730210AbgKINDu (ORCPT + 15 others); Mon, 9 Nov 2020 08:03:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:56492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730636AbgKINCz (ORCPT ); Mon, 9 Nov 2020 08:02:55 -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 9334722201; Mon, 9 Nov 2020 13:02:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926974; bh=Sc22hHC5x/A69Ljw+UA6/Br5HDR8C/JbPvO9urOWKV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t1YVHJUMj5MbrZwsqypRQAYZ44oLYIdeyIcZg+FrZGPKhbQPSS9VGah46k+sv+YP6 7VszA6RVy8vWgU2CSaIyMsbP9TAb5s83Zql8rA6OwDKTKnQUAlqaOiZRGi+HwLTYnl 2PEpz5JWeI4Ai8DPz1VEOmWUSyaqCFkNnshUKZ24= 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.9 067/117] iio:adc:ti-adc12138 Fix alignment issue with timestamp Date: Mon, 9 Nov 2020 13:54:53 +0100 Message-Id: <20201109125028.851411094@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125025.630721781@linuxfoundation.org> References: <20201109125025.630721781@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 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 @@ -50,6 +50,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]; @@ -333,7 +339,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; @@ -349,7 +354,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"); @@ -366,7 +371,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"); @@ -374,7 +379,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);