Re: [PATCH] x86/sev: get the AP jump table address from secrets page

From: Borislav Petkov
Date: Wed Apr 20 2022 - 14:31:04 EST


On Wed, Apr 20, 2022 at 10:27:51AM -0500, Michael Roth wrote:
> +static u64 get_secrets_page(void)
> +{
> + u64 pa_data = boot_params.cc_blob_address;
> + struct cc_blob_sev_info info;
> + void *map;
> +
> + /*
> + * The CC blob contains the address of the secrets page, check if the
> + * blob is present.
> + */
> + if (!pa_data)
> + return 0;
> +
> + map = early_memremap(pa_data, sizeof(info));

That function can return NULL so you need to handle it.

> + memcpy(&info, map, sizeof(info));
> + early_memunmap(map, sizeof(info));
> +
> + /* smoke-test the secrets page passed */
> + if (!info.secrets_phys || info.secrets_len != PAGE_SIZE)
> + return 0;
> +
> + return info.secrets_phys;
> +}
> +
> +static u64 get_snp_jump_table_addr(void)
> +{
> + struct snp_secrets_page_layout *layout;
> + u64 pa = get_secrets_page();
> + u64 addr;

Please don't hide the function call in the local variables declaration
but do this instead:

struct snp_secrets_page_layout *layout;
u64 pa, addr;

pa = get_secrets_page();
if (!pa)
return 0;

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette