Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3116983imm; Sun, 13 May 2018 04:42:24 -0700 (PDT) X-Google-Smtp-Source: AB8JxZriH9uuRhminpYYdmaoBkZU0as/wZVLnqyCp7LJNBnTEeKGyO12Oe9yNIpvtjyQs2KgXM6M X-Received: by 2002:a65:5d0f:: with SMTP id e15-v6mr5296623pgr.119.1526211744320; Sun, 13 May 2018 04:42:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526211744; cv=none; d=google.com; s=arc-20160816; b=IUHIPAbxBxLzP3qJLpUojGCA+BB/MZxaeCcBpXQOT0OfT50huS8TYagHnUuyNcGtHE /9MPLcK48s1KfnYB5m1C53V4HsYPZ1VIkU974a0BRjf+7zB816qcNM9PJ72jjI7h8CnF xo9RitNHPJGIzas9/VGXT3qWJLvehULCGg750XemJzGScOJh+1h0HSAnWsvC3MCb83PV BJ95ug4pbQ5EW4dPGWM9dbufIbBrWqw6h+EtiRsLWxyfK34JICpSp1HJY2GEVK3eLtCs jbj0gYpDPz5odVqgehsiUvxDQlt0pG1ZpuDTNFXdF4MVqg7kbrLbtguDUVSLe2Vw4emY SLzQ== 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=Yofs1XflVxQ4F2iXq+75jAcPS30iPzBQKlIto06CBj0=; b=J/xSTo2ICi60mOlUIaTyfd2OrLqZ8xZ/27J262PxeD4yqyoonZOrs6CvAJd7g61G48 HdL6mTr+b6fAeDiJ8t0Bl22zW0n/38yKsF3KeGTuzSVs0WAUfpf6P5JUxUFpq1lupwDR RISApQPTQAZ8l/kAJzs06j/1EimEui2Gd+WGyvWW6VuHwCGtSHP+o9+ozTmXqTBJWPGe EN1cBuBx9+kPJHBygVzPGgPrBaJjTioVGpKAmWVehB4krOe4CYOslVACkK9ffv/k4HEv TUJdjBH4yp4dmI+jjKEnsnRfdm4lISEg8saY4KBKA/wfdArSZsqgW2shHCrlYMyplZsR qlNQ== 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 77-v6si7014483pfz.334.2018.05.13.04.42.09; Sun, 13 May 2018 04:42:24 -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 S1751449AbeEMLlg (ORCPT + 99 others); Sun, 13 May 2018 07:41:36 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:34407 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750949AbeEMLld (ORCPT ); Sun, 13 May 2018 07:41:33 -0400 Received: by mail-wr0-f194.google.com with SMTP id p18-v6so9422032wrm.1 for ; Sun, 13 May 2018 04:41:32 -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=Yofs1XflVxQ4F2iXq+75jAcPS30iPzBQKlIto06CBj0=; b=tr9KtQsQ1FNWYm6GN42+9LbYVTQd3f6l6ierbEjpjv5wwxW22SO/0X0wfX8wwXzQ12 7DfpOPBkivDg1vw2tNwGvMLrTjluY5jUBljv8Tz+kFot1dBuh+PKBEoCgedi3IREFF6U XWW03Cna4EIWEs4pvewPZdlfQY0VKxcSQ947nJ0o2YvANDI4WrV09rsiR+6bUTA+TAzs xUw+Q/kdZn0J1H23W0twr1nz9sqrjf8Gbpofx3F4ZvJ9QzsibsMgYLGLiFvhxm5DNOkS U4NOylGx9zQ1OL/hvaJ87aufKZulGo7p/CDtdF/VIoxg3nz819+0XvyQpVx/YUXEeRYV HRsA== X-Gm-Message-State: ALKqPwfS1q0kl0ED8jkp+FBTg6GRwH+NQ4I0YSaqELHYdhYysqkeyebo 6W62zQ0IsRdSSltndV+QHuVtGg== X-Received: by 2002:adf:b722:: with SMTP id l34-v6mr4474584wre.85.1526211692001; Sun, 13 May 2018 04:41:32 -0700 (PDT) Received: from localhost.localdomain ([109.144.218.20]) by smtp.gmail.com with ESMTPSA id g105-v6sm11946532wrd.45.2018.05.13.04.41.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 May 2018 04:41:31 -0700 (PDT) Subject: Re: [PATCH v5 2/5] efi: Add embedded peripheral firmware support To: Andy Lutomirski , "Luis R. Rodriguez" Cc: 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" 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> From: Hans de Goede Message-ID: Date: Sun, 13 May 2018 12:41:11 +0100 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/03/2018 11:35 PM, Andy Lutomirski wrote: > 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. Looks good, I've cherry picked this into my personal tree and will make the next version of the EFI embedded-firmware patches use SHA256. As Luis already mentioned geting the EFI embedded-firmware patches upstream is not something urgent, so it is probably best to just wait for you to push these upstream I guess? Regards, Hans