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

Intel txt aem 2.06 testing #16

Closed
wants to merge 20 commits into from

Conversation

krystian-hebel
Copy link
Member

No description provided.

@krystian-hebel krystian-hebel force-pushed the intel-txt-aem-2.06-testing branch 3 times, most recently from fa228ba to 2a10c64 Compare January 29, 2024 15:55
Daniel Kiper and others added 9 commits January 31, 2024 12:56
It does not make sense to have separate headers for separate static
functions. Additionally, we have to add some constants with MSR addresses
in subsequent patches. So, make one common place to store them.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
... to grub_rdmsr() and grub_wrmsr() respectively. New names are more
obvious than older ones.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Currently rdmsr and wrmsr commands have own MSR support detection code.
This code is the same. So, it is duplicated. Additionally, this code
cannot be reused by others. Hence, extract this code to a function and
make it public. By the way, improve a code a bit.

Additionally, use GRUB_ERR_BAD_DEVICE instead of GRUB_ERR_BUG to signal
an error because errors encountered by this new routine are not bugs.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
...to avoid potential conflicts and confusion.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Subsequent patches will use that constant.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
…acros

Subsequent patches will use those macros and constant.

Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
The functions calculate lowest and highest available RAM
addresses respectively.

Both functions are needed to calculate PMR boundaries for
Intel TXT secure launcher introduced by subsequent patches.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
...to avoid naming collision with TPM TIS and CRB driver introduced
by subsequent patch.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
It will be used by Intel TXT secure launcher introduced
by subsequent patches.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
@krystian-hebel krystian-hebel force-pushed the intel-txt-aem-2.06-testing branch from 2a10c64 to 66004ae Compare January 31, 2024 11:57
@krystian-hebel krystian-hebel changed the base branch from intel-txt-aem-2.06 to intel-txt-aem-base January 31, 2024 11:57
Copy link

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

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

Please rename all read and write functions to include the number of bits they access, so read64 instead of readq (and similar for other functions). Also please document the magic numbers used in the SLRT calls

docs/grub.texi Show resolved Hide resolved
grub-core/lib/i386/relocator32.S Show resolved Hide resolved
Comment on lines 184 to 188
prot_size = ALIGN_UP (prot_size, GRUB_TXT_PMR_ALIGN);

if (prot_size > GRUB_TXT_MLE_MAX_SIZE)
{
err = GRUB_ERR_OUT_OF_RANGE;
goto fail;
}

Choose a reason for hiding this comment

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

Should these be reordered to make sure ALIGN_UP cannot overflow?

Comment on lines 548 to 558
/* TODO the initrd image and size can have hi bits but for now assume always < 4G */
grub_slaunch_add_slrt_policy_entry (17,
GRUB_SLR_ET_RAMDISK,
/*flags=*/0,
boot_params->ramdisk_image,
boot_params->ramdisk_size,
"Measured Kernel initrd");

Choose a reason for hiding this comment

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

Should this be checked?

if (! ctx.real_mode_target)
return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate real mode pages");

