Received: by 10.192.165.148 with SMTP id m20csp91112imm; Thu, 3 May 2018 15:33:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZq6H00IVAm6fScqmqFr6Pt6sVoRKglXuQJ8mILm8ZVPs9770VmRXiO8LBMcUs5iytViFYAi X-Received: by 10.98.231.16 with SMTP id s16mr24646158pfh.227.1525386796645; Thu, 03 May 2018 15:33:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525386796; cv=none; d=google.com; s=arc-20160816; b=CTDDNJlRaDide8mXHTTdcsg3irSQKyhTu8iFs67BoB72XeWg/x0jlEGAE0dVVzVchU FY1ZpJTolSil3gEca/oJl2BRDoKSvOTuIaDi102IF7453aRkvq+ScGwAxUR9wSuqeVpB XC8tzuStbvbh0bXsZ5XPsDuHRIH4z9EXF0r9FOD8JqKvmIjf2ilMXqMcFFSkr0Fmx/Mo fK4RTPzurDpQJw8Pa8fcvZxVL3x1fTgLooUGkkcQUdTy4TlQCt/rxdGm868AxHtEf2fB vAhD/JPVkfAFjMTmpNNwZ6cmrUkZAeqBC9J/Z5tRX3/uLDGAv+rMiTBtji8vx4Pyvh0T H4Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Zo4kVBy+bkXjnamvpTrFhAs3TSda75Eksy4abMOVb+4=; b=QkCP6IenasroAOjOoYKlS6eS1XfKrPvHldNIq5unM1p+WnJ3JxyXWTPrUnruNolpsA MMoaSjQIry4YbRQE+MyLlirYhLRIU4DNCPKKIy1shcFs72gOTkxumqCeiZW893aSQ5Z0 mZCXfCNehZZf/yEepsCt7O93MKRErNUifNvUFMzlD/UHxIjT1GXxEVvvVxelKkYEFpmo nrieieTx4dqitJW3VAaPcOKZIdTWgTTNs9rZIv209Ufr8tQTIBVE7AvuLLi7eD7OQ8UW e9N9uafHyi8epkE+UFoFVnMgn991I+7xFHAp8yg3WHJppZvAP82UlgZWCz5X2EzpHAF5 hVbQ== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q124-v6si12081983pgq.215.2018.05.03.15.33.02; Thu, 03 May 2018 15:33:16 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751173AbeECWbb (ORCPT + 99 others); Thu, 3 May 2018 18:31:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:55868 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750970AbeECWb3 (ORCPT ); Thu, 3 May 2018 18:31:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9F9CDAF41; Thu, 3 May 2018 22:31:27 +0000 (UTC) Date: Thu, 3 May 2018 22:31:26 +0000 From: "Luis R. Rodriguez" To: Hans de Goede Cc: Andy Lutomirski , 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 Subject: Re: [PATCH v5 2/5] efi: Add embedded peripheral firmware support Message-ID: <20180503223126.GE27853@wotan.suse.de> References: <20180429093558.5411-1-hdegoede@redhat.com> <20180429093558.5411-3-hdegoede@redhat.com> <59023265-bfca-fe5d-e047-4c69404a0dd1@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <59023265-bfca-fe5d-e047-4c69404a0dd1@redhat.com> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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. Luis > > (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 > -- Do not panic