From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8477C433DF for ; Mon, 8 Jun 2020 13:17:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AEA1D2074B for ; Mon, 8 Jun 2020 13:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729574AbgFHNRQ (ORCPT ); Mon, 8 Jun 2020 09:17:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:7537 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728938AbgFHNRQ (ORCPT ); Mon, 8 Jun 2020 09:17:16 -0400 IronPort-SDR: osrbZ7MX2R5LhUJAHtUNeDIJ2REFXCQKL4MhUFajsmcSLnzsxyemF75I8mA+53trezPnsT7s9l nXpbNDzOdlyA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2020 06:17:15 -0700 IronPort-SDR: EDZisSNlnqWQGknYnyxgc7eQLggSLdye5KHL+uxUpYCzGqCvul7CNXIh3/7IgwebGk3ozzrtxU qW9zHN+vFjLA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,487,1583222400"; d="scan'208";a="305818270" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by fmsmga002.fm.intel.com with ESMTP; 08 Jun 2020 06:17:10 -0700 Received: from andy by smile with local (Exim 4.93) (envelope-from ) id 1jiHeK-00Bgem-NA; Mon, 08 Jun 2020 16:17:12 +0300 Date: Mon, 8 Jun 2020 16:17:12 +0300 From: Andy Shevchenko To: Jonathan Cameron Cc: linux-iio@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Daniel Baluta Subject: Re: [PATCH 18/32] iio:imu:bmi160 Fix alignment and data leak issues Message-ID: <20200608131712.GQ2428291@smile.fi.intel.com> References: <20200607155408.958437-1-jic23@kernel.org> <20200607155408.958437-19-jic23@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200607155408.958437-19-jic23@kernel.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Sun, Jun 07, 2020 at 04:53:54PM +0100, Jonathan Cameron wrote: > From: Jonathan Cameron > > 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 an array of smaller elements on the stack. > As Lars also noted this anti pattern can involve a leak of data to > userspace and that indeed can happen here. We close both issues by > moving to a suitable array in the iio_priv() data with alignment > explicitly requested. This data is allocated with kzalloc so no > data can leak apart from previous readings. > + /* Ensure natural alignment for timestamp if present */ > + __le16 buf[16] __aligned(8); Perhaps struct in all such cases, like struct scan { __le16 buf[3 * 3]; // 3 axis per 3 sensors s64 ts; __aligned(8); }; ? -- With Best Regards, Andy Shevchenko