Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4480426ivc; Tue, 3 Nov 2020 13:08:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJw9/Pa9tuE+0br0jLnVXrH5r61YNXFSMiJrpXUgzMv1vo93rR5fMwo3XoE0dMcnCrhIYNtV X-Received: by 2002:a17:906:12cf:: with SMTP id l15mr23048257ejb.540.1604437718844; Tue, 03 Nov 2020 13:08:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437718; cv=none; d=google.com; s=arc-20160816; b=t4lFApp/npwN7pxSzGp2Ez9F4qCCV0r40YYVNj6HsttC05t9VGbvOcf4zMCp2+vpIL RtpXEGacZFIMCaGxrSWJW6DbI9etWDp8aTIFyF/BG1HoihUyKMYL4KCNaJ8fi/KuFHaa lGSiuoJbgetOYOqotZSxPXdTmLWZzNwFCwaO8reQt1gd2ZvkEyVNDy9YAjUTL8+pylb1 9I99ccfkmKCF11tf7nAXtGM3BTe2Uu7K+84Nh82+rZZNUHlqF5l1lsUuSVG4tV5rj0Rx 21L+so4ytb6OnbjxM0bVIJ7JM9wu1kANuuF+VF/zNVxzseF7Ir9f8qoS11uUPRQxaO81 uftg== 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=sE3xG0IR//+t+i7k9zwxGhyWu2ceS8EhbARZIz30m3V+VQV6EU7QHIl6AU0ng8lHLq uCbkUMR5BS5n/2rBpZ98tdV1XIEA7iumpQfjv8m2O0I3Rxv5wsbWQb7XXec7LQq/p1wT kRokt4GrCwMXZ1IyE9NSdF03d6fAsrKRAzQG9U1tapEAkJKC2b0fGwSzmH/cKc65RrbQ a5/7vOY1m4ubaGHxil/8vJWhmQxXE8VT/2gsfIP0cEWHHCvo5kZ/fPVSnontg8z9rJwR TgIXapfcM5G75FR4Mx+0iym0FzWkuyxouIJ/FuTPf5aaMGKtAbVcJJNMtIY+dXUUWmmI pkcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jLmi/e/c"; 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 m13si10529734edi.391.2020.11.03.13.08.15; Tue, 03 Nov 2020 13:08:38 -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="jLmi/e/c"; 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 S2388240AbgKCVG7 (ORCPT + 99 others); Tue, 3 Nov 2020 16:06:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:46020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731404AbgKCVG4 (ORCPT ); Tue, 3 Nov 2020 16:06:56 -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 17C9020757; Tue, 3 Nov 2020 21:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437615; bh=/y7H92Kxy/9wo+t0QSJYuIYPw2TgRjpkBGgOFB+T/No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLmi/e/c7WF13miuDDIpGkS/tBUZjQRMuwA0mbLd0pYiXB2qG2AkxKNVuHleFlwm4 rUHI70EyICAzr/vugTqy+48Xo3k1JhCW83UnDkvn3LTGllQahsnIa1/gW0KU89GB7F kTOED3NUkUZw4jW3zRc4TkwRRPVwNzyreDHFfBlM= 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.19 152/191] iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. Date: Tue, 3 Nov 2020 21:37:24 +0100 Message-Id: <20201103203246.864510812@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@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 @@ -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);