Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp835092pxb; Tue, 3 Nov 2020 13:56:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJySD3+3dqsMFiZOWnnf1nr9CCxSh6auNOB8l/gNOJ6ZSHGa/W+gtzfEtq1tM/uK4oQJjfX6 X-Received: by 2002:a17:906:158e:: with SMTP id k14mr21417581ejd.496.1604440566978; Tue, 03 Nov 2020 13:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604440566; cv=none; d=google.com; s=arc-20160816; b=pmah05tptLBqg1u9SG0hERlF7SrxcxBS20DZ0shybNfZ0OFAOwUu0Wp20lGNmBER6Q ofPhzBAH4AmNlMtnMuyM4uCJv6tPjcb36UUgbso4LTQnM7uA0hpD9nW0Bcu4XxdeXoIw I2dm6r4ALM177FQwEM2EjueLmrfQ3CqcWR/Cj4btrB2x0PJqBhtmpB7a7J3WNLzq8GyY u42bxilT7m3p8gaA8MIT7HFEHaUW2qvHEyqriqu5gkVOcDNNdGA+9AdDmTjbLjqFFcPy INk7BOx71kq7tz6E33V/pKJIEtYkweR0ZeL5GHMC51n4hUVuhNmgglKzRPRQOho+KeAF ikjw== 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=c/lFjaJ849yYlHnI68RqS0MUfAyj6RY2tG5xv0AeCmQ=; b=qQrsZdtj7LXWsOhKL0DpiGzOSes6X3ANLtGS9DCKJLnA4W79UuUq7euq5Z7dKg5UUe VjppMH2DWyXyfORmK9AGmByF4hHW7AplVOyNDf9c3JD2QLWJyeBLjsFW7jd1iV5Wognh 1AaldhZTyylzRcSmQHBkM3nu8uqo8o29sRu2eKM8pIpKo/Xx7GgqExAhhaoxfXA7hMsm Of5L+J1qizvZ8A6+hvIlc56WQEV7WkxAR3u9zhLKygQ3b2UzJmyR9vL9J6CdzePRwsY8 4+JOkfG1MdEZvxfuKzqMF04kewfN19PDndkYhQo/bYPngfXwUsQb70WXCnRzkrVQyhlN lcLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=STqlmSUf; 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 j7si13276682edy.250.2020.11.03.13.55.44; Tue, 03 Nov 2020 13:56:06 -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=STqlmSUf; 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 S1731396AbgKCVvk (ORCPT + 99 others); Tue, 3 Nov 2020 16:51:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:39774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731449AbgKCUsV (ORCPT ); Tue, 3 Nov 2020 15:48:21 -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 7E75022409; Tue, 3 Nov 2020 20:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436501; bh=BKfdIyt5z62L/599YN5431rgr0e3luTrifZW3PySgKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=STqlmSUfP06TL4aDJ2swdTbs6GkSwI7eMJA71x1w8MKOLmhzgR6r/oYOiFlURiMcb 6CbEALWu8lbWSlJqlQUGMPH0bd81K1llTG1O7Uyl1slUFpk5EkdyREaFChJu5K0hG3 Agw31IvMvFmJLHn4SHcNO27Z6UdrsOGaWdhWe92M= 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 5.9 278/391] iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. Date: Tue, 3 Nov 2020 21:35:29 +0100 Message-Id: <20201103203405.793226857@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 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 @@ -46,13 +46,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);