lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAC_iWj+C+HmC=8BN+ZvGt2QV1p=+8mP8rTjT1VsUUGoCioHHPQ@mail.gmail.com>
Date: Mon, 25 Aug 2025 11:12:42 +0300
From: Ilias Apalodimas <ilias.apalodimas@...aro.org>
To: Jan Kiszka <jan.kiszka@...mens.com>
Cc: Ard Biesheuvel <ardb@...nel.org>, Masahisa Kojima <kojima.masahisa@...ionext.com>, 
	linux-efi@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Sumit Garg <sumit.garg@...nel.org>, Jens Wiklander <jens.wiklander@...aro.org>, 
	Hua Qian Li <huaqian.li@...mens.com>
Subject: Re: [PATCH v2 1/4] efi: stmm: Fix incorrect buffer allocation method

Thanks Jan

On Sat, 23 Aug 2025 at 20:22, Jan Kiszka <jan.kiszka@...mens.com> wrote:
>
> From: Jan Kiszka <jan.kiszka@...mens.com>
>
> The communication buffer allocated by setup_mm_hdr is later on passed to
> tee_shm_register_kernel_buf. The latter expects those buffers to be
> contiguous pages, but setup_mm_hdr just uses kmalloc. That can cause
> various corruptions or BUGs, specifically since 9aec2fb0fd5e, though it
> was broken before as well.
>
> Fix this by using alloc_pages_exact instead of kmalloc.
>
> Fixes: c44b6be62e8d ("efi: Add tee-based EFI variable driver")
> Signed-off-by: Jan Kiszka <jan.kiszka@...mens.com>

Acked-by: Ilias Apalodimas <ilias.apalodimas@...aro.org>

> ---
>  drivers/firmware/efi/stmm/tee_stmm_efi.c | 21 ++++++++++++---------
>  1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/firmware/efi/stmm/tee_stmm_efi.c b/drivers/firmware/efi/stmm/tee_stmm_efi.c
> index f741ca279052..e15d11ed165e 100644
> --- a/drivers/firmware/efi/stmm/tee_stmm_efi.c
> +++ b/drivers/firmware/efi/stmm/tee_stmm_efi.c
> @@ -143,6 +143,10 @@ static efi_status_t mm_communicate(u8 *comm_buf, size_t payload_size)
>         return var_hdr->ret_status;
>  }
>
> +#define COMM_BUF_SIZE(__payload_size)  (MM_COMMUNICATE_HEADER_SIZE + \
> +                                        MM_VARIABLE_COMMUNICATE_SIZE + \
> +                                        (__payload_size))
> +
>  /**
>   * setup_mm_hdr() -    Allocate a buffer for StandAloneMM and initialize the
>   *                     header data.
> @@ -173,9 +177,8 @@ static void *setup_mm_hdr(u8 **dptr, size_t payload_size, size_t func,
>                 return NULL;
>         }
>
> -       comm_buf = kzalloc(MM_COMMUNICATE_HEADER_SIZE +
> -                                  MM_VARIABLE_COMMUNICATE_SIZE + payload_size,
> -                          GFP_KERNEL);
> +       comm_buf = alloc_pages_exact(COMM_BUF_SIZE(payload_size),
> +                                    GFP_KERNEL | __GFP_ZERO);
>         if (!comm_buf) {
>                 *ret = EFI_OUT_OF_RESOURCES;
>                 return NULL;
> @@ -239,7 +242,7 @@ static efi_status_t get_max_payload(size_t *size)
>          */
>         *size -= 2;
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> @@ -282,7 +285,7 @@ static efi_status_t get_property_int(u16 *name, size_t name_size,
>         memcpy(var_property, &smm_property->property, sizeof(*var_property));
>
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> @@ -347,7 +350,7 @@ static efi_status_t tee_get_variable(u16 *name, efi_guid_t *vendor,
>         memcpy(data, (u8 *)var_acc->name + var_acc->name_size,
>                var_acc->data_size);
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> @@ -404,7 +407,7 @@ static efi_status_t tee_get_next_variable(unsigned long *name_size,
>         memcpy(name, var_getnext->name, var_getnext->name_size);
>
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> @@ -467,7 +470,7 @@ static efi_status_t tee_set_variable(efi_char16_t *name, efi_guid_t *vendor,
>         ret = mm_communicate(comm_buf, payload_size);
>         dev_dbg(pvt_data.dev, "Set Variable %s %d %lx\n", __FILE__, __LINE__, ret);
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> @@ -507,7 +510,7 @@ static efi_status_t tee_query_variable_info(u32 attributes,
>         *max_variable_size = mm_query_info->max_variable_size;
>
>  out:
> -       kfree(comm_buf);
> +       free_pages_exact(comm_buf, COMM_BUF_SIZE(payload_size));
>         return ret;
>  }
>
> --
> 2.43.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