{
grub_relocator_chunk_t ch;
grub_size_t sz;

if (grub_add (ctx.real_size, efi_mmap_size, &sz))
if (grub_add (ctx.real_size, efi_mmap_size + ap_wake_block_size, &sz))

Choose a reason for hiding this comment

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

Use grub_add() here too?

grub-core/loader/i386/txt/verify.c Outdated Show resolved Hide resolved
grub-core/loader/multiboot_elfxx.c Show resolved Hide resolved

for (i = 0, cur = modules; i < modcnt; i++, cur = cur->next)
{
grub_slaunch_add_slrt_policy_entry (17,

Choose a reason for hiding this comment

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

Where does 17 come from?

grub-core/loader/i386/txt/txt.c Outdated Show resolved Hide resolved
grub-core/loader/i386/slaunch.c Outdated Show resolved Hide resolved
grub-core/loader/i386/linux.c Show resolved Hide resolved
Comment on lines +132 to +133
info_table_size = __builtin_offsetof (struct grub_txt_acm_info_table, length)
+ sizeof(ptr->length);

Choose a reason for hiding this comment

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

I thought stddef.h is available in freestanding code. On my system (GCC with Fedora 39) it is provided by the compiler, not libc, and it only provides definitions for macros, structs, and typedefs that are defined by the compiler.

return proc_id_list;
}

static int

Choose a reason for hiding this comment

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

typedef _Bool bool? That said, I thought <stdbool.h> was available even in freestanding mode. You don’t get a libc in freestanding mode, but <stdbool.h> is the compiler’s job to provide, not libc’s.

grub-core/loader/i386/txt/acmod.c Show resolved Hide resolved
grub-core/loader/i386/txt/verify.c Outdated Show resolved Hide resolved
include/grub/i386/linux.h Show resolved Hide resolved
include/grub/slr_table.h Outdated Show resolved Hide resolved
include/grub/slr_table.h Show resolved Hide resolved
Comment on lines +246 to +258
/* Can read the size field of next entry? */
if ( grub_add (addr, sizeof(*next), &addr) )
return NULL;

/* Does next element's header fit within the table? */
if (addr >= grub_slr_end_of_entries (table))
return NULL;

next = (struct grub_slr_entry_hdr *) (addr - sizeof(*next));

/* Does next element fit within the table? */
if (grub_slr_end_of_entries (table) - (addr - sizeof(*next)) < next->size)
return NULL;

Choose a reason for hiding this comment

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

Suggested change
/* Can read the size field of next entry? */
if ( grub_add (addr, sizeof(*next), &addr) )
return NULL;
/* Does next element's header fit within the table? */
if (addr >= grub_slr_end_of_entries (table))
return NULL;
next = (struct grub_slr_entry_hdr *) (addr - sizeof(*next));
/* Does next element fit within the table? */
if (grub_slr_end_of_entries (table) - (addr - sizeof(*next)) < next->size)
return NULL;
/* Does next element's header fit within the table? */
if (addr >= grub_slr_end_of_entries (table) - sizeof(*next))
return NULL;
next = (struct grub_slr_entry_hdr *) addr);
/* Does next element fit within the table? */
if (grub_slr_end_of_entries (table) - addr < next->size)
return NULL;
/* Does next element include a header? */
if (next->size < sizeof(*next))
return NULL;

Copy link
Member Author

@krystian-hebel krystian-hebel left a comment

Choose a reason for hiding this comment

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

@DemiMarie could you mark discussions as resolved wherever you're happy with the change?

grub-core/loader/i386/txt/acmod.c Show resolved Hide resolved
grub-core/loader/i386/linux.c Show resolved Hide resolved
Comment on lines +132 to +133
info_table_size = __builtin_offsetof (struct grub_txt_acm_info_table, length)
+ sizeof(ptr->length);
Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I've mistook it with stdint.h, which in theory is available since C99, but compilers still have problems with it.

In any case, GRUB seems to avoid standard headers in core code, except for stdarg.h. They are used in OS utilities and libraries, but not in the bootloader itself, so I don't feel comfortable including it just for this.

return proc_id_list;
}

static int
Copy link
Member Author

Choose a reason for hiding this comment

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

Same reasoning as above.

include/grub/i386/linux.h Show resolved Hide resolved
include/grub/slr_table.h Show resolved Hide resolved
Copy link

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

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

Looks good!

docs/grub.texi Show resolved Hide resolved
grub-core/lib/i386/relocator32.S Show resolved Hide resolved
include/grub/slr_table.h Show resolved Hide resolved
Comment on lines +247 to +273
if (!entry) /* Start from the beginning */
entry = (struct grub_slr_entry_hdr *)((grub_uint8_t *) table + sizeof(*table));

Choose a reason for hiding this comment

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

That falls into the “input is known trusted here” case.

Comment on lines +66 to +67
#define GRUB_MSR_EFER_LME (1<<8) /* Enable Long Mode/IA-32e */
#define GRUB_MSR_EFER_LMA (1<<10) /* Long Mode/IA-32e Active */

Choose a reason for hiding this comment

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

For some reason I could not find this in my copy, probably because I was not looking at the right place. Consider this resolved.

