From patchwork Mon Nov 9 12:54:52 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: 320924 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp1746530ilc; Mon, 9 Nov 2020 05:45:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVVPPafCFhTonDVlOJXxUK/O57UiLvheWyGtlxi1ZHTSXqjBeyBOfzC1eYt3VgWGkFqcqS X-Received: by 2002:a05:6402:a53:: with SMTP id bt19mr15285216edb.26.1604929526850; Mon, 09 Nov 2020 05:45:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929526; cv=none; d=google.com; s=arc-20160816; b=IjuOyvjUNG3sNxNJZ3W4Mu27hdavpiKRv/n8J7R7taZ80Reu2OMJfyl/rNSvEM7t60 BABUp23cOMoLUFsRLW2ZnptK259IjqOfKBicr7HoDQ0B0q6QpxQzCZ0E7Xj2ph1lkvyA w+RUcqBTP7Xd/alEn66RLQmP11NNhGAWFOCB2TWQCUyFA+vKJxgSgTaMdUS4wSJQHu1H M+Tg6ci6MLJe0A2HvWJtX3lWK5OnriNPBF1SuQ8Ivxur+D05ycx8v3IemXBJYDnzN6kb HzKYGW3t6es5JRf7Xn4DoITgHlsUfGxzPMeKY4J5scgQelJoVc6SPlZpVibb5zWhQo9y cdcw== 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=YWinaq5EOm0XklRHwf+9L3zMVnVbwTk0ga7+Qq/NsGM=; b=N8DHCOB9Hcp4WbEb/szlNl2Kb+uqxZc1kJ0nDRnf1mydXoRpy05rwEdEnE5oDyedtT AkCJ48zYA5yx4G2Y+1NYIkSo07GXbovyjqFwv3DS13OUBD/61f6JgN+2cf1Qph7tZrS2 F7Z8tfIUnEdDGu2YMl5BxvZjqX5B0EEmXFx7c0Kn3fx/FK9p2gOUvl2uBlgNFNt2RayI Rv0YBogPKPbSmc7HSlglkFdLCVCTHU+JJdtZ7izFi5pS8Qi5LN4EELWiGE1UkEZ8pXDt w9YG3JquynM+cViRJ3qihMr2jh3uTXylWc/VNrerULpNVYCg5EINtgAk4dKGALaFmxBS zgdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="hCMeAK/1"; 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 j24si6880965ejy.346.2020.11.09.05.45.26; Mon, 09 Nov 2020 05:45:26 -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="hCMeAK/1"; 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 S1729585AbgKIM6a (ORCPT + 15 others); Mon, 9 Nov 2020 07:58:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:52748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729984AbgKIM60 (ORCPT ); Mon, 9 Nov 2020 07:58:26 -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 DDFA92076E; Mon, 9 Nov 2020 12:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926705; bh=/y7H92Kxy/9wo+t0QSJYuIYPw2TgRjpkBGgOFB+T/No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hCMeAK/1zV4sDYeKttvLpJEkeAEarrbmwhG/6lgg+zmFnsofXeuIdfN2A+X9LRz2z WQm5cMzWumQUh/PpxBZDngXJWDKZ+NSX4f6itl2fSpJVw7Pmd6OoiHj5vHgyph76mG jNtfNLpPEYVTbYN6KcmDzQRL3BqpwhGOKfG7tngA= 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 , Stable@vger.kernel.org Subject: [PATCH 4.4 45/86] iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. Date: Mon, 9 Nov 2020 13:54:52 +0100 Message-Id: <20201109125023.004403488@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109125020.852643676@linuxfoundation.org> References: <20201109125020.852643676@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 10ab7cfd5522f0041028556dac864a003e158556 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 a 16 byte array of smaller elements on the stack. This is fixed by using an explicit c structure. As there are no holes in the structure, there is no possiblity of data leakage in this case. The explicit alignment of ts is not strictly necessary but potentially makes the code slightly less fragile. It also removes the possibility of this being cut and paste into another driver where the alignment isn't already true. Fixes: 36e0371e7764 ("iio:itg3200: Use iio_push_to_buffers_with_timestamp()") Reported-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Link: https://lore.kernel.org/r/20200722155103.979802-6-jic23@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/iio/gyro/itg3200_buffer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) --- a/drivers/iio/gyro/itg3200_buffer.c +++ b/drivers/iio/gyro/itg3200_buffer.c @@ -49,13 +49,20 @@ static irqreturn_t itg3200_trigger_handl struct iio_poll_func *pf = p; struct iio_dev *indio_dev = pf->indio_dev; struct itg3200 *st = iio_priv(indio_dev); - __be16 buf[ITG3200_SCAN_ELEMENTS + sizeof(s64)/sizeof(u16)]; + /* + * Ensure correct alignment and padding including for the + * timestamp that may be inserted. + */ + struct { + __be16 buf[ITG3200_SCAN_ELEMENTS]; + s64 ts __aligned(8); + } scan; - int ret = itg3200_read_all_channels(st->i2c, buf); + int ret = itg3200_read_all_channels(st->i2c, scan.buf); if (ret < 0) goto error_ret; - iio_push_to_buffers_with_timestamp(indio_dev, buf, pf->timestamp); + iio_push_to_buffers_with_timestamp(indio_dev, &scan, pf->timestamp); iio_trigger_notify_done(indio_dev->trig);