Modify user space from kernel.

Brooks Davis brooks at freebsd.org
Sat Jul 30 23:40:41 UTC 2016


On Fri, Jul 29, 2016 at 03:11:25PM +0200, Adam Starak wrote:
> Hello!
> 
> My name is Adam. I participate in Google Summer of Code this year. I came
> up with a big problem, which doesn't allow me to go further in my project.
> 
> I made a new syscall, which is going to retrieve sysctl data and put it
> inside the nvlist. And here my problem is. I need to move somehow this data
> (packed nvlist) into the user space. Is there any chance to pass data from
> kernel to user space without knowing the size of it?
> 
> Right now, the implementation of __sysctl() function requests void pointer
> and size in order to get data. If allocated memory is too low, it returns
> ENOMEM and you need to realloc the data. I wanted to avoid this situation.

If you want a memory based interface, that is what how it should be.  If
the size won't change, then you can output the required size on failure.
For example, if your syscall has a definition like:

int give_me_an_nvlist(void *buf, size_t *buflen);

On ENOMEM you'd write the required size to buflen.  If the list really
don't change size, requiring two system calls would be a lot cheaper and
easier to handle than a socket as someone else proposed.

-- Brooks

P.S. Purely as an FYI, there is technically another option.  You could
inject a set of page mappings into the process, write the nvlist to them,
and then return a pointer to them.  This would be fragile, prone to hard
to diagnose memory leaks, and would probably break all sorts of tools
like valgrind, but it's theoretically possible.  I seriously doubt such
an interface would be acceptable to the project.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20160730/542eb961/attachment.sig>


More information about the freebsd-hackers mailing list