Comment on lines +281 to +288
GRUB_MOD_INIT (slaunch)
{
cmd_slaunch = grub_register_command ("slaunch", grub_cmd_slaunch,
NULL, N_("Enable secure launcher"));
cmd_slaunch_module = grub_register_command ("slaunch_module", grub_cmd_slaunch_module,
NULL, N_("Load secure launcher module from file"));
cmd_slaunch_state = grub_register_command ("slaunch_state", grub_cmd_slaunch_state,
NULL, N_("Display secure launcher state"));

Choose a reason for hiding this comment

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

This can be resolved.

Comment on lines +132 to +133
info_table_size = __builtin_offsetof (struct grub_txt_acm_info_table, length)
+ sizeof(ptr->length);

Choose a reason for hiding this comment

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

That’s fine, you can resolve this.

return proc_id_list;
}

static int

Choose a reason for hiding this comment

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

I see. Not worth blocking merge.

grub-core/loader/i386/txt/acmod.c Show resolved Hide resolved
include/grub/i386/slaunch.h Show resolved Hide resolved
N_("TXT heap is not configured correctly"));

bios_size = grub_txt_bios_data_size (txt_heap);
/* We support versions >= 4, but bios_data->mle_flags is in versions >= 5. */
Copy link
Member Author

Choose a reason for hiding this comment

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

Great, SNB_IVB_SINIT_20190708_PW.bin is version 4 but it has mle_flags. Fu Thanks, Intel.

Some of the commands declared in header files will be implemented in
the follow-up commits.

Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
@krystian-hebel krystian-hebel force-pushed the intel-txt-aem-2.06-testing branch from efdb40d to d57eb43 Compare February 13, 2024 19:32
@DemiMarie
Copy link

@DemiMarie could you mark discussions as resolved wherever you're happy with the change?

GitHub isn’t allowing it, sadly.

Copy link

@DemiMarie DemiMarie left a comment

Choose a reason for hiding this comment

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

Looks okay

@krystian-hebel
Copy link
Member Author

Those two sneaky errors were breaking boot on Optiplex... I'll redo the same tests on HP just in case before clearing debug output and finally preparing patches for qubes-grub2

Provide definitions of structures and basic functions for constructing
and parsing of SLRT.

Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
rossphilipson and others added 8 commits February 20, 2024 21:06
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Signed-off-by: Ross Philipson <ross.philipson@oracle.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
GRUB_MULTIBOOT(get_mbi_size) doesn't look like an accurate source of the
final size, more like a minimal memory buffer size.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
The code makes sure that MBI entry goes first in DRTM, so the payload
can measure it first on launch.

SLRT table is allocated on the heap first, size for it is reserved
inside TXT heap by TXT code and data is later copied into its final
place.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Signed-off-by: Michał Żygowski <michal.zygowski@3mdeb.com>
Signed-off-by: Tomasz Żyjewski <tomasz.zyjewski@3mdeb.com>
Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
@krystian-hebel krystian-hebel force-pushed the intel-txt-aem-2.06-testing branch from 9dc582a to 58c9a06 Compare February 20, 2024 20:07
@krystian-hebel
Copy link
Member Author

No regression on HP, debug output cleared, fixes squashed to appropriate commits. Running per-commit build test (for bisectability) and will send patches tomorrow.

krystian-hebel added a commit to 3mdeb/qubes-grub2 that referenced this pull request Feb 21, 2024
Reviewed on TrenchBoot/grub#16

Signed-off-by: Krystian Hebel <krystian.hebel@3mdeb.com>
@marmarek
Copy link
Contributor

@DemiMarie can you send me signed message with commit ID which you approve (can be pasted clearsigned here, or via email)?

@SergiiDmytruk
Copy link
Member

SergiiDmytruk commented Aug 20, 2024

Cleanup: @krystian-hebel, so this got upstreamed and we won't need this PR and branches anymore?

@krystian-hebel
Copy link
Member Author

@krystian-hebel, so this got upstreamed and we won't need this PR and branches anymore?

FSVO upstreamed, it was implemented in Qubes GRUB repo. Can be closed.

@krystian-hebel krystian-hebel deleted the intel-txt-aem-2.06-testing branch August 26, 2024 11:53
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.

6 participants