简体   繁体   中英

How to perform a memory range check within the Linux kernel for non-userspace memory?

I am writing an API as a linux kernel module for another module. For initial development, I would like to do some memory range checking on the physical memory pointers being passed to my API. That way my module can help catch bugs in their module and my module cannot be blamed for bad pointers.

I know there are plenty of ways to check userspace pointers in the kernel for a valid memory. The problem is I have not found a prepackaged way to do range checking for physical memory that is accessible to the kernel.

Checking the normal kernel linear address ranges is certainly a possiblity (0x00000000 to 0xbfffffff and 0xc0000000 to 0xffffffff [Understanding the Linux Kernel 3rd ed]). Are there any functions or macros readily available in the kernel to do this and potentially better than my suggestion?

If they are really physical addresses you could use page_is_ram() .

You are probably getting kernel virtual addresses though, in which case you'll have to convert them first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM