Received: by 10.192.165.148 with SMTP id m20csp93295imm; Thu, 3 May 2018 15:36:14 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoYK3EvtJnr4kYkNQMLoX8+RcTxFL+pAKIm0R+kBSpU90PgnmrMeLG3G7XlkcPM8t9kAL6G X-Received: by 10.98.165.19 with SMTP id v19mr2979823pfm.195.1525386974082; Thu, 03 May 2018 15:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525386974; cv=none; d=google.com; s=arc-20160816; b=abVb//YmO4XwHgGBDb+w/XVW8kP6yTIhzx7NP48uwDiC1i/Y9YDBspZkci4G7mXYjs qbhCqm5RhZXeD91ISpCMZwNZeAAU3KX/3NM2O91/JyUVCqr9/Mrbd29MqBrezOoeZMu8 FJ7GMv5w0/02er5Ea6tZAItWcqNwkMCKlNYHHmMbbBsLFjUw07sHR0s+EYQsxcqkqDkA cDbtdHVuWcQlSjo/2jhJ4WcdwZXUq6xpGCD6HeIvZGZ/YVItSBAIo9fGMTRm98IDYOyZ KxeDGdv92XW0/7Vz7ye/BmZ2M+7u0IzDueAczm2bnbJUCxipxEeHsyxZOqQu3mMGftFb oFqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=c0NdqqaXkkuQU5i1TY2kfitFQtV++r6BSbqh+k1qgzc=; b=jiT335RYiqNUZUvcFE+qD6dP2l7G8Z5Dp5M5OEDlF3M9Zqas/rvb+asP9gYNk7QuTl ZxwcSNpaUi2jJcaBWbrpKbyFDC92LDjwP8mQZkQwSctzYtHpaDrKzXpc83Bw6WY9etIy RDNQTDIWwOIIGyKTUvrTNrW/zIHzi1r6GuzUv3bjs/qaNv49G8fCqRFoyV6e7hOMrA/T XwID/StKH1WBRi9DWkmYUmBZXMRgq556CEOV6jshsBdivM+UlN3kzLmXEZl79sXrAVwA qcC6FkEe/6BZbpnup5cNWKJQBiRkFEI1LgX/Xa1nu8TBWX2eux0iOAQphdps3GAnX9c+ RubA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LM/DuUHc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63-v6si13957790pld.429.2018.05.03.15.35.35; Thu, 03 May 2018 15:36:14 -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; dkim=pass header.i=@kernel.org header.s=default header.b=LM/DuUHc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbeECWfZ (ORCPT + 99 others); Thu, 3 May 2018 18:35:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:33072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbeECWfV (ORCPT ); Thu, 3 May 2018 18:35:21 -0400 Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1713D217A5 for ; Thu, 3 May 2018 22:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1525386921; bh=CPHoAGBztiKnGDacAg0yEp0sTfPUODooynU0byF2CPI=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LM/DuUHcSJOQ+7wjr4PKipU1GHVPRNH6vYct+SO4kTy5ks32TcnLGwW5sq6JOf7IB n5ojx8iuUmDRCyPxTyrJu6Tu66cx5V9O9UVEksimmSJpa/DyuPg2C6gO4lpuauyEZb KStJa3C4HMfl4c/yyzddU93kSK6uVI1MOFEpQ4Bo= Received: by mail-wm0-f53.google.com with SMTP id j4so1333635wme.1 for ; Thu, 03 May 2018 15:35:21 -0700 (PDT) X-Gm-Message-State: ALQs6tCQpxUnt5iINHVOEMkMGt8xY5d+jD/9/nR0r9uRmGDU4rkDaLxK aJWlV/dNdqGzTXcmMM4Dyaee3THGs2N/IGeEV88c6Q== X-Received: by 10.28.71.146 with SMTP id m18mr15049936wmi.144.1525386917398; Thu, 03 May 2018 15:35:17 -0700 (PDT) MIME-Version: 1.0 References: <20180429093558.5411-1-hdegoede@redhat.com> <20180429093558.5411-3-hdegoede@redhat.com> <59023265-bfca-fe5d-e047-4c69404a0dd1@redhat.com> <20180503223126.GE27853@wotan.suse.de> In-Reply-To: <20180503223126.GE27853@wotan.suse.de> From: Andy Lutomirski Date: Thu, 03 May 2018 22:35:07 +0000 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v5 2/5] efi: Add embedded peripheral firmware support To: "Luis R. Rodriguez" Cc: Hans de Goede , Andrew Lutomirski , Ard Biesheuvel , 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 , Nicolas Broeking , Bjorn Andersson , duwe@suse.de, Kees Cook , X86 ML , linux-efi , LKML , LSM List , "Jason A. Donenfeld" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 3, 2018 at 3:31 PM Luis R. Rodriguez wrote: > On Wed, May 02, 2018 at 04:49:53PM +0200, Hans de Goede wrote: > > 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. > Not being sure is different than being certain. As Andy noted, if that does > not work please poke Andy about the SHA-256 API he has which would enable > its use in kernel. Nah, don't use the cryptoapi for this. You'll probably regret it for any number of reasons. My code is here: https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/commit/?h=crypto/sha256_bpf&id=e9e12f056f2abed50a30b762db9185799f5864e6 and its two parents. It needs a little bit of dusting and it needs checking that all combinations of modular and non-modular builds work. Ard probably has further comments. > Right now this is just a crazy hack for *2* drivers. Its a lot of hacks for > just that, so no need to rush this in just yet. It seems unclear if we're > all happy with this yet as well. Fair enough.