Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp895603imm; Mon, 9 Jul 2018 12:43:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd+CCKfogyQ0X1ZfwHkT7OYPjigTDEWOmf7IrpKIKLJBUbiLljIlKQjWZ/xZb0e50O0I3gh X-Received: by 2002:a63:81c3:: with SMTP id t186-v6mr14074217pgd.413.1531165425151; Mon, 09 Jul 2018 12:43:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531165425; cv=none; d=google.com; s=arc-20160816; b=yWaJ6q2fE4/CXg0LWTUCYykVuOpwq934BtZ8KkFJ6XL/9ygyPE+jO7LFxRl7XVgqRF M0MuZfHGKTJv2VKyjcPhze9S9eQjFfvxGwZbX1mROwMvApYdn6AFcoZmhMcdck+TpmO4 14wVdAVM6ex1+eDS90liGqg5WDaX1sRGFdrysQ+hysV3GLETlbiNO7MkgUjTAej/PQwu RIiREhFyL9kGvG6FAcIupuqrv1EBYvn2j9I1eAF+e+/CvD/Ia5wdyVKt7RA/ehbegqvQ 9fNfFz732GRLUpvSsAIulIN/1MkkgLXuCiNtnujWzb4/qL6tOiH1zitJMZp9Wg+2vKXd jVOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=4H++CXCWDtmvQBSBHI9sD4ea2mN+d2VHPSvTpUlYQYc=; b=beo6giRw1x6RRdyI+qtRHKPGaQKxjbvkN8s4O+nqrGGO4udp9y+5i59kcb5ap+77Zu zR276iwe20VZbVuhAmiT6wEahbVTxbSU5Uju5JqoYjsgIHJdWuuszz5UzA47aaVwGBqV QxMFfEcsgggBoaxA459x3LpEEsPQYKQNX2undoVqk8PY/Lu56Q1YlYKl+yXgnMSkdt25 ugV9bNYPKvjQTBYjmpQwQQJa0XPN78UTV7Em9Qej6af6Myii8bx24XrTVtk5vyq/NkQt F3WIeIh8Zb3FkgbQTazbisufzdfJTXvukbZ/5dclQqYYOEnuXVcItVW+I2FAOkr4edDv /LdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9-v6si626628pgo.42.2018.07.09.12.43.30; Mon, 09 Jul 2018 12:43:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933004AbeGITlq (ORCPT + 99 others); Mon, 9 Jul 2018 15:41:46 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:34302 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932827AbeGITlo (ORCPT ); Mon, 9 Jul 2018 15:41:44 -0400 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w69JdLCY019456 for ; Mon, 9 Jul 2018 15:41:43 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2k4c88err5-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 09 Jul 2018 15:41:43 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 9 Jul 2018 20:41:41 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 9 Jul 2018 20:41:37 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w69JfaA643122784 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 9 Jul 2018 19:41:36 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9B3254C044; Mon, 9 Jul 2018 22:41:59 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 074854C046; Mon, 9 Jul 2018 22:41:58 +0100 (BST) Received: from dhcp-9-31-103-18.watson.ibm.com (unknown [9.31.103.18]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 9 Jul 2018 22:41:57 +0100 (BST) Subject: Re: [PATCH v5 7/8] ima: based on policy warn about loading firmware (pre-allocated buffer) From: Mimi Zohar To: Ard Biesheuvel , Mimi Zohar Cc: linux-integrity , linux-security-module , Linux Kernel Mailing List , David Howells , "Luis R . Rodriguez" , Eric Biederman , Kexec Mailing List , Andres Rodriguez , Greg Kroah-Hartman , "Luis R . Rodriguez" , Kees Cook , "Serge E . Hallyn" , Stephen Boyd , Bjorn Andersson Date: Mon, 09 Jul 2018 15:41:34 -0400 In-Reply-To: References: <1530542283-26145-1-git-send-email-zohar@linux.vnet.ibm.com> <1530542283-26145-8-git-send-email-zohar@linux.vnet.ibm.com> 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 X-TM-AS-GCONF: 00 x-cbid: 18070919-0028-0000-0000-000002D9CA4F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18070919-0029-0000-0000-0000239167C8 Message-Id: <1531165294.3332.40.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-07-09_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807090222 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-07-02 at 17:30 +0200, Ard Biesheuvel wrote: > On 2 July 2018 at 16:38, Mimi Zohar wrote: > > Some systems are memory constrained but they need to load very large > > firmwares. The firmware subsystem allows drivers to request this > > firmware be loaded from the filesystem, but this requires that the > > entire firmware be loaded into kernel memory first before it's provided > > to the driver. This can lead to a situation where we map the firmware > > twice, once to load the firmware into kernel memory and once to copy the > > firmware into the final resting place. > > > > To resolve this problem, commit a098ecd2fa7d ("firmware: support loading > > into a pre-allocated buffer") introduced request_firmware_into_buf() API > > that allows drivers to request firmware be loaded directly into a > > pre-allocated buffer. (Based on the mailing list discussions, calling > > dma_alloc_coherent() is unnecessary and confusing.) > > > > (Very broken/buggy) devices using pre-allocated memory run the risk of > > the firmware being accessible to the device prior to the completion of > > IMA's signature verification. For the time being, this patch emits a > > warning, but does not prevent the loading of the firmware. > > > > As I attempted to explain in the exchange with Luis, this has nothing > to do with broken or buggy devices, but is simply the reality we have > to deal with on platforms that lack IOMMUs. > Even if you load into one buffer, carry out the signature verification > and *only then* copy it to another buffer, a bus master could > potentially read it from the first buffer as well. Mapping for DMA > does *not* mean 'making the memory readable by the device' unless > IOMMUs are being used. Otherwise, a bus master can read it from the > first buffer, or even patch the code that performs the security check > in the first place. For such platforms, copying the data around to > prevent the device from reading it is simply pointless, as well as any > other mitigation in software to protect yourself from misbehaving bus > masters. Thank you for taking the time to explain this again. > So issuing a warning in this particular case is rather arbitrary. On > these platforms, all bus masters can read (and modify) all of your > memory all of the time, and as long as the firmware loader code takes > care not to provide the DMA address to the device until after the > verification is complete, it really has done all it reasonably can in > the environment that it is expected to operate in. So for the non-IOMMU system case, differentiating between pre- allocated buffers vs. using two buffers doesn't make sense. > > (The use of dma_alloc_coherent() is a bit of a red herring here, as it > incorporates the DMA map operation. However, DMA map is a no-op on > systems with cache coherent 1:1 DMA [iow, all PCs and most arm64 > platforms unless they have IOMMUs], and so there is not much > difference between memory allocated with kmalloc() or with > dma_alloc_coherent() in terms of whether the device can access it > freely)   What about systems with an IOMMU? Mimi