

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Q1. Suppose that you plug a new disk into your laptop and boot the machine. But when you try to access the disk, the whole machine freezes, including the power button โ the only way to restart it is to physically remove the battery, after which it finally comes back to life. Explain in one or two lines if each of these is a possible culprit:
A malfunctioning disk controller could, in effect, jam the computerโs bus. The bus connects the CPU to
main memory, the special flash memory where the BIOS lives, and with devicesโฆ if the bus is jammed,
the entire system will freeze up because nothing, not even the BIOS, can be executed.
This is much less likely because the O/S kernel protects itself against anything a user โ mode application could possibly do. For the machine to wedge up so firmly, whatever went wrong was much worse than a simple user โ mode software bug.
Q2. You are using FireFox. Everything was working properly yesterday, but then your machine crashed. Now FireFox hangs when you run it. With โprocess explorerโ you can see that it is rapidly issuing file I/O operations (very rapidly: about 10,000 per second!). The only open file is called โfirefox.cnf.โ This file exists, and can definitely be accessed by the application. On the other hand, the file looks a bit strange (it is a small text file, the line of which seems to be truncated).
If FireFox is in an infinite loop (and apparently it is), that would be a terrible idea: the system would hang and become completely unresponsive. You would then have no option except to kill FireFox with alt โ F (^C if you use Linux), or to hold the power โ key down until the BIOS notices and restarts the machine.
It seems likely that FireFox has gotten stuck somehow trying to read the last line of that file, looking for the newline but not checking for EOF. This is a good example of how people who write O/S services need to be extra careful in ways that normal application designers might not.
Hereโs an example of how you can easily make this mistake. This code fragment, written in C, would behave precisely as described (getchar() calls the read() system call, which would account for those I/O requests):
readline(string_buffer) char string_buffer[]; { char *sp, c; sp = string_buffer;
while((c = getchar()) != โ\nโ) if(isalnum(c) || c == โ=โ || c == โ;โ) *sp++ = c; *sp = 0; }
The code is โtryingโ to read one line of text into string_buffer, but is only keeping alpha โ numeric characters, equal signs, and semicolons. Programs like FireFox do this all the time, to clean up pretty โ printing in their input file. The bug here is that this particular code snippet doesnโt check for EOF, which comes back from getchar() as a null (0) byte. So if a line doesnโt end with a newline character, it loops forever, and getchar() keeps calling the read system call, explaining the high rate of I/O requests. Notice that the program wonโt run off the end of the string buffer because a null doesnโt satisfy the if condition.
This code illustrates a second kind of common mistake, too: it doesnโt check to see if the string is too long
Very often, the string buffer argument is just a local variable allocated by the caller of readline, and this means it might live on the stackโฆ right next to the return PC address that the caller of readline() will use when it finishes looking at the string readline() copied in. A virus could potentially take advantage of this kind of mistake to trick such a program into copying the virus instructions into memory โ the virus writer would study the application, realize that a bad argument string can be used to overwrite the stack and the return PC address. They would design virus code that can live on the stack and pick a return PC address that will jump right into the virus code at the โmainโ procedure of their virus. In effect, like an alien that takes over the body of an innocent actor, the virus is able to fool the service into loading its code and launching it! This is called a โbuffer overrun exploitโ and is surprisingly easy to do if people write sloppy code like the fragment shown, and then give out the source code. Most computer viruses spread through these sorts of tricks.
Sure, it wouldnโt be easy (the virus writer needs to be sure he can guess what the stack will look like, and where it will be in memory). But believe it or not, many programs are so predictable that you can actually study them with a debugging tool and figure things like this out! Virus writers take that extra time and this is why they are so good at building viruses that can spread and cause such havoc. Of course if everyone took cs4410, they would write code that simply checks for EOF and makes sure to copy incoming strings within the allocated space, and that would completely fix the problem here.
Q3. FireFox is a โmulti โ threadedโ program.
Nope. Threads are a logical, not a physical thing. You can have as many threads as you like, provided that there is enough memory for their stack areas.