All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Borislav Petkov <bp@alien8.de>
Cc: Emanuele Giuseppe Esposito <eesposit@redhat.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	x86@kernel.org, Thomas Gleixner <tglx@linutronix.de>,
	bluca@debian.org, lennart@poettering.net,
	Ingo Molnar <mingo@redhat.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Alexander Potapenko <glider@google.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2] x86/boot: add .sbat section to the bzImage
Date: Wed, 12 Jul 2023 13:48:45 +0100	[thread overview]
Message-ID: <ZK6hLZcuAH9jXKuL@redhat.com> (raw)
In-Reply-To: <20230712120002.GIZK6Vwga6DlJqdjEh@fat_crate.local>

On Wed, Jul 12, 2023 at 02:00:02PM +0200, Borislav Petkov wrote:
> On Wed, Jul 12, 2023 at 08:19:32AM +0200, Emanuele Giuseppe Esposito wrote:
> > And any comment on the SBAT string itself? I would like to get an
> > agreement on
> > "linux,1,The Linux Developers,linux,$(KERNELVERSION),https://linux.org"
> > before we use it as semplate also for downstream.
> 
> Yeah, looks useless to me. With your patch I get:
> 
> $ cat linux.sbat
> sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
> linux,1,The Linux Developers,linux,6.5.0-rc1,https://linux.org
> 
> But my branch is:
> 
> $ git describe
> v6.5-rc1-6-g3f01e9fed845

That doesn't make it useless, as the 3rd/4th/5th fields in the SBAT
file are just human targetted metadata. The validation process just
works off the 1st/2nd field.

> So your thing needs to enable CONFIG_LOCALVERSION_AUTO or so which
> allows for uniquely identifying the build. At least I think it did at
> some point. So that you can do stuff like:
> 
> $ file vmlinux
> vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=19f22ac85675ea30042fb703373d97c460bb5a61, with debug_info, not stripped
> 
> and you have a build ID sha there.
> 
> But not even that works because if I change the source, I still get the
> same sha. So it needs to be an mechanism which identifies the kernel
> image uniquely.

From a functional POV, it doesn't have to be unique identified,
as it is just a human targetted metadata field. A friendly git
version as from 'git describe' is more appropriate than a build
ID sha.

> And then why does it have to be a separate section? All those
> requirements need to be written down.
>
> And regardless what you do, this looks like a contract between the
> kernel and userspace tools so it absolutely needs to be documented
> somewhere prominently - not in a commit message with links to flaky URLs
> which would probably change in the future - and explained what the tools
> parse and where one can find that parsing code.

More precisely this is a contract between 'shim' and any other
EFI binary that is intended to be validated by 'shim' during EFI
boot, with SecureBoot enabled. Normally 'shim' would be loading
a bootloader like 'grub', but with unified kernel images (vmlinuz+
cmdline+initrd bundled in one EFI binary), there's a desire to
load the kernels directly from shim without an intermediate
bootloader. IIUC, the sbat info against the kernel would actually
be relevant even if grub is loading the kernel, as grub would still
call back into shim todo validation of the binary for secureboot
compliance.

The shim project has defined this format, and the linked git repo
provided URL is the canonical location for where this is documented.

The first doc gives the background and design approach

  https://github.com/rhboot/shim/blob/main/SBAT.md

The second docs gives an example of how revocation happens

  https://github.com/rhboot/shim/blob/main/SBAT.example.md

shim is also where you'll find the parsing code, though it is
not especially interesting, since this is just a CSV file

  https://github.com/rhboot/shim/blob/main/csv.c

called from

  https://github.com/rhboot/shim/blob/main/sbat.c

> Because if we go and change that, we need to be able to verify whether
> we're not breaking any userspace tools.
>
> Actually, I wouldn't mind even having a small script which does the
> parsing and which we can use to check that we're not breaking things.

The parsing isn't the interesting bit - any trivial CSV parsing
can validate, the semantics of each field are more important.

The first line just identifies the file format and should
never change:

  sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md

The second line identifies the kernel generation

  linux,1,The Linux Developers,linux,6.5.0-rc1,https://linux.org

The first field 'linux' should never change once decided upon, as it is
the name of the upstream project's EFI component - in this case the
linux kernel.

The second field '1' is the most important one, as it is the mechanism
through which revokation takes places, and the only one a human upstream
maintainer should manually change.

If there is discovered a flaw in Linux that allows the Secure Boot chain
to be broken (eg some flaw allowed linux to be exploited as a mechanism
to load an unsigned binary), then this 'generation' number would need
to be incremented when a fix is provided in upstream Linux trees.

The SBAT config for shim would be updated to say 'linux,2' was the new
baseline, at which point it would refuse to load any binaries that still
had 'linux,1' in their sbat PE section.

When a downstream vendor builds the kernel they would actually add a
third record, where they append a vendor identifier to the 'linux'
component name, so the .sbat PE section might say.

 $ cat linux.sbat
 sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md
 linux,1,The Linux Developers,linux,6.5.0-rc1,https://linux.org
 linux.fedora,1,The Fedora Project,linux,6.5.0-rc1,https://fedoraproject.org

