All of lore.kernel.org
 help / color / mirror / Atom feed
[parent not found: < <CAFA6WYPFjiOhTnyi-NFCMhiXdsQr7Ro_YzXY-20Gg4e57Y8tEA@mail.gmail.com>]
[parent not found: < <CAFA6WYNNTr0O60ggowzqpJVso5cySO=peBTBTzVm9MzZy8b4ww@mail.gmail.com>]
* drivers/tee double-free of page when optee_shm_register fails
@ 2021-12-10 14:53 Lars Persson
  2021-12-14  7:41 ` Sumit Garg
  0 siblings, 1 reply; 7+ messages in thread
From: Lars Persson @ 2021-12-10 14:53 UTC (permalink / raw)
  To: op-tee

[-- Attachment #1: Type: text/plain, Size: 1339 bytes --]

Hi

Me and Patrik have been tracing a kernel memory corruption bug that is 
triggered when op-tee runs out of resources and returns an error from 
the OPTEE_MSG_CMD_REGISTER_SHM call. This is yet another fall-out from 
Patrik's fuzzing of the TEE subsystem.

The symptoms would look like this when page debugging is enabled:
BUG: Bad page state in process optee_example_h  pfn:46bb0
page:(ptrval) refcount:-1 mapcount:0 mapping:00000000 index:0x0 pfn:0x46bb0
flags: 0x0(zone=0)

Our reproducer runs a loop with the TEE_IOC_SHM_ALLOC until memory runs 
out at the optee-os end (dynamic SHM enabled). The error is 100% 
reproducible with such a loop.

We have traced this down to what seems to be a miss in the memory 
ownership contract during the call to OPTEE_MSG_CMD_REGISTER_SHM.

When pool_op_alloc() detects that optee_shm_register() has failed, it 
will free the allocated page at the very end of the function. 
Unfortunately that page has already been freed because OP-TEE has sent a 
OPTEE_RPC_CMD_SHM_FREE for this shm object before returning from 
OPTEE_MSG_CMD_REGISTER_SHM. This is my conclusion based on prints added 
to the code.

I cannot write a patch for this because I am at a loss of who actually 
is supposed to trigger the free of the pages in this situation. Is there 
an API spec that makes this clear ?

BR,
  Lars

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-12-16  8:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] < <CAFA6WYObPg3gTh9Vas55ae7AhRHWHV7sLNq8=BPNYKqK2aXS8g@mail.gmail.com>
2021-12-14 11:25 ` drivers/tee double-free of page when optee_shm_register fails Patrik Lantz
2021-12-15 10:27   ` Sumit Garg
     [not found] < <CAFA6WYPFjiOhTnyi-NFCMhiXdsQr7Ro_YzXY-20Gg4e57Y8tEA@mail.gmail.com>
2021-12-16  8:09 ` Patrik Lantz
     [not found] < <CAFA6WYNNTr0O60ggowzqpJVso5cySO=peBTBTzVm9MzZy8b4ww@mail.gmail.com>
2021-12-14  8:30 ` Patrik Lantz
2021-12-14  9:55   ` Sumit Garg
2021-12-10 14:53 Lars Persson
2021-12-14  7:41 ` Sumit Garg

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.