Docsity

CS4410: Possible Culprits for System Freezes and High I/O in FireFox - Prof. E. Sirer, Assignments of Operating Systems

Toggle sidebar
bg1
CS4410: Homework 1. Due 9am Feb. 2 Feb 3 via CMS
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:
1.๎˜ƒA๎˜ƒhardware๎˜ƒproblem๎˜ƒwith๎˜ƒthe๎˜ƒdisk๎˜ƒcontroller.๎˜ƒ
๎˜ƒ
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.๎˜ƒ๎˜ƒ๎˜ƒ
2.๎˜ƒA๎˜ƒbug๎˜ƒin๎˜ƒthe๎˜ƒfile๎˜ƒsystem๎˜ƒbrowser,๎˜ƒwhich๎˜ƒruns๎˜ƒin๎˜ƒuserโ€mode.๎˜ƒ
๎˜ƒ
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).
3.๎˜ƒWhat๎˜ƒwould๎˜ƒbe๎˜ƒthe๎˜ƒlikely๎˜ƒconsequence๎˜ƒof๎˜ƒchanging๎˜ƒthe๎˜ƒscheduler๎˜ƒpriority๎˜ƒof๎˜ƒFireFox๎˜ƒto๎˜ƒthe๎˜ƒ
maximum๎˜ƒvalue๎˜ƒsupported๎˜ƒby๎˜ƒthe๎˜ƒoperating๎˜ƒsystem?๎˜ƒ(You๎˜ƒmay๎˜ƒassume๎˜ƒthat๎˜ƒthis๎˜ƒwould๎˜ƒbe๎˜ƒ
higher๎˜ƒthan๎˜ƒthe๎˜ƒpriority๎˜ƒof๎˜ƒany๎˜ƒother๎˜ƒprocess,๎˜ƒincluding๎˜ƒthe๎˜ƒcommand๎˜ƒinterface).๎˜ƒ
๎˜ƒ
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โ€F4๎˜ƒ
(^C๎˜ƒif๎˜ƒyou๎˜ƒuse๎˜ƒLinux),๎˜ƒor๎˜ƒto๎˜ƒhold๎˜ƒthe๎˜ƒpowerโ€key๎˜ƒdown๎˜ƒuntil๎˜ƒthe๎˜ƒBIOS๎˜ƒnotices๎˜ƒand๎˜ƒrestarts๎˜ƒthe๎˜ƒmachine.๎˜ƒ๎˜ƒ๎˜ƒ
๎˜ƒ
4.๎˜ƒPresumably,๎˜ƒthe๎˜ƒfile๎˜ƒwas๎˜ƒdamaged๎˜ƒby๎˜ƒthe๎˜ƒcrash๎˜ƒand๎˜ƒthis๎˜ƒis๎˜ƒthe๎˜ƒroot๎˜ƒcause๎˜ƒof๎˜ƒthe๎˜ƒproblem.๎˜ƒBut๎˜ƒ
whatโ€™s๎˜ƒyour๎˜ƒbest๎˜ƒguess๎˜ƒas๎˜ƒto๎˜ƒwhy๎˜ƒFireFox๎˜ƒis๎˜ƒperforming๎˜ƒso๎˜ƒmany๎˜ƒsystem๎˜ƒcalls๎˜ƒ
๎˜ƒ
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;
pf3

Partial preview of the text

Download CS4410: Possible Culprits for System Freezes and High I/O in FireFox - Prof. E. Sirer and more Assignments Operating Systems in PDF only on Docsity!

CS4410: Homework 1. Due 9am Feb. 2 Feb 3 via CMS

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:

  1. A hardware problem with the disk controller.

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.

  1. A bug in the file system browser, which runs in userโ€mode.

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).

  1. What would be the likely consequence of changing the scheduler priority of FireFox to the maximum value supported by the operating system? (You may assume that this would be higher than the priority of any other process, including the command interface).

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.

  1. Presumably, the file was damaged by the crash and this is the root cause of the problem. But whatโ€™s your best guess as to why FireFox is performing so many system calls

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

  • it has no way to know whether *sp has run off the end of the string buffer. We canโ€™t even tell how long the string buffer argument is allowed to be! Probably our truncated file wonโ€™t trigger this bug, but imagine a file with a really long (screwed up) last line. The program will just copy and copy, overwriting the stuff beyond the end of the string buffer argument, until it sees a newline character. You are probably guessing that this would cause the application to crashโ€ฆ but it isnโ€™t so simple.

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.

  1. Is the number of threads FireFox can create limited by the number of cores on your computer?

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.

  1. Describe a situation in which, if it were up to you, you would have coded FireFox to create an additional thread. What would be the benefit of doing so?