Hi,
JAAman wrote:1) you increase task-switch overhead since you must modify the TSS on each task switch (although im thinking... what if device drivers each had their own TSS, then a generic one for all others... this would allow you to just change it instead of modifying it on each switch)
A bitmap with one bit per I/O port costs 8 KB. If you support a maximum of 8192 tasks, then it'll cost a maximum of 64 MB just for I/O permission bitmaps. That is far too much.
Instead, each process could have a "I don't use any I/O ports" flag, and you could have a shared "no I/O port access allowed" TSS. That would reduce the memory consumption a lot (e.g. for 50 device drivers it'd only cost 400 KB), but then your task switch code becomes something like:
Code: Select all
if(new_task_uses_IO_ports) {
copy_IO_bitmap();
} else {
if(old_task_used_IO_ports) {
wipe_IO_bitmap();
}
}
That's 2 branches (and up to 2 branch mispredictions per task switch) plus the cost of "rep movsd" or "rep stosd" added to the worst case task switch times.
Instead, I can have an array that says which process owns each I/O port. It costs 256 KB (4 bytes per I/O port) and nothing needs to be done during task switches. Given that my OS/kernel is modular, this helps reduce the dependancies between modules (e.g. I can have a "scheduler module" and a "hardware support module", where both modules don't need to care what each other do). Also, because my OS uses a lot of event-driven programming there's lots more task switches than there would be in a normal monolithic system, so reducing the overhead of task switches makes more sense.
zeii wrote:don't get me wrong, but isn't that the point of a device driver?
I mean, A driver needs to know the port addresses of the hardware it is trying to access. It doesn't necessarily have to use the ABSOLUTE addresses in action.
I mean... lets look at this.
Driver:"Hi, I'm a driver for the VIA 8237 Audio chipset!"
Kernel: "Hey dude, no problem. What IRQs, Ports do you require to control the device?"
Driver:"Er... Im not so sure, man. last night is kind of blurry..."
Kernel: "I see..." <kernel kills driver>
In a monolithic kernel, the kernel assumes that device drivers can be trusted because they're part of the kernel. For a micro-kernel, device drivers are just seperate pieces of code (like applications), and shouldn't be trusted. In this case the kernel should give them just enough access to do their job, but no more.
Consider this:
Driver: Hi, I'm a driver for the VIA 8237 Audio chipset!
Kernel: Hey dude, no problem. What IRQs, Ports do you require to control the device?
Driver: I want access to all these I/O ports [Driver sends list of I/O ports to Kernel]
Kernel: Hmm, OK I guess....
Driver: Sucker! [Computer crashes as malicious driver turns off A20]
For my OS it works more like this:
Device Manager: I just found a VIA 8237 Audio chipset during the PCI bus scan!
Device Manager: Hmm, according to the device's PCI configuration space, this device needs some I/O ports. I guess I can assign I/O ports 0x1234 to 0x1345 to this device.
Device Manager: Now I'll see if there's a device driver for it....
Device Manager: Woot! Found a device driver [various grunting noises as the device driver is started]
Device Manager: Hey kernel - I'm starting this device driver, and it needs to be able to access I/O ports 0x1234 to 0x1345. Can you make it happen?
Kernel: You are the official Device Manager, and there's no other problems. Approved.
Device Manager: Thanks Kernel!
Driver: Hello?
Device Manager: Hi audio driver. Today you'll be using IRQ #33, and I/O ports 0x1234 to 0x1345.
Driver: Cool - initializing
Driver: Hey, everything is working!
Device Manager: Good. I'll tell the user interface to talk to you
UI: Hello sound driver
Driver: Hello UI. I can do MIDI and have 5 channel surround sound!
UI: That's nice. For now just play this aweful startup jingle.
Driver: Ok
Of course security should go further than this. Should a keyboard driver be able to use networking and send keypresses to some dodgy server on the internet? No. Should a network card driver be able to open the file "/etc/passwd"? No. Should a sound card driver be able to tell the kernel it's a disk driver and get access to data that applications send to swap space? No.
For systems like Windows and Linux there really isn't enough device driver security built into the system, and to get around that there's digitally signed drivers and Windows Hardware Quality Lab (WHQL) tests, or you need to spend months arguing with Kernel maintainers to get your driver into the kernel source code tree. I simply don't have enough cash or time to do things that way.
Cheers,
Brendan