Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp804917pxb; Tue, 3 Nov 2020 13:02:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJzROTyJ9hrxLP9gOeabxzrQ+tRLpcMNldRpQcoHgvjQHIi79ilfLzHkfJe9AAnLr7Ro2Zzn X-Received: by 2002:a17:906:8282:: with SMTP id h2mr17008005ejx.50.1604437332363; Tue, 03 Nov 2020 13:02:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437332; cv=none; d=google.com; s=arc-20160816; b=ilcs+oGYtGVar9ul9MGFc2vQSp8/YXeKo7IsmF2SoD4fFm139cRSPjyv+YKiCxKeXA nEnlgfgb9aCI8lZVtlnDF9+zMcis+J9j6IYTb61m3LlUNC5WrOQMeumu7vg2XGmJ4lpW LurGf5Fz05mpLHxcfTpVr9ZNpvRz23DW5q4oEYEKznygFSBEG9NIAJ8rDzVfGH9TTy1/ Kgf4AZ00hmxECe+JlpXy0eaJ7mSwyJS4ucMFYO0lNNpXMgS1vDMONy6K2FA1ZCbSKXZR ip5LfWvExs+HaOosBB/S7ZpSi0Ux9CG1MpCDY8D7hgomXqbxD+FZglBtpQiocobTMK7Q N4Tw== 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=CsPksRxjoNrX36HqpSWqi53n6qV39pjEXi2TM4tuTbMOnKpARdtAhPlK7uVb7RpQuM O2FSHoTGLjU0MPIVpVYpPtW7tCfLQyQGebzAtLpP5y+dETx/i0ZM1+DOgB+heF6kphgb kVFJw8TWBVDt+pJ65Qd1x3j1ayt5fO/5wjVF69Adumui7kQYtnX1aeqfz6gsebGy4FZb FyWukBi8qdHOX59Dq+cBw8P/q7MJKWi9zf8yc4X3BeEJKqs8GNUsbhfzjEacsa5NoRlw YZYYWs8EUwlNcsqtCk3oZq3ahRYY4Dr4djHYlR5UPlnmbZsPPona/B/V3nOECb5s8Qs9 0R5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yWvk/YT/"; 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 ci22si24004ejc.413.2020.11.03.13.01.49; Tue, 03 Nov 2020 13:02:12 -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="yWvk/YT/"; 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 S1733247AbgKCVAd (ORCPT + 99 others); Tue, 3 Nov 2020 16:00:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:36330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732942AbgKCVAa (ORCPT ); Tue, 3 Nov 2020 16:00:30 -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 7735C223C7; Tue, 3 Nov 2020 21:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437229; bh=BKfdIyt5z62L/599YN5431rgr0e3luTrifZW3PySgKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yWvk/YT/UOmM8E8H/Zr8I5S39X5III+DKH6w3inDEzlGvtiSzudxy2MWMFmnUh6cH iixxJaWATuj2k3z3NKRyvcWoLJRovNIce1e7A9wSPfYG3U9tpa/a9fkL7rGD9UhYXW db5TOQVFI3LlKqjcKBI86G6RIOfZkzf73qtyVM+U= 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.4 154/214] iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. Date: Tue, 3 Nov 2020 21:36:42 +0100 Message-Id: <20201103203305.230721354@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@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);