Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 29 May 2016 12:18:27 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Eric McCorkle <eric@metricspace.net>
Cc:        Allan Jude <allanjude@freebsd.org>, freebsd-hackers@freebsd.org
Subject:   Re: EFI GELI support ready for testers
Message-ID:  <20160529091827.GD38613@kib.kiev.ua>
In-Reply-To: <6A9DADE0-B214-424A-BB14-0B0848F0D08D@metricspace.net>
References:  <519CC1FC-84DF-4710-8E62-AF26D8AED2CF@metricspace.net> <20160528083656.GT38613@kib.kiev.ua> <d6b96a6c-4e92-35a5-e78b-cc674b6d2f25@freebsd.org> <20160528172618.GB38613@kib.kiev.ua> <6A9DADE0-B214-424A-BB14-0B0848F0D08D@metricspace.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, May 28, 2016 at 04:02:43PM -0400, Eric McCorkle wrote:
> 
> > On May 28, 2016, at 13:26, Konstantin Belousov <kostikbel@gmail.com> wrote:
> > 
> >> On Sat, May 28, 2016 at 10:27:40AM -0400, Allan Jude wrote:
> >>> On 2016-05-28 04:36, Konstantin Belousov wrote:
> >>>> On Fri, May 27, 2016 at 07:39:57PM -0400, Eric McCorkle wrote:
> >>>> I am pleased to announce that my work to add support for GELI in the EFI boot loader (as well as perform more general refactoring) is now ready for testing.  I am able to successfully detect multiple GELI partitions in boot1 and pass the keys into the kernel.
> >>> 
> >>> Can somebody explain in which way this is useful ?
> >>> Same question for the GELI code for non-EFI loader.
> >>> 
> >>> BIOS cannot read raw data from the encrypted partition, so you need
> >>> either old boot or the loader and some additional data on EFI boot
> >>> partition anyway.
> >>> 
> >>> Features adds significant amount of code, which must be maintained in
> >>> parallel with the kernel code.
> >>> _______________________________________________
> >>> freebsd-hackers@freebsd.org mailing list
> >>> https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> >>> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
> >> 
> >> The motivation for my work (GELI in boot2 and loader for non-EFI boot)
> >> was supporting ZFS boot environments. Previously, when you use GELI you
> >> needed to have two ZFS pools, one for an unencrypted /boot and one for
> >> the encrypted /
> >> 
> >> This breaks ZFS boot environments, since a snapshot of the root file
> >> system won't include the correct kernel etc.
> > Why cannot /boot included into the boot environment ?
> > When I last saw Solaris, somewhere in its 10-th, any amount of
> > filesystems could be added to the bootenv.  But whatever the definition
> > of bootenv is used, it exists at a level of the shell scripts and selecting
> > the actual partition for loader.  Throw thousand lines of code into
> > the unstable and very hard to debug environment of loader looks somewhat
> > unproductive.
> 
> You misunderstand.  Alan was talking about pure ZFS systems, where there is one big ZFS pool holding everything.  You need to be able to access /boot obviously, but ZFS does not allow you to assign separate out data on to a single device.  It creates a pool, which combines all devices.
> 
> To have /boot unencrypted, you have to have a separate partition for just /boot, which is undesirable.
Why it is undesirable ?  You must have EFI boot partition by any means.

And why it is simultaneously desirable to add a bunch of code to loader
to hide this ?

> 
> >> 
> >> The final version of my geliboot took an extra effort to reuse the AES
> >> code from sys/crypto/rijndael and sys/opencrypto and GELI directly from
> >> sys/geom/eli to avoid maintaining a separate copy of that code in sys/boot
> > Which means that kernel code must be also runnable in the strange and
> > incompatible environment of the loader. I cannot see how this reduces
> > code maintanability even a bit. I am already rather unhappy about ZFS
> > kernel code being compiled as the userspace library, which hurt me
> > and other people more than once. Now (?) the kernel code must be also
> > verified for the loader.
> 
> I mean, the loader has to be able to access the filesystems, there's no way around it (barring crazy coreboot stuff).
> 
> Also, it should be possible to create a synthetic EFI test-harness that runs in *userland*. EFI is basically just a bunch of tables of function pointers, no bios interrupts or anything.  As long as you implement the interfaces, any loader should also run in your synthetic environment.  I had plans to look into this after this work is done.
> 
Of course EFI is not 'just a bunch of tables'. It might look so when you
have tunnel vision and all you do is writing code making calls, but it
is definitely not when you consider it as a part of platform.

UEFI makes it absurdly easy to distribute a code that gets executed on
every boot before boot loaders. The most straighforward is to put UEFI
driver binary into the UEFI FAT and register it into some variables (too
lazy to remember details). You get this way both boot- and runtime-
injection, officially supported. This was one of the reason for secure
boot.

To avoid trivial debunks, I put a note that of course drivers are not
the only way for such code to appear on the system, without
requiring any hardware modifications. The rich programming environment,
with flat memory and full control over hardware, with easily explorable
data structures, with documented and compatible ways to get code
persistent are the characteristics of it.

It is much easier to target such preboot env then to maintain dynamic
list of the userspace escalation code.

