Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp915835ybk; Wed, 13 May 2020 17:03:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfYbFIW2xrpJ4gOcdq4GVLtwHKSGuBlMrSRh/I8buZI8dxj97vhkfZk8DefavD9A22F321 X-Received: by 2002:a17:906:af6f:: with SMTP id os15mr1529854ejb.78.1589414602495; Wed, 13 May 2020 17:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589414602; cv=none; d=google.com; s=arc-20160816; b=BlyBEHEBoFywOHHlQt7+ATpU+ADdOblQSDur8O90SaogPSoIz+NZTM0R8JJyqEnhcL /+Qwiaux4gtiwchIPY39vzJJR2xwHBWPdwvYRsAlM/WT1q3X6e6+YdMyj0SdvTCuWdk9 2xvLGg5Q7rdeALLJuL9GzH+7zIC8k7NuXCjSIZldtUgQMu0WnzfDXg6A2WW37vHZt28o +M8u5y8TP/W67YeYD8C6Ka26wObQFr39OQwvO9JEgKGvsmnZYUqwTcT/PlKnc86VQ75Q d0+pP/BpsYV5LMVZHVbV1Qy1YAUkSvWDIT3dxb8kfg8iBPpGZKKNRR194nBemic6vBwZ Qa8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=baKmRFONBanK64KmIHZ/XjPANqP9pxrESW09ycDxoYU=; b=jgai/7bzYB4MJDYiFnJJ+X36yO+OGAFV5mzRRCUgjKyvjyj7qGxUHRz/BoodJjvvFU NSKiYIUJpK4/mRExrCvWTj3pNzezH1H7vVowYRZlVqQ6i0WME8KfVqAHUzjCH+H/xiii eGy2u/ypHCdGQIrvd8EgAaq3cQW0LwoVn4EWI1C0lhCDzVvRgXwY60md2Fdb16TwvgDF SfEm86xdREdjkPqXPs1Ho/SXNwTKqA03E+Tzpyhh+AyzSdkjiYqSjWfmF9gxC9Boxrxf tq72RSn4VAFl71MRlLejlfToavPKd4seWC98ZQwOzZJ3Wflgq6zoHet+34JFludzAeT1 dvwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="oBxa/gfQ"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si815911eje.107.2020.05.13.17.02.59; Wed, 13 May 2020 17:03:22 -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=@kernel.org header.s=default header.b="oBxa/gfQ"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732847AbgEMX64 (ORCPT + 99 others); Wed, 13 May 2020 19:58:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:45520 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732456AbgEMX6z (ORCPT ); Wed, 13 May 2020 19:58:55 -0400 Received: from localhost.localdomain (pool-96-246-152-186.nycmny.fios.verizon.net [96.246.152.186]) (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 8F9C120659; Wed, 13 May 2020 23:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589414335; bh=k7d/LyV6/crKMI22byjJd9hAviD5VxpO78pU5eT8y2k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=oBxa/gfQQuQhzphTY+MmzddBFdYANvOzL69/j0LUCqoCdJAyjI7Ha50dh8igvPyiU ft3RTEd0N5e3O+aByRtxnNHWRgwxNyYXX9LJdlvhieNbhXmnEWJuKW5lOFbJUrRjQr SaRqovklhMbxBuEcXuh4wLwaV5ZRZRT7PagwZWQc= Message-ID: <1589414332.5098.246.camel@kernel.org> Subject: Re: [PATCH v5 1/7] fs: introduce kernel_pread_file* support From: Mimi Zohar To: Kees Cook 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 Date: Wed, 13 May 2020 19:58:52 -0400 In-Reply-To: <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> <202005131630.8B1ECE0@keescook> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2020-05-13 at 16:34 -0700, Kees Cook wrote: > 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 The security_kernel_read_file(), the pre-hook, would need to be moved after getting the file size, but yes that's exactly what would be done in the pre-hook, when the current offset is 0 and the file size and buffer size aren't the same. Mimi