Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp903094ybk; Wed, 13 May 2020 16:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKCkD0nu8rcIWDrnoDwSY8iybiJaU0ktHVvQhyLloMMZ5MDcOQaou3TcTmKY11W6nSbfsa X-Received: by 2002:aa7:d787:: with SMTP id s7mr1835851edq.104.1589413043359; Wed, 13 May 2020 16:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589413043; cv=none; d=google.com; s=arc-20160816; b=NMlNefLhX9jt8xzGaMIHDBFazwF6N+W3eNhbKAfduoQyrGjG0GBCNidWTA/0g0arK7 BhtEmYXC1Z/6HS1tV/sAzbwP+KqbUBaeOvzycjAc+IH7vde6GxxK2Shu23UxT3hyPuht 9TMUbUv8IMlhO3PIRJ6L/0rCduTDcQmfH8/bi2bKb5RXQcHeLWtFHhOyfDDaR+J07F+W b9eIr/oT17sNoMkuOeKCpAt05HcezqQ9C92nz8+3JbUiH2N+9WNmk37qbYDUCMvQOc6S x6s1Evj7CXYzu/nhkkSGUVIbk6Kx7AcBXgnATkqrDIDyLQS0sgvTlxC0dq5bNLjLPb7G eQjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=9+kHGmySmNxox5wuBQoQwck1bLpTOuP5gTxm3+9miDE=; b=CaCVSZToMFqRQH/e9W4UvLygwf5IoY1qzDTQWIfOal2S95zZe/Hr62dVEMlP+AK/+Z tesyrR8dZvMG39beciDSUXqKPKqttPgIvZX89xWdamCDnvgVukSeHCrZEMS3Gwzsptna BY5gZ4S98cI/6erc42/MqjzabIytvrGS4EIAIMKAChaFFGvWm9rlSDNVM+V5eg+rswu5 ZUlJFcNE7LxSaR6Nd9ArBb2pO+szX4oe+YoORk500DaVgP9yrQnB2klM53w3uRk+7zre c3Zgk4UmX/eIH/wUX6n9xoo+u1Fb/1x98tA4mHBjDBnWQnvX1k4kN5G7xeBfPylwhDig 0Akg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=a5bkxw4l; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si635198edk.17.2020.05.13.16.37.00; Wed, 13 May 2020 16:37:23 -0700 (PDT) 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=@chromium.org header.s=google header.b=a5bkxw4l; 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=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732730AbgEMXeT (ORCPT + 99 others); Wed, 13 May 2020 19:34:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1732727AbgEMXeS (ORCPT ); Wed, 13 May 2020 19:34:18 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09242C05BD0A for ; Wed, 13 May 2020 16:34:17 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id f4so51378pjm.2 for ; Wed, 13 May 2020 16:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=9+kHGmySmNxox5wuBQoQwck1bLpTOuP5gTxm3+9miDE=; b=a5bkxw4lZ5KtU/7XSy6vFoZNzxoQzbwCg8Ve+eRR31EJupSDG7nd9WLXO+x/fuH+oD T1iajkovrL+KE9IJDAnGZnwmEOeil6jnqMj0ZttdnSHvAjbD2Xl9s8EUwYBVXUeQAo9q t1ZXN1sRSkY/OXB5O/18TcHvWPlpTqquHyqAw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=9+kHGmySmNxox5wuBQoQwck1bLpTOuP5gTxm3+9miDE=; b=oEi9ZlAM1EFH1t6IcQHvfZHoR68kuU7+qCjKeDTC8EEG/+ypp7fs/iR0M/AurNy2c2 ZTmkc2xv3fK6s1OxxwN7kOJZ0rq50wu5jFRGIRPVqdfha4O/tjdkyQsMPYBdUewQETPy DAYrZ+P41tuf4VX23N+WBI47YQA+WjACvmLUItseQqyBCDKfgCJSQKE6EYDl34zJtRxR JGjmVUfKWEnDuY3jRrjf/CgV3A616Z5p/AWwNw0XfyZ8n6pejLAYu69tSwgjIlLgjJb8 KJjbO6gQwvQe63ij3c15vPEQP7+f9tVPplNzMJubGg5u1ZsYb06GFiXfVEFx4BS0Edte egaw== X-Gm-Message-State: AOAM530XfvV/sWm+xXrWdmf5RxsX696tLE9woBkl4OQ2WKYFg/Q5DoKY PX7pqnlQvVQTxPMTnN97TEBQig== X-Received: by 2002:a17:90b:1994:: with SMTP id mv20mr863273pjb.41.1589412856445; Wed, 13 May 2020 16:34:16 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id k2sm568374pfd.108.2020.05.13.16.34.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 16:34:15 -0700 (PDT) Date: Wed, 13 May 2020 16:34:14 -0700 From: Kees Cook To: Mimi Zohar Cc: Scott Branden , Luis Chamberlain , Greg Kroah-Hartman , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org, Shuah Khan , Arnd Bergmann , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Takashi Iwai , linux-kselftest@vger.kernel.org, Andy Gross , linux-security-module , linux-integrity Subject: Re: [PATCH v5 1/7] fs: introduce kernel_pread_file* support Message-ID: <202005131630.8B1ECE0@keescook> References: <0e6b5f65-8c61-b02e-7d35-b4ae52aebcf3@broadcom.com> <1589396593.5098.166.camel@kernel.org> <1589398747.5098.178.camel@kernel.org> <1589404814.5098.185.camel@kernel.org> <20200513212847.GT11244@42.do-not-panic.com> <1589407924.5098.208.camel@kernel.org> <1589410843.5098.220.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1589410843.5098.220.camel@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2020 at 07:00:43PM -0400, Mimi Zohar wrote: > On Wed, 2020-05-13 at 15:48 -0700, Scott Branden wrote: > > > > On 2020-05-13 3:12 p.m., Mimi Zohar wrote: > > > On Wed, 2020-05-13 at 21:28 +0000, Luis Chamberlain wrote: > > >> On Wed, May 13, 2020 at 05:20:14PM -0400, Mimi Zohar wrote: > > >>> On Wed, 2020-05-13 at 12:41 -0700, Scott Branden wrote: > > >>>> On 2020-05-13 12:39 p.m., Mimi Zohar wrote: > > >>>>> On Wed, 2020-05-13 at 12:18 -0700, Scott Branden wrote: > > >>>>>> On 2020-05-13 12:03 p.m., Mimi Zohar wrote: > > >>>>>>> On Wed, 2020-05-13 at 11:53 -0700, Scott Branden wrote: > > >>>>>> Even if the kernel successfully verified the firmware file signature it > > >>>>>> would just be wasting its time.? The kernel in these use cases is not always > > >>>>>> trusted.? The device needs to authenticate the firmware image itself. > > >>>>> There are also environments where the kernel is trusted and limits the > > >>>>> firmware being provided to the device to one which they signed. > > >>>>> > > >>>>>>> The device firmware is being downloaded piecemeal from somewhere and > > >>>>>>> won't be measured? > > >>>>>> It doesn't need to be measured for current driver needs. > > >>>>> Sure the device doesn't need the kernel measuring the firmware, but > > >>>>> hardened environments do measure firmware. > > >>>>> > > >>>>>> If someone has such need the infrastructure could be added to the kernel > > >>>>>> at a later date.? Existing functionality is not broken in any way by > > >>>>>> this patch series. > > >>>>> Wow! ?You're saying that your patch set takes precedence over the > > >>>>> existing expectations and can break them. > > >>>> Huh? I said existing functionality is NOT broken by this patch series. > > >>> Assuming a system is configured to measure and appraise firmware > > >>> (rules below), with this change the firmware file will not be properly > > >>> measured and will fail signature verification. > > So no existing functionality has been broken. > > >>> > > >>> Sample IMA policy rules: > > >>> measure func=FIRMWARE_CHECK > > >>> appraise func=FIRMWARE_CHECK appraise_type=imasig > > >> Would a pre and post lsm hook for pread do it? > > > IMA currently measures and verifies the firmware file signature on the > > > post hook. ?The file is read once into a buffer. ?With this change, > > > IMA would need to be on the pre hook, to read the entire file, > > > calculating the file hash and verifying the file signature. ?Basically > > > the firmware would be read once for IMA and again for the device. > > The entire file may not fit into available memory to measure and > > verify.? Hence the reason for a partial read. > > Previously, IMA pre-read the file in page size chunks in order to > calculate the file hash. ?To avoid reading the file twice, the file is > now read into a buffer. Can the VFS be locked in some way and then using the partial reads would trigger the "read twice" mode? I.e. something like: open first partial read: lock file contents (?) perform full page-at-a-time-read-and-measure rewind, read partial other partial reads final partial read unlock -- Kees Cook