> >> 
> >> Hopefully the work I did to make sys/opencrypto and sys/geom/eli more
> >> reusable outside of the kernel will make it easier for Eric to do the
> >> same for the EFI version.
> >> 
> >> The motivation for the EFI version is the same, ZFS boot environments,
> >> plus the obvious security advantages of having the kernel stored
> >> encrypted rather than not.
> > 
> > Obvious security advantages ?  Seriously ?
> > What is a single 'security' advantage of hiding the kernel ?
> > 
> 
> There are plenty.
> 
> Right up at the top, an attacker able to access /boot is free to tamper with anything, and can insert back-doors into the kernel, loader, or any module.  If you assume that the attacker can't write, then they can still scan the kernel and modules for signatures for known vulnerabilities (since the kernel itself has a commit id and detailed version info, they can compare this against a CVE database).  Even if they can't do that for some reason, they could still potentially exfilt a kernel address map for use in rootkit attacks against your system.  Lastly, general security principles say to minimize the attack surface, which would definitely mean you should protect the core of the system.
> 
I cannot believe that somebody considers hiding kernel binary even
remotely viable 'security' measure. But let me accompany that for a
second and see what attack surface does the attacker get from knowing
the kernel binary ?

>From inspecting quirks in the syscalls it is (almost trivially) easy
to reconstruct the date of kernel sources up to probably month, without
causing much observable havoc in the system.  The kern.osreldate is around
as well, not only as sysctl, but also having some impact on the runtime
behaviour of several syscalls and image activators.

Same fingerprints are available from the sizes of the objects in UMA
zones, readily available from vmstat -z.  Changes in the basic kernel
structures layout are reflected in the size changes.

Facilities like procstat -kk would show code reorganization and refactoring
changes.

The list above was written after about 10 minutes spent on thinking how
to identify the system sources without having access to binaries. I
believe another 10 minutes would give even more suggestions.


> > Since you noted a 'security', I realized that your changes decrypt the
> > keys in the pre-kernel environment. In other words, very sensitive
> > material becoming accessible to strange and unknown code which is
> > managed by firmware.
> 
> The likelihood of such an attack, while something I considered, is very low.  A key should look like random binary data (much like the GUIDs prevalent in EFI code).  I seriously doubt someone could write a firmware module that could dig through the memory state of an arbitrary OS's boot loader and find keys.  You'd basically have to put a full online binary analysis framework in the firmware, and have it run fast enough to not be noticed.  That would be some serious Turing award-worthy work kept secret from the world solely to build firmware backdoors.  I don't think even Lenovo would go that far.
> 
> (I know I mentioned scanning the kernel as a threat above; that's an offline attack that can be done on a copy.  Online undetectable analysis of a running program is WAY harder.)
> 
Nobody would scan for random data looking like keys. If attacker is
interested in keys from the freebsd loader or password decrypting the
keys, the address of the memory region where the material is stored and
region' layout are immediately available for any code collocated in the
common address space.

The hooks into the interfaces and pre-recorded sequence of calls for
the initialization of loader give unique execution profile which allow
to determine the password and key storage location.

Exact attack scenario is not the point I am trying to make.  Instead, I
point out that UEFI execution environment is shared one, with no walls
between software components from arbitrary sources.  It is absolutely
unsuitable for exposing sensitive material.  Even more laughtable to
simultaneosly hide kernel binary.

In contrast with the kernel environment, which even with ME/BMC/ACPI/UEFI
runtime components, is less penetrable by trying to own the execution
state of the machine.


> Besides, if someone wants to do evil things in firmware, I think it's far more likely they'd just backdoor the network or USB controllers to let someone send an override packet and execute bundled code in kernel mode.  That works every time for every OS and doesn't require surreptitiously picking apart arbitrary programs' data structures in real time.
> 
Of course backdoring hardware is order of magnitude harder and requires
physical access to the machine.  The realistic action by level of script
kiddie is getting UEFI driver installed.

To close this branch, backdored busmasters (but not ME) are
trivially mitigated by enabling IOMMU, FWIW.

> For what it's worth, I have considered possible hardening measures: using alias GUIDs to disguise interfaces and adding per-build padding or XOR masks to structures with keys to throw off scanners.  However, I don't think the threat is realistic enough to warrant such measures.
> 
I do not see a way to comment about the measures, without adding
the word 'theatre'.

> > Putting aside ineradicable evil of Intel ME or its
> > AMD twin, and SMM handler, you are exposing keys to whatever code happen
> > to inhabit the preboot env, not neccessary originating from the firmware
> > vendor.  Secure Boot would not help there, since when the measurement
> > indicate that untrusted component was there, it is too late.  I.e.,
> > you making much easier for malice hacker to steal the keys.
> 
> I mean, the same argument holds for the kernel, if not moreso.  You have ACPI bytecode, SMM, device blobs, anything that the boot environment chose to keep around for runtime by marking that memory as "unavailable", and of course, the evil that is Intel ME.  This is an unavoidable risk of having keys in main memory ever.
> 
See above.

> If you really want any kind of safety from this, you need to use a hardware crypto device that stores keys in a separate memory (which, I specifically designed things to make it easy to add support for one).  Of course, you then have to trust the device...
> 

No, what I want is avoiding bad choices which are seemingly made just
because code can be written. Code exposing sensitive material is written
for very weak and leaking environment, at least without secure boot
turned on. Arguments supporting that decision reference 'security' by
e.g. hiding kernel binary, and undesire to have /boot partition. Please
take a step outside and see bigger picture.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160529091827.GD38613>