this allows Fedora to deal with revokation if they make a downstream
only mistake that compromises SecureBoot.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


  reply	other threads:[~2023-07-12 12:49 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 15:44 [RFC PATCH v2] x86/boot: add .sbat section to the bzImage Emanuele Giuseppe Esposito
2023-07-12  1:21 ` H. Peter Anvin
2023-07-12  1:33 ` H. Peter Anvin
2023-07-12  6:19   ` Emanuele Giuseppe Esposito
2023-07-12 12:00     ` Borislav Petkov
2023-07-12 12:48       ` Daniel P. Berrangé [this message]
2023-07-12 13:28         ` Borislav Petkov
2023-07-12 14:06           ` Daniel P. Berrangé
2023-07-12 15:43             ` Greg KH
2023-07-12 16:23               ` Luca Boccassi
2023-07-12 16:57                 ` Greg KH
2023-07-12 18:59                   ` Luca Boccassi
2023-07-12 19:05                     ` Greg KH
2023-07-12 19:35                       ` Luca Boccassi
2023-07-12 19:42                         ` Borislav Petkov
2023-07-12 19:56                           ` Luca Boccassi
2023-07-12 20:01                             ` Borislav Petkov
2023-07-12 20:16                               ` Luca Boccassi
2023-07-12 20:07                         ` Greg KH
2023-07-12 20:41                           ` Luca Boccassi
2023-07-12 21:11                             ` Greg KH
2023-07-12 21:12                             ` Willy Tarreau
2023-07-12 22:32                               ` Luca Boccassi
2023-07-12 21:20                             ` Greg KH
2023-07-12 21:50                               ` Luca Boccassi
2023-07-13  6:09                                 ` Greg KH
2023-07-14  0:29                                   ` Luca Boccassi
2023-07-15  6:51                                     ` Greg KH
2023-07-16 17:41                                       ` Luca Boccassi
2023-07-16 18:28                                         ` Greg KH
2023-07-17  9:22                                           ` Daniel P. Berrangé
2023-07-17 11:06                                             ` Peter Zijlstra
2023-07-17 11:47                                               ` Daniel P. Berrangé
2023-07-17 14:10                                                 ` Greg KH
2023-07-17 11:12                                             ` Luca Boccassi
2023-07-17 14:11                                               ` Greg KH
2023-07-17 14:06                                             ` Greg KH
2023-07-12 15:45 ` Greg KH
2023-07-13  8:57   ` Vitaly Kuznetsov
2023-07-13  9:16     ` Peter Zijlstra
2023-07-13 14:58     ` Greg KH
2023-07-13 15:51       ` Vitaly Kuznetsov
2023-07-13 16:58         ` Greg KH
2023-07-13 20:49           ` Emanuele Giuseppe Esposito
2023-07-13 22:04             ` Greg KH
2023-07-14  6:57               ` Emanuele Giuseppe Esposito
2023-07-15  6:59                 ` Greg KH
2023-07-13 13:33 ` Ard Biesheuvel
2023-07-13 13:52   ` Ard Biesheuvel
2023-07-13 20:39     ` Emanuele Giuseppe Esposito
2023-07-13 22:31     ` Luca Boccassi
2023-07-14  8:52       ` Ard Biesheuvel
2023-07-14  9:13         ` Matthew Garrett
2023-07-14  9:14           ` Ard Biesheuvel
2023-07-14  9:25         ` Luca Boccassi
2023-07-17 16:08     ` James Bottomley
2023-07-17 16:56       ` Daniel P. Berrangé
2023-07-17 17:15         ` James Bottomley
2023-07-17 18:16           ` Daniel P. Berrangé
2023-07-20 16:46           ` Eric Snowberg
2023-07-20 17:07             ` James Bottomley
2023-07-20 18:10               ` Eric Snowberg
2023-07-20 19:16             ` Luca Boccassi
2023-07-21  0:02               ` Eric Snowberg
2023-07-21  8:55                 ` Luca Boccassi
2023-07-21 11:24                   ` James Bottomley
2023-07-21 12:40                     ` Luca Boccassi
2023-07-21 13:01                       ` James Bottomley
2023-07-21 13:10                         ` Luca Boccassi
2023-07-21 13:33                           ` James Bottomley
2023-07-21 15:14                             ` Luca Boccassi
2023-07-21 15:22                               ` Luca Boccassi
2023-07-21 15:27                                 ` James Bottomley
2023-07-13 23:13   ` Luca Boccassi
2023-07-14  9:33     ` Ard Biesheuvel
2023-07-14  9:59       ` Daniel P. Berrangé
2023-07-14 10:40       ` Luca Boccassi
2023-07-18 13:34   ` Paolo Bonzini
2023-07-18 14:02     ` Luca Boccassi
2023-07-18 15:51       ` Paolo Bonzini
2023-07-18 16:35         ` Daniel P. Berrangé
2023-07-19 13:21           ` Paolo Bonzini
2023-07-19 13:34             ` Luca Boccassi
2023-07-19 15:11               ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZK6hLZcuAH9jXKuL@redhat.com \
    --to=berrange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=bluca@debian.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=eesposit@redhat.com \
    --cc=glider@google.com \
    --cc=hpa@zytor.com \
    --cc=lennart@poettering.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masahiroy@kernel.org \
    --cc=mingo@redhat.com \
    --cc=ndesaulniers@google.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.