get_user_pages and pinning

Greg KH greg at kroah.com
Sat Jan 2 08:20:09 EST 2021


On Sat, Jan 02, 2021 at 07:39:08AM -0500, Sadanand Warrier wrote:
> Folks
>    Since Linux uses lazy evaluation with respect to allocating memory
> what happens if a user process allocates memory using malloc in excess
> of say 8 or nine pages and calls a device ioctl and passes the user
> space pointer to it to be used to pin pages using get_user_pages().
> This buffer is to be used for a dma read from a device.
> What happens if the memory isn't actually allocated (no initialization
> with memset or calloc etc. and all PTEs are pointing to some zero
> filled page) and there is no IOMMU?

You should get an error of -EFAULT when you try to do this when the
kernel tries to access memory you don't have.

But the best way to be sure is to actually try it yourself and see!
There's nothing preventing you from doing that, right?  :)

good luck!

greg k-h



More information about the Kernelnewbies mailing list