All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Cc: u-boot@lists.denx.de, Alexander Graf <agraf@csgraf.de>,
	Masahisa Kojima <masahisa.kojima@linaro.org>
Subject: Re: [PATCH v2 3/4] efi_loader: simplify efi_sigstore_parse_sigdb()
Date: Sat, 2 Oct 2021 23:11:04 +0300	[thread overview]
Message-ID: <YVi82ApG0duWEc+z@apalos.home> (raw)
In-Reply-To: <20211002094227.119870-4-heinrich.schuchardt@canonical.com>

Hi Heinrich,

[...]

> @@ -740,44 +741,15 @@ err:
>   */
>  struct efi_signature_store *efi_sigstore_parse_sigdb(u16 *name)
>  {
> -	struct efi_signature_store *sigstore = NULL;
>  	const efi_guid_t *vendor;
>  	void *db;
>  	efi_uintn_t db_size;
> -	efi_status_t ret;
> -
> -	if (!u16_strcmp(name, L"PK") || !u16_strcmp(name, L"KEK")) {
> -		vendor = &efi_global_variable_guid;
> -	} else if (!u16_strcmp(name, L"db") || !u16_strcmp(name, L"dbx")) {
> -		vendor = &efi_guid_image_security_database;
> -	} else {
> -		EFI_PRINT("unknown signature database, %ls\n", name);
> -		return NULL;
> -	}
> -
> -	/* retrieve variable data */
> -	db_size = 0;
> -	ret = EFI_CALL(efi_get_variable(name, vendor, NULL, &db_size, NULL));
> -	if (ret == EFI_NOT_FOUND) {
> -		EFI_PRINT("variable, %ls, not found\n", name);
> -		sigstore = calloc(sizeof(*sigstore), 1);
> -		return sigstore;
> -	} else if (ret != EFI_BUFFER_TOO_SMALL) {
> -		EFI_PRINT("Getting variable, %ls, failed\n", name);
> -		return NULL;
> -	}
>  
> -	db = malloc(db_size);
> +	vendor = efi_auth_var_get_guid(name);
> +	db = efi_get_var(name, vendor, &db_size);
>  	if (!db) {
> -		EFI_PRINT("Out of memory\n");
> -		return NULL;
> -	}
> -
> -	ret = EFI_CALL(efi_get_variable(name, vendor, NULL, &db_size, db));
> -	if (ret != EFI_SUCCESS) {
> -		EFI_PRINT("Getting variable, %ls, failed\n", name);
> -		free(db);
> -		return NULL;
> +		EFI_PRINT("variable, %ls, not found\n", name);
> +		return calloc(sizeof(struct efi_signature_store), 1);

We are creating a security problem here.  The previous code,  before
returning a calloced buffer,   was specifically checking for EFI_NOT_FOUND.
The way this is restructured might lead to an weird situation.  There's a
chance efi_get_var() will return NULL, even if the variable is there (e.g
an alloc failed).  That's problematic if we want to check 'dbx' though.  The new
fucntion will return that empty buffer and we'll end up ignoring the 'dbx'
entries. 

Regards
/Ilias
>  	}
>  
>  	return efi_build_signature_store(db, db_size);
> -- 
> 2.32.0
> 

  reply	other threads:[~2021-10-02 20:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-02  9:42 [PATCH v2 0/4] efi_loader: centralize known vendor GUIDs Heinrich Schuchardt
2021-10-02  9:42 ` [PATCH v2 1/4] efi_loader: treat UEFI variable name as const Heinrich Schuchardt
2021-10-02  9:42 ` [PATCH v2 2/4] efi_loader: function to get GUID for variable name Heinrich Schuchardt
2021-10-02  9:42 ` [PATCH v2 3/4] efi_loader: simplify efi_sigstore_parse_sigdb() Heinrich Schuchardt
2021-10-02 20:11   ` Ilias Apalodimas [this message]
2021-10-02  9:42 ` [PATCH v2 4/4] efi_loader: simplify tcg2_measure_secure_boot_variable() Heinrich Schuchardt

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=YVi82ApG0duWEc+z@apalos.home \
    --to=ilias.apalodimas@linaro.org \
    --cc=agraf@csgraf.de \
    --cc=heinrich.schuchardt@canonical.com \
    --cc=masahisa.kojima@linaro.org \
    --cc=u-boot@lists.denx.de \
    /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.