ISR Customization

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

Re: ISR Customization

Post by SoulofDeity »

bluemoon wrote:
SoulofDeity wrote:I'm saying that the sub-idt would be cut off from low level functions such as modifying the real idt
No. any ring0 code can read&write IDT by SIDT, map it, LIDT, this including code injection - all supported by the CPU itself and do not require kernel call.
If your driver is not running ring0, I then do not see any advantage over traditional event mechanism.
No it can't. The sub-idt can only be modified from a kernel-mode process whose idt hasn't been remapped (aka. the process that executed it).
bluemoon wrote:
SoulofDeity wrote:modifying drivers
I'm not sure why should on modify driver, but with a bit of reverse engineering(If the Os worth spending any effort at all), it should be possible to figure out the mechanism and data structures of permission, and grant permission, then it can call standard kernel/DDK function for driver manipulation.
I plan on encrypting all the kernel code with AES-256 to prevent that :P
bluemoon wrote:
SoulofDeity wrote:Once the ISR's have been remapped, it can't be undone
No. The ISR can be freely modified anytime by bad drivers.
Of course the IDT can be modified by the drivers :P I'm saying that it's impossible to remap the IDT from a process using a sub-idt.
bluemoon wrote:
SoulofDeity wrote:...the applications cannot modify the kernel in RAM or on the hard disk.
Simple not true. Ring0 grant access to take over the whole machine.
The plan is that the task-manager will keep track of processes using sub-idt's and ensure they are always in user mode. So even if they enter kernel mode, they'll just be shoved back into user mode.


I'm sorry I can't really explain the concept very well... :P
The point is, I myself know it'll work. If anyone can tell me a better way to hook the ISR's, I'd be grateful.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ISR Customization

Post by Combuster »

No it can't. The sub-idt can only be modified from a kernel-mode process whose idt hasn't been remapped
The world minus you says any kernel task can. So obviously something is going wrong in your head.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: ISR Customization

Post by JamesM »

I plan on encrypting all the kernel code with AES-256 to prevent that
As a sidenote, whenever someone says "I'll use encryption to solve that", the hairs on the back of my neck stand on end as I wonder exactly how much that person knows about attack vectors and making a secure system...
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: ISR Customization

Post by bluemoon »

SoulofDeity wrote:If anyone can tell me a better way to hook the ISR's, I'd be grateful.
Think about how CPU handle interrupts.
1. lookup (cached) IDT
2. Getting CS:E/RIP, Stack/Task switch, etc (refer to manual)
3. Execute the code from the destination address

So, here are some choices:
1. flush IDT upon every context switch, which is impractically slow.
2. Remap the paged memory pointed by ISR with different region of physical memory.

If you are fine with additional lookup chain:
3. Give each process a dedicated kernel stack, so the ISR can de-reference some ID number on the stack and brach to different handlers
4. Abuse process's pid to lookup a table and do chaining.

However, doing long chain without EOI/IRET quickly may cause problems, then upon you improve it you may end up having a traditional signal/IPC mechanism for delayed handling of event, instead of inline handler.

Bottom line, this cannot boost performance as it either pollute cache or doing some overhead; and this provide no security enhancement over standard IPC model.
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

Re: ISR Customization

Post by SoulofDeity »

Combuster wrote:
No it can't. The sub-idt can only be modified from a kernel-mode process whose idt hasn't been remapped
The world minus you says any kernel task can. So obviously something is going wrong in your head.
How my kernel handles sub-idt's is entirely my choice, and I plan to design it in such a way that it doesn't give a damn whether the process is in kernel-mode or not, if you're using a sub-idt, you're not gonna remap it. There's no need to be so arrogant.
JamesM wrote:
SoulofDeity wrote:I plan on encrypting all the kernel code with AES-256 to prevent that
As a sidenote, whenever someone says "I'll use encryption to solve that", the hairs on the back of my neck stand on end as I wonder exactly how much that person knows about attack vectors and making a secure system...
The closest anyone has every gotten to cracking the rijindael encryption was 'theoretically' reducing the encryption key by 2-bits. I'm not saying it's impossible, I mean if they wanted to they could simply dump the ram with some hardware gizmos and disassemble it, but if the kernel keeps shoving them into user mode and they can't make a kernel-mode binary without the keys, any software attacks would be futile.
bluemoon wrote:
SoulofDeity wrote:If anyone can tell me a better way to hook the ISR's, I'd be grateful.
Think about how CPU handle interrupts.
1. lookup (cached) IDT
2. Getting CS:E/RIP, Stack/Task switch, etc (refer to manual)
3. Execute the code from the destination address

So, here are some choices:
1. flush IDT upon every context switch, which is impractically slow.
2. Remap the paged memory pointed by ISR with different region of physical memory.

If you are fine with additional lookup chain:
3. Give each process a dedicated kernel stack, so the ISR can de-reference some ID number on the stack and brach to different handlers
4. Abuse process's pid to lookup a table and do chaining.

However, doing long chain without EOI/IRET quickly may cause problems, then upon you improve it you may end up having a traditional signal/IPC mechanism for delayed handling of event, instead of inline handler.

Bottom line, this cannot boost performance as it either pollute cache or doing some overhead; and this provide no security enhancement over standard IPC model.
Thanks for actually posting a solution :D

1. kinda agree this would be slow

2. sounds decent, but it might be really messy to implement

I'm not entirely sure I understand 3 and 4 :/

------------------------------------------

I have a feeling I've confused everyone about this, so I'm gonna try to re-explain from the start:

Kernel processes can start other processes that have a custom interrupt table called the sub-idt. The actual sub-idt and it's functions are located in the memory space of the calling process so only the calling process can modify it. Whenever an interrupt is executed, the handler is looked up in the sub-idt and executed. The task-manager ensures that processes that use a sub-idt are always in user-mode before executing anything.

Security-wise, this means that process can't remap the real idt (or their own sub-idt without the calling process's permission), can't access kernel data, and the calling process can restrict their access to certain resources (such as using external libraries or reading/writing to certain files or ports).
Outside that, it also makes it possible to log all interrupts called by a process for debugging and improves the performance of virtualized processes by reducing load time, cutting down on memory use, and removing the need for them to be interpreted or dynamically recompiled.

Note that not ALL processes will be run using a sub-idt, it is merely used as a sandbox-environment or a way to simplify virtualizing software.

Honestly, that's the best I can explain it and I hope that clears up some confusion. :?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: ISR Customization

Post by Combuster »

SoulofDeity wrote:Thanks for actually posting a solution :D
Feel free to blatantly ignore the "It's broken, don't do it" as the repeatedly cited solution. :roll:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
SoulofDeity
Member
Member
Posts: 193
Joined: Wed Jan 11, 2012 6:10 pm

Re: ISR Customization

Post by SoulofDeity »

Combuster wrote:
SoulofDeity wrote:Thanks for actually posting a solution :D
Feel free to blatantly ignore the "It's broken, don't do it" as the repeatedly cited solution. :roll:
will do. most ingenious ideas were once considered flat-out ignorant :P
Post Reply