Received: by 10.192.165.148 with SMTP id m20csp725204imm; Wed, 2 May 2018 07:51:49 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoLu1/TUu3bgmIv8M1/XNfu8aHpO/e6pjjYEhX+3cCn3f50V53Q1jdNVuS3XLsbNBqTIPkL X-Received: by 2002:a17:902:1aa:: with SMTP id b39-v6mr20513668plb.120.1525272708993; Wed, 02 May 2018 07:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525272708; cv=none; d=google.com; s=arc-20160816; b=YdO+odvSCZY3VpeNOiZ6lH4T5gkCucLTsUpX9LREuBY02i5c4RE9VQ2+uePUr5rpZ1 WmNHzaIy101bXKLI1vkD4MsbBfOCDibBipdhuraXJs9KN5SgbK9Eu3dZUDao9Xl2/9Ow Kn44qOS4x5n0+oHaCLNcd7ACWIaab0O6tma+RZgqt2IOsFbwEw9PXzUx6sVMqZe+GxNh W7PWSS4bdylXFYQbaSdZKkfnI6/WcI1IgSScZp7plz5LsH+Sp/Wc9WecsSkdxrl4txc4 WDhqJhG2qFQp7orema7ahkqZPXTcE33Gxel0Xyk70A2OG8Gmnb1qDlo9xmjYSxZKlXMU p6NA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=uTAUkX/R6Pq3IV3s8MiSgDKEf2H+6+anYk1fV+yMVik=; b=oPFhJ90UUbRsv07ua7e8WjdEViUEY7JaO1Lb1VpKtwh6ahK9UgeBPXrLbsKLkDbtFu VRudZIpB4GJTht3blU8yo50GZAr4ZpxUUr5IlOfxQmYcdXzlyz/FvbQnDKWAO9b0bdLr OGxj03Oh6qgHQNP+xGw5hrDORqpEN/fNFWLbwj43baWZl2h1GtDttPDuM/kjuEqewzIw FB6hzLlkbddxGhhwzJirV6Yn3MwQKh9tSu982DlrfVZAd4UbEEhBDU62qeqgk74EkOVn 3fcho1vwqDzoa1oAL1KqnetQvlsJrKN+/ckEzcvI2caU1c6KTKpDBwjrxAkRKosWmUyr 156g== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12-v6si9782066pgf.497.2018.05.02.07.51.34; Wed, 02 May 2018 07:51:48 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751800AbeEBOt7 (ORCPT + 99 others); Wed, 2 May 2018 10:49:59 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:36490 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751539AbeEBOt4 (ORCPT ); Wed, 2 May 2018 10:49:56 -0400 Received: by mail-wm0-f47.google.com with SMTP id n10so24829780wmc.1 for ; Wed, 02 May 2018 07:49:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=uTAUkX/R6Pq3IV3s8MiSgDKEf2H+6+anYk1fV+yMVik=; b=SInwPGYZ5tMc9DGOHbzD2qDHSC5VxOT6dmCChWFcDLAnvL7Qie7Mtivf2xnQbQzdnI tgJ6MEc6GmtTLLo9LrCmyYoeldomVyRFQ/UOF6ZCk73WSklfeQ6HHTMxMMMh0m6wV724 W05rCDvHsOAJd/zmlvoKOUaIw0UjwYmjfKpZUqAQy29h0w3j1Ewku4eOCjlp+UBnzaRS CfsfzFbD3qJLesR1m4PqZnlyi1KtTOsFW/k+k7PZWIMcUEhf1Yb//txsEnSCiaUwOVds VAZw+cgO8WFPUL1CsEl4ILeptCecWdmwxZ3APRpHPA+AWW0OkHb/N0ehPM8nMG1bgrRj xx+A== X-Gm-Message-State: ALQs6tAOXRpZqXMaAAeOqECMGftR/QdR0Co8f9m/QKovFin1DvX3bdKf wjv1GgT2jX3JHJKzpTHlUfFFMg== X-Received: by 2002:a50:9fc1:: with SMTP id c59-v6mr25858588edf.277.1525272595263; Wed, 02 May 2018 07:49:55 -0700 (PDT) Received: from dhcp-44-202.space.revspace.nl ([2001:470:7a95:4242:97d5:94a:fff6:e77a]) by smtp.gmail.com with ESMTPSA id x29-v6sm7391613edm.26.2018.05.02.07.49.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 May 2018 07:49:54 -0700 (PDT) Subject: Re: [PATCH v5 2/5] efi: Add embedded peripheral firmware support To: Andy Lutomirski Cc: Ard Biesheuvel , "Luis R. Rodriguez" , Greg KH , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Peter Jones , dave@bewaar.me, Will Deacon , Matt Fleming , David Howells , Mimi Zohar , Josh Triplett , Dmitry Torokhov , Martin Fuzzey , Kalle Valo , Arend Van Spriel , Linus Torvalds , nbroeking@me.com, Bjorn Andersson , duwe@suse.de, Kees Cook , X86 ML , linux-efi , LKML , LSM List References: <20180429093558.5411-1-hdegoede@redhat.com> <20180429093558.5411-3-hdegoede@redhat.com> From: Hans de Goede Message-ID: <59023265-bfca-fe5d-e047-4c69404a0dd1@redhat.com> Date: Wed, 2 May 2018 16:49:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 05/01/2018 09:29 PM, Andy Lutomirski wrote: > On Sun, Apr 29, 2018 at 2:36 AM Hans de Goede wrote: >> +The EFI embedded-fw code works by scanning all EFI_BOOT_SERVICES_CODE > memory >> +segments for an eight byte sequence matching prefix, if the prefix is > found it >> +then does a crc32 over length bytes and if that matches makes a copy of > length >> +bytes and adds that to its list with found firmwares. >> + > > Eww, gross. Is there really no better way to do this? I'm afraid not. > Is the issue that > the EFI code does not intend to pass the firmware to the OS but that it has > a copy for its own purposes and that Linux is just going to hijack EFI's > copy? If so, that's brilliant and terrible at the same time. Yes that is exactly the issue / what it happening here. > >> + for (i = 0; i < size; i += 8) { >> + if (*((u64 *)(mem + i)) != *((u64 *)desc->prefix)) >> + continue; >> + >> + /* Seed with ~0, invert to match crc32 userspace utility > */ >> + crc = ~crc32(~0, mem + i, desc->length); >> + if (crc == desc->crc) >> + break; >> + } > > I hate to play the security card, but this stinks a bit. The kernel > obviously needs to trust the EFI boot services code since the EFI boot > services code is free to modify the kernel image. But your patch is not > actually getting this firmware blob from the boot services code via any > defined interface -- you're literally snarfing up the blob from a range of > memory. I fully expect there to be any number of ways for untrustworthy > entities to inject malicious blobs into this memory range on quite a few > implementations. For example, there are probably unauthenticated EFI > variables and even parts of USB sticks and such that get read into boot > services memory, and I see no reason at all to expect that nothing in the > so-called "boot services code" range is actually just plain old boot > services *heap*. > > Fortunately, given your design, this is very easy to fix. Just replace > CRC32 with SHA-256 or similar. If you find the crypto api too ugly for > this purpose, I have patches that only need a small amount of dusting off > to give an entirely reasonable SHA-256 API in the kernel. My main reason for going with crc32 is that the scanning happens before the kernel is fully up and running (it happens just before the rest_init() call in start_kernel() (from init/main.c) I'm open to using the crypto api, but I was not sure if that is ready for use at that time. > (To be clear, I don't love my own suggestion here. What I'd *really* like > to see is a better interface and no attempt to match the data to some > built-in hash at all. In particular, there are plenty of devices for which > the driver wants access to a genuinely device-specific blob. For example, > I'm typing this email while connected to a router that is running ath10k > and is using a calibration blob awkwardly snarfed out of flash somewhere. > It would be really nice if there was a way to pull a blob out of EFI space > that is marked, by EFI, as belonging to a particular device. Then the > firmware could just pass it over without any particular verification. But > since your code is literally scanning a wide swath of physical memory for > something that looks like a valid blob, I think you need to use a > cryptographically strong concept of validity.) Yes ideally this would not be needed at all and/or use a well defined interface, but alas we don't live in an ideal world :) Regards, Hans