ot memory allocation question

Don Raikes don.raikes at oracle.com
Fri Jul 19 05:53:23 EDT 2013


Sorry folks, but I still have a question about all this kernel programming stuff.

 

Is it possible from within a kernel module to allocate memory in userspace?

 

The reason I am asking is the function I am hooking into sys_write takes a buffer as input, but the buffer is defined as const __user *.

 

To me this means that if I modify the text that I was given in the buffer and want it to get written to the file, then I need to update the buffer.

However since the buffer is a const, I shuldn't write to it, plus in my case I am enlarging the amount of data, so if I were to cast the buffer to a writable __user *, then I am in danger of overwriting something I shouldn't in the user process (which in my case is the file pointer).

 

After completing the sys_write by passing the updated buffer to the original sys_write, I try to close the file and get an error.

 

My solution:

Allocate a new larger buffer inside of the userspace and copy_to_user into the new buffer and then when I pass control to the "real" sys_write function point it to the new buffer.

 

But the problem is how do I allocate this new buffer?

-- 
Best Regards, Donald

HYPERLINK "http://www.oracle.com/" \nOracle
Donald raikes | Accessibility Specialist/ QA Engineer
Phone: HYPERLINK "tel:+15202717608"+15202717608 | Mobile: HYPERLINK "tel:+15202717608"+15202717608 
Oracle Quality Assurance
| Tucson, Arizona 

HYPERLINK "http://www.oracle.com/commitment" \nGreen Oracle

Oracle is committed to developing practices and products that help protect the environment

 


More information about the Speakup mailing list