Imagine any user-level application can access and modify all the processor registers,
including flags. Describe the danger of this possibility. Give example of what can go
wrong. Does this approach has any positive sides?
Imagine any user-level application can access and modify all the processor registers,
|
Banned
|
|
| 21Feb2012,23:06 | #1 |
|
Go4Expert Member
|
|
| 18Feb2013,15:59 | #2 |
|
Let's take only one and very clear example:
Any process can modify processor status register (or any equivalent register depending on the register naming and the processor in question). We have one bit telling are interrupts enabled or not. One process sets interrupts are not enabled any more. Then no interrupts will happen before next boot. The computer is frozen totally. |
|
Go4Expert Member
|
|
| 24Feb2013,20:42 | #3 |
|
Answer may be simple and may be clear. Still it is far from complete.
Reader can get an idea that necessarily if a process clears interrupt the system hangs.
|
|
Go4Expert Member
|
|
| 24Feb2013,20:56 | #4 |
|
1. An example of the case that disabling interrupts will not cause any harm:
Code:
int i;//Linux OS
main() {
_asm_ ("cli;");//We disable interrupts (Intel/AMD).
i=i/0;// Causes the divide by zero fault, faults can't be disabled.
while(1);
}
OS handles the fault and crashes the current task and starts an other with interrupts enabled. No harm done, because during some ns we have not lost anything important- hopefully. If we comment the line i=i/0 in the above code, the processor hangs until the next boot. 2. SMP (many processors): A "cli"-instruction most probably hangs only one processor running the "bad" task (can depend on the system and error handling of OS). What if we run (Linux) the code: Code:
int j;
main(){
for (j=0;j<100;j++)
if(fork())
{
sleep(5);//We sleep 5 seconds to wait tasks are divided to run queues of procssors, otherwise first running task with cli stops our experiment.
_asm_ ("cli;");
}
}
If every processor is poisoned with a "bad" task, every processor is useless. Simulate the above case (Linux) with: Code:
#define work_as_parlament() while(1)
long j;
main(){
for (j=0;j<100;j++)//100 could be replaced with the number of your CPUs, but then it is pssible that
if(fork()) work_as_parlament(); //more than one of the forked tasks is scheduled to one CPU - leaving one free
}
This proves the scheduling of "bad" tasks to all CPUs. (Monitor works still fine (Linux has the round robin multilevel queue scheduling.) 3. How, we can experiment are the answers correct. Many ways, one example:
Still we are far from complete.
shabbir
likes this
|
|
Go4Expert Member
|
|
| 25Feb2013,16:22 | #5 |
|
I was waiting the following question (nobody did): Now I understand what you mean by saying "far from complete".What I would answer to this question: You are right. If we add the line i=0; in the beginning of the program then my explanation is correct (I hope). Clearly what happens when we run the original program is:
The Sage_sage's original question seems to reveal many things, a good question. The answer is far from complete even now. For ex. it is not explained why while(1); is necessary or is not necessary (in the case we have not divide by zero and we want to stop one CPU) and so on................. I was using Linux as an example. Not a good thing. Would have been better to talk only at a general level. If somebody asks something difficult (about Linux) based on my example, I can't answer. I think it is easier to write your own small kernel (what I have done) than try to follow how all things are done inside Linux kernel (4000000 code lines). Every OS can do some things at it's own way, even general principles are the same.
shabbir
likes this
|
|
Go4Expert Member
|
|
| 28Feb2013,17:28 | #6 |
|
Far from complete answers?
Yes, what about cpu recovery from "cli". With important real-time applications we have had for a long time a watchdog timer (HW interrupting cpu to answer somehow "I am alive"). For example we have main control computer and standby computer taking care of the system if the main computer is down. What about Linux? What kind watchdog- have we one? We can compile the Linux kernel with or without watchdog. What the Linux watchdog does? On many(!) x86/x86-64 type hardware there is a feature that enables us to generate 'watchdog NMI interrupts'. It's even possible to disable the NMI watchdog in run-time by writing "0" to /proc/sys/kernel/nmi_watchdog. If any CPU in the system does not execute the period local timer interrupt for more than 5 seconds, APIC tries to fix the situation by a non-maskable interrupt (cpu executes the handler, and kills the process)! (SCC Linux is an different case as to NMI.) My answers (in the original question) were based on the system without watchdog! It is problematic to answer at a general level and give examples based on some fixed system. The answers can be correct or depending the cpu and configuration and settings. |

