Is it OK to allocating memory in usermode process from kernel?

title is obscure, my purpose is: i want my usermode application can read a unknown sized data like registry value’s data, and i try this method:

  1. KeStackAttachProcess/KeUnstackDetachProcess to attach to my process.
  2. call ZwAllocateVirtualMemory to allocating memory, then copy data to returned memory pointer.
  3. send to process at least 2 informations: size of data and pointer to that data, so process can read correctly.
  4. free all after read.

i tried this method and usermode process can read that data correctly.
my question is: is this a good approach to solve my problem? any other good methods?
thank you.

P/S: mods please move this topic to NTDEV, thanks.

Why the gymnastics? Have the app send a request to determine the size and then another request to get the data. This is a pretty standard I/O pattern in Windows.

im deving a minifilter, anytime an “editing event” occur like registry value editing, registry delete, etc… my driver will notify to the user with FltSendMessage, then receive a reply message. ask how many bytes first seem its more complicated.
so i just wanna send once to my app with data size and pointer to that data, not send the request first. thanks.

P/S: for example: when editing a registry value, i will send data in that value to my app too, and that size might be up to 1MB, its big. i just wanna find an easier way to read message send from driver in my app.
https://docs.microsoft.com/en-us/windows/win32/sysinfo/registry-element-size-limits

Ooooh, it’s a Communication Port…

For as great as they are the API doesn’t handle variable length messages very well. Usually the done thing is to have user mode send max size buffers and the driver sends variable length messages to fill those buffers.

1 MB is small. You can allocate many hundreads of buffers of this size on a typical desktop