Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror some more efi variables to mok-variables #723

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

vathpela
Copy link
Contributor

Some machines have EFI Boot Services variables but not Runtime variables, and thus it can be quite difficult to figure out what's going on once the system is booted.

This changes mok variable mirroring to also mirror the following variables to the mok variable config table:

  AuditMode
  BootOrder
  BootCurrent
  BootNext
  Boot0000
  Boot0001
  Boot0002
  Boot0003
  Boot0004
  Boot0005
  Boot0006
  DeployedMode
  SecureBoot
  SetupMode
  SignatureSupport
  PK
  KEK
  db
  dbx
  Kernel_SkuSiStatus

There's no attempt to do anything involving creating runtime or boot-services only variables, it just mirrors them into the config table so they'll be exposed there.

@vathpela
Copy link
Contributor Author

Note that this is now on top of #660

This fixes some minor errors with the testing of how ALIGN() and similar
are defined, and makes an explicit "ALIGN_UP()" macro to complement the
existing ALIGN_DOWN() macro.

Signed-off-by: Peter Jones <pjones@redhat.com>
This moves decls for errlog.c into errlog.h

Signed-off-by: Peter Jones <pjones@redhat.com>
@vathpela vathpela force-pushed the mirror-more-stuff branch 2 times, most recently from 9e22a36 to c269276 Compare February 19, 2025 20:30
@vathpela vathpela requested a review from jsetje February 19, 2025 20:32
@vathpela vathpela marked this pull request as ready for review February 19, 2025 20:32
This changes our debug and error logging to save the entire logs into
mok-variables as "shim-dbg.txt" and "shim-log.txt".

Signed-off-by: Peter Jones <pjones@redhat.com>
Previously when there were no load options, this would go in the debug
log:

  load-options.c:313:parse_load_options() full load options:
  include/hexdump.h:92:vhexdumpf() hexdump of a NULL pointer!

This changes it to say:

  load-options.c:315:parse_load_options() LoadOptions is empty

Signed-off-by: Peter Jones <pjones@redhat.com>
This changes get_mem_attrs() to return EFI_UNSUPPORTED if
LibLocateProtocol() does not return an error but does give us a NULL
pointer.

Signed-off-by: Peter Jones <pjones@redhat.com>
This adds a mok variable flag "MOK_VARIABLE_CONFIG_ONLY" to specify that
the data should be added to our UEFI config table, but shim should not
create a legacy UEFI variable.

Signed-off-by: Peter Jones <pjones@redhat.com>
This adds a member to the mok_state_variable struct to provide a
callback function for formatting external data.  It basically has
snprintf()-like semantics for filling the buffer, but without the actual
printf-like formatting bits.

Signed-off-by: Peter Jones <pjones@redhat.com>
Currently when you've added a variable and not correctly changed the
test cases to match, you get a message like:

	./test-mok-mirror
	test-mok-mirror: setting variable sort policy to MOCK_SORT_DESCENDING
	test-mok-mirror: setting delete policy to MOCK_VAR_DELETE_ATTR_ALLOW_ZERO
	running test_mok_mirror_with_enough_space
	test_mok_mirror_with_enough_space: passed
	running test_mok_mirror_setvar_out_of_resources
	check_config_table:232:mok.name[0] 72 != test.name[0] 0
	check_config_table:232:Assertion `mok_entry->name[0] == mock_entry->name[0]' failed.

This adds another two lines:

	test-mok-mirror: Failed on entry 4 mok.name:"HSIStatus" mock.name:""
	test-mok-mirror: Entry is missing in expected variable list.

Or:

	test-mok-mirror: Failed on entry 4 mok.name:"" mock.name:"HSIStatus"
	test-mok-mirror: Entry is missing in found variable list.

Which will usually tell you which variable you forgot to add that's
present in test data, or what's missing in the test data and present
in the expected data.

Signed-off-by: Peter Jones <pjones@redhat.com>
This moves the EFI Memory Attribute Protocol helper functions to their
own file, since they're not related to PE things.

Signed-off-by: Peter Jones <pjones@redhat.com>
hughsie asked me if I can make shim tell userland what kinds of accesses
are allowed to the heap, stack, and allocations on the running platform,
so that these could be reported up through fwupd's Host Security ID
program (see https://fwupd.github.io/libfwupdplugin/hsi.html ).

This adds a new config-only (i.e. not a UEFI variable) variable
generated during boot, "/sys/firmware/efi/mok-variables/HSIStatus",
which tells us those properties as well as if the EFI Memory Attribute
Protocol is present.

Signed-off-by: Peter Jones <pjones@redhat.com>
This debug printf in our mock variable test code, which isn't normally
enabled, has a missing comma at the end of the format specifier.  This
causes __FILE__ to be part of the format specifier, which then means
we've got a missing parameter and also the types don't match up like
you'd hope.

This causes the most confusing segfaults.

Signed-off-by: Peter Jones <pjones@redhat.com>
This changes test-mock-variables and related code to not print all debug
messages at SHIM_DEBUG=1, and also adds some prints and comments for
context as to what's going on in the tests.

Signed-off-by: Peter Jones <pjones@redhat.com>
Previously the mok mirror state flags were only used in the mok
mirroring code.  But there are other consumers of that data, namely our
variable test cases, and it's useful for them to be able to check the
flags.

Signed-off-by: Peter Jones <pjones@redhat.com>
Some machines have EFI Boot Services variables but not Runtime
variables, and thus it can be quite difficult to figure out what's going
on once the system is booted.

This changes mok variable mirroring to also mirror the following
variables to the mok variable config table:

  AuditMode
  BootOrder
  BootCurrent
  BootNext
  Boot0000
  Boot0001
  Boot0002
  Boot0003
  Boot0004
  Boot0005
  Boot0006
  DeployedMode
  SecureBoot
  SetupMode
  SignatureSupport
  Timeout
  PK
  KEK
  db
  dbx
  Kernel_SkuSiStatus

There's no attempt to do anything involving creating runtime or
boot-services only variables, it just mirrors them into the config
table so they'll be exposed there.

Signed-off-by: Peter Jones <pjones@redhat.com>
Copy link
Collaborator

@jsetje jsetje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want some way to disable the mirroring entirely. Something like MOK_VARIABLE_NOTHING ? I certainly don't want this by default, but some light memory only configs might want to be able to save the space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants