Make sure of new instructions, support old processors.

Programming, for all ages and all languages.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Make sure of new instructions, support old processors.

Post by JamesM »

Hi Brendan,
IMHO using self modifying code (e.g. copying the best version of some code into a fixed location) is usually a bad idea - it means that your code needs to be writable and can be modified by bugs (e.g. uninitialized pointer) or malicious code (e.g. bad plugins or libraries). The overhead of modifying the code is often larger than the overhead of using function pointers and/or conditional branches (assuming function pointers and/or conditional branches are used sensibly). Worst case is if the OS supports memory mapped executable files; where unmodified pages are loaded from the file system if/when needed and can be freed at any time to save RAM. In this case modified pages would need to loaded from disk when they're modified, then sent to swap to reclaim the RAM, and then reloaded from swap if/when needed; which either means a lot more file I/O, or means that less RAM is left free for more important things.
Your response seems to be based on the assumption that the OP is developing in a hosted environment. A scan-read didn't tell me this, maybe I missed something?

In a hosted environment your points are valid, however my advice was aimed at being for an OS kernel; in which case noexecute has no effect, bugs and malicious code neither as you're in kernel mode - anything can be destroyed!
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Make sure of new instructions, support old processors.

Post by Owen »

Code which can call your mprotect (or similar) system call can already run anyway. The exception is code which uses a Return-to-libc attack to carefully return to libc to call mprotect to undo your protection. The defense against this is address space layout randomization.
Post Reply