Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3211886pxb; Mon, 9 Nov 2020 05:43:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeUgsHEOfmAagmU0dg0nymwKrBxKeBREAXL69Typ2OXdxs0p3oM9LM2HqZgiGT4OPz3K8E X-Received: by 2002:a05:6402:cb4:: with SMTP id cn20mr15335123edb.235.1604929397831; Mon, 09 Nov 2020 05:43:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604929397; cv=none; d=google.com; s=arc-20160816; b=gGRq6Z8d7HtfONwlTRA9JfbXaDsvdh2xnANAdFvQux6pIPYVuvwEZfa5HoopL4Aavc K1tdTHVUsaynLWguYIRMj7vhhL6991gacMG+CgXY+tU6T02BgoLN725oVGyiHkeYcUDl bjISgMXpf8nmDeWBUl9GPvmc7oR9ONoZnt0z+aE96t0zGhFVJC08K15RQ4Ui4tVG2EVU CtCK96QopmrJEfP11Pji+j6YkpwNZYCNtxm85MjPg7RjmV8woJTrtaowWoP8t0PXI9JN tk1et4eN9rJz1DWiSl7FJsxCvXJZcT6hb9wD5CqCd+e0KkAW6IiD0wrZnXQYtLIsk6w0 Gpgw== 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=Kpj7ce553l7KzX7Xj/OiQ1E+q562wwG1uoRkAnyIHkDkEE9CBi65QuNm6Gq8GMkC2p 74rkyASX14auvPOE16gThYAgM1YpBGjOb+Lv28VnCVWVW7HZJGXXQ7U/qpDj3i2vZZKu Z2Ma3GnUhrgVKYv7FyZIeDC2Bo8S0mVbh+T9ztSYgPpqMETIYcsex5BVwM4hXIuEQaUS kC+RGkQW2Fvw2x0FxudSJEFOqfkuiwXI7v5lNQ8sbJb6pEcK05n0RR1V8+3peM2yjzvA VHm0pSKibhU6ku8l1yDSbPHfT9tQD46GmY0pcLdpIU0nTMPwPnUipr96ZI0GrW4H6eJ1 zkYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iu9o33Sx; 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 qo13si6626730ejb.650.2020.11.09.05.42.53; Mon, 09 Nov 2020 05:43:17 -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=iu9o33Sx; 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 S2387669AbgKINja (ORCPT + 99 others); Mon, 9 Nov 2020 08:39:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:56244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730670AbgKINDk (ORCPT ); Mon, 9 Nov 2020 08:03:40 -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 A480E22202; Mon, 9 Nov 2020 13:02:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604926977; bh=/y7H92Kxy/9wo+t0QSJYuIYPw2TgRjpkBGgOFB+T/No=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iu9o33Sx1m5JquLxP2nBc//Lj8AGQrEy+IpauGD3IOF2e0mJJTzDTqkjzKfdlQaFp 0slAdUIFZ0x+TLEyTopoLCS3N6/RZynLGe7rn3i7l7wT7LSQkptpI6y1CxeTunEQri WMXKe6ElMrbcJlI9MUTcsNHCj1qQI+UXptJlsSKg= 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.9 068/117] iio:gyro:itg3200: Fix timestamp alignment and prevent data leak. Date: Mon, 9 Nov 2020 13:54:54 +0100 Message-Id: <20201109125028.902266505@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 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);