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.

#include <br />

#include <br />

#include <br />

void spc_limit_core(void) {<br />

struct rlimit rlim;<br />

rlim.rlim_cur = rlim.rlim_max = 0;<br />

setrlimit(RLIMIT_CORE, &rlim);<br />

}<br />

In addition to the RLIMIT_CORE limit, the setrlimit( ) function also<br />

allows other per-process limits to be adjusted. We discuss these other<br />

limits in Recipe 13.9.<br />

The advantage of disabling core dumps is that if your program has particularly sensitive<br />

information residing in memory unencrypted (even transient data is at risk,<br />

because a skilled attacker could potentially time the core dumps so that your program<br />

dumps core at precisely the right time), it will not ever write this data to disk in<br />

a core dump. The primary disadvantage of this approach is that the lack of a core file<br />

makes debugging program crashes very difficult after the fact. How big an issue this<br />

is depends on program deployment and how bugs are tracked and fixed. A number<br />

of shells provide an interface to the setrlimit( ) function via a built-in command.<br />

Users who want to prevent core file generation can set the appropriate limit with the<br />

shell command, then run the program.<br />

However, for situations where data in memory is required to be protected, the application<br />

should limit the core dumps directly via setrlimit( ) so that it becomes<br />

impossible to inadvertently run the program with core dumps enabled. When core<br />

dumps are needed for debugging purposes, a safer alternative is to allow core dumps<br />

only when the program has been compiled in “debug mode.” This is easily done by<br />

wrapping the setrlimit( ) call with the appropriate preprocessor conditional to disable<br />

the code in debug mode and enable it otherwise.<br />

Some Unix variants (Solaris, for example) allow the system administrator to control<br />

how core dumps are handled on a system-wide basis. Some of the capabilities of<br />

these systems allow the administrator to specify a directory where all core dumps<br />

will be placed. When this capability is employed, the directory configured to hold<br />

the core dump files is typically owned by the superuser and made unreadable to any<br />

other users. In addition, most systems force the permissions of a core file so that it is<br />

only readable by the user the process was running as when it dumped core. However,<br />

this is not a very robust solution, as many other exploits could possibly be used<br />

to read this file.<br />

See Also<br />

Recipe 13.9<br />

Disabling Memory Dumps in the Event of a Crash | 37<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!