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.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 131CFC433E1 for ; Sun, 7 Jun 2020 16:08:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E589420663 for ; Sun, 7 Jun 2020 16:08:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="srXavBFA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726634AbgFGQIT (ORCPT ); Sun, 7 Jun 2020 12:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgFGQIT (ORCPT ); Sun, 7 Jun 2020 12:08:19 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCF7EC08C5C3 for ; Sun, 7 Jun 2020 09:08:18 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 64so550949pfv.11 for ; Sun, 07 Jun 2020 09:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/lTjDuJCL3y6fcqv/FiMUZc5xhoW+8W2Ou9KB/LImeI=; b=srXavBFATXls2qUz3oyiw1yLfuq33v+B7xhLXLng2KH+8wsG+pbIlOaWBxBu1bGfuh QLUaZBz37E9fbHLE5e5UDhK1WG7Eg198bVaq13f7pG7fgwKaVsgbj68WW0cQKJgxNjKz BsPIszS2zcFv7rMw7wehgS4XuhQW9V5neQzb9rRqX2ChhM6k/ADid+/R3zbPWX0L7Yd5 VU1e8X02Njk92Gt8j09jc2/IL+CBnI+wWkOjibIoaM5P4mhZ9mRMuB6YWdJl5+bFJKPc RMfcl5WQsCVGBZ/V0SGThKzHzbRqCYM/Q4C76oJo7AQ3Pslr5Cc4GoAWj3TbPIm6+XVM Ccug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/lTjDuJCL3y6fcqv/FiMUZc5xhoW+8W2Ou9KB/LImeI=; b=FtlSvFfNDUOv2bt7LMd0P2iuJS+2OHMvowaH6JOfLx995TKx+TgUkxU5rgFdZ/+DlJ odobh5h+b62l/Gt4gaXScW+kBnv/9lYYugMf5LDCsvp0sCapL1WwxnbP8RFcuVN+fpW7 ZgxA9pnDvDVBONULv/eVBkrDiPha0YT1FU76lwA8spgbqgP93tz4qQFWxSPcYcSW3f79 QPBMWEHtj1x9AsCadpJV9TxusmiifsMwvJpwoXQUHs8wllc+LhIOC2FhXKaynpV2/BLK 44wgKLysNEHTHP4ptwgirrEzdRbRWe9e4BYW2mNnI/xRuJ65qZ9LQ2QlUteU9xQuFbOa oDZQ== X-Gm-Message-State: AOAM5324Pm9LB9mBgvoUrduc3E2U2L1mNSC6T9y2XPEKN4Gi8JQzHvzW vld2WgWUmz6mf+mnPYjXbNAm1a+bwg3qY2KxhE8= X-Google-Smtp-Source: ABdhPJwZ17IxxjTOfbM9P2WFwB8DQ6r5QxTR3N+hioJ8On+3Zvcjthlw7WylDkODUcgYjnyBgP5J4UCQ0KBNmmKgRqs= X-Received: by 2002:a63:ff52:: with SMTP id s18mr17525260pgk.203.1591546098265; Sun, 07 Jun 2020 09:08:18 -0700 (PDT) MIME-Version: 1.0 References: <20200607155408.958437-1-jic23@kernel.org> <20200607155408.958437-4-jic23@kernel.org> In-Reply-To: <20200607155408.958437-4-jic23@kernel.org> From: Andy Shevchenko Date: Sun, 7 Jun 2020 19:08:01 +0300 Message-ID: Subject: Re: [PATCH 03/32] iio:accel:bmc150-accel: Fix timestamp alignment and prevent data leak. To: Jonathan Cameron Cc: linux-iio , Andy Shevchenko , Jonathan Cameron , Lars-Peter Clausen , Srinivas Pandruvada Content-Type: text/plain; charset="UTF-8" Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Sun, Jun 7, 2020 at 6:57 PM 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 a 16 byte 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 structure in the iio_priv() data with alignment > ensured by use of an explicit c structure. This data is allocated > with kzalloc so no data can leak appart from previous readings. > > Fixes tag is beyond some major refactoring so likely manual backporting > would be needed to get that far back. > > Whilst the force alignment of the ts is not strictly necessary, it > does make the code less fragile. ... > + memcpy(&data->scan.channels[j++], &buffer[i * 3 + bit], > + 2); sizeof() ? -- With Best Regards, Andy Shevchenko