From: Sumit Garg <sumit.garg@kernel.org>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Ard Biesheuvel <ardb@kernel.org>,
linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org,
Jens Wiklander <jens.wiklander@linaro.org>,
Masahisa Kojima <kojima.masahisa@socionext.com>
Subject: Re: [PATCH 1/3] efi: stmm: Fix incorrect buffer allocation method
Date: Thu, 21 Aug 2025 15:05:31 +0530 [thread overview]
Message-ID: <aKboY9oBmHJJb2Pc@sumit-X1> (raw)
In-Reply-To: <75db5f5e-9e0c-4c48-a3c8-034414276036@siemens.com>
Hi Jan,
On Wed, Aug 20, 2025 at 05:05:43PM +0200, Jan Kiszka wrote:
> On 20.08.25 09:29, Ilias Apalodimas wrote:
> > (++cc Sumit and Kojima-san on their updated emails)
> >
> > On Fri, 15 Aug 2025 at 22:12, Jan Kiszka <jan.kiszka@siemens.com> wrote:
> >>
> >> From: Jan Kiszka <jan.kiszka@siemens.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@siemens.com>
> >> ---
> >
> > [...]
> >
> >> const efi_guid_t mm_var_guid = EFI_MM_VARIABLE_GUID;
> >> struct efi_mm_communicate_header *mm_hdr;
> >> @@ -173,9 +174,12 @@ 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);
> >> + *nr_pages = roundup(MM_COMMUNICATE_HEADER_SIZE +
> >> + MM_VARIABLE_COMMUNICATE_SIZE + payload_size,
> >> + PAGE_SIZE) / PAGE_SIZE;
> >> +
> >> + comm_buf = alloc_pages_exact(*nr_pages * PAGE_SIZE,
> >> + GFP_KERNEL | __GFP_ZERO);
> >
> > Rename nr_pages to something else and skip division, multiplying.
> > Unless there's a reason I am missing?
> > Also doesn't alloc_pages_exact() already rounds things up?
>
> I was looking at tee_dyn_shm_alloc_helper and the dance it does to
> calculate the pages from the size parameter.
The rework of tee_shm_register_kernel_buf() is directly accept kernel
pages instead of buffer pointers is already due. If you are willing to
fix existing TEE client drivers and the API then I will be happy to
review them.
-Sumit
next prev parent reply other threads:[~2025-08-21 9:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-15 19:12 [PATCH 0/3] efi: stmm: Fix for incorrect buffer allocation and cleanups Jan Kiszka
2025-08-15 19:12 ` [PATCH 1/3] efi: stmm: Fix incorrect buffer allocation method Jan Kiszka
2025-08-20 7:29 ` Ilias Apalodimas
2025-08-20 15:05 ` Jan Kiszka
2025-08-21 9:35 ` Sumit Garg [this message]
2025-08-21 12:56 ` Jan Kiszka
2025-08-22 9:07 ` Sumit Garg
2025-08-15 19:12 ` [PATCH 2/3] efi: stmm: Use EFI return code of setup_mm_hdr Jan Kiszka
2025-08-20 7:10 ` Ilias Apalodimas
2025-08-20 14:59 ` Jan Kiszka
2025-08-21 13:00 ` Jan Kiszka
2025-08-21 13:26 ` Ilias Apalodimas
2025-08-15 19:12 ` [PATCH 3/3] efi: stmm: Drop unneeded null pointer check Jan Kiszka
2025-08-20 6:44 ` Ilias Apalodimas
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=aKboY9oBmHJJb2Pc@sumit-X1 \
--to=sumit.garg@kernel.org \
--cc=ardb@kernel.org \
--cc=ilias.apalodimas@linaro.org \
--cc=jan.kiszka@siemens.com \
--cc=jens.wiklander@linaro.org \
--cc=kojima.masahisa@socionext.com \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox