21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ability to run. The default limits are usually set much higher than they need to be,<br />

which ends up allowing any given application to use up far more resources than it<br />

ordinarily should.<br />

Windows 2000 and newer versions provide a mechanism by which applications can<br />

self-impose restrictive limits on the resources that it uses. It’s a good idea for the programmer<br />

to lower the limits to a point where the application can run comfortably,<br />

but if something unexpected happens (such as a memory leak or, more to the point,<br />

a denial of service attack), the limits cause the application to terminate without<br />

bringing down the rest of the system with it.<br />

Discussion<br />

Operating system resources are difficult for an application to control; the pooling<br />

approach used in threads and sockets is difficult to implement when the application<br />

does not explicitly allocate and destroy its own resources. System resources, such as<br />

memory and CPU time, are best managed using system quotas. The programmer can<br />

never be sure that system quotas are enabled when the application is running; therefore,<br />

it pays to be defensive and write code that is reasonably aware of system<br />

resource management.<br />

The most basic advice will be long familiar from lectures on good programming practice:<br />

• Avoid the use of system calls when possible.<br />

• Minimize the number of filesystem reads and writes.<br />

• Steer away from CPU-intensive or “tight” loops.<br />

• Avoid allocating large buffers on the stack.<br />

The ambitious programmer may wish to replace library and operating system<br />

resource management subsystems, by such means as writing a memory allocator that<br />

enforces a maximum memory usage per thread, or writing a scheduler tied to the system<br />

clock which pauses or stops threads and processes after a specified period of<br />

time. While these are viable solutions and should be considered for any large-scale<br />

project, they greatly increase development time and will likely introduce new bugs<br />

into the system.<br />

Instead, you may wish to voluntarily submit to the resource limits enforced by system<br />

quotas, thereby in effect “enabling” quotas for the application. This can be done<br />

on Windows using job objects. Job objects are created to hold and control processes,<br />

imposing limits on them that do not exist on processes outside of the job object. Various<br />

restrictions may be imposed upon processes running within a job object, including<br />

limiting CPU time, memory usage, and access to the user interface. Here, we are<br />

only interested in restricting resource utilization of processes within a job, which will<br />

Guarding Against Resource Starvation Attacks on Windows | 731<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!