21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Normally, the two processes are closely related. Usually they’re the same program<br />

split during initialization into two separate processes using fork( ). The original process<br />

retains its privileges and enters a loop waiting to service requests from the child<br />

process. The child process starts by permanently dropping the extra privileges inherited<br />

from the parent process and continues normally, sending requests to the parent<br />

when it needs privileged operations to be performed.<br />

By separating the process into privileged and unprivileged pieces, the risk of a privilege<br />

escalation attack is significantly reduced. The risk is further reduced by the parent<br />

process refusing to perform any operations that it knows the child does not need.<br />

For example, if the program never needs to delete any files, the privileged process<br />

should refuse to service any requests to delete files. Because the unprivileged child<br />

process undertakes most of the program’s functionality, it stands the greatest risk of<br />

compromise by an attacker, but because it has no extra privileges of its own, an<br />

attacker does not stand to gain much from the compromise.<br />

A privilege separation library: privman<br />

NAI Labs has released a library that implements privilege separation on Unix with an<br />

easy-to-use API. This library, called privman, can be obtained from http://opensource.<br />

nailabs.com/privman/. As of this writing, the library is still in an alpha state and the<br />

API is subject to change, but it is quite usable, and it provides a good generic framework<br />

from which to work.<br />

A program using privman should include the privman.h header file and link to the<br />

privman library. As part of the program’s initialization, call the privman API function<br />

priv_init( ), which requires a single argument specifying the name of the program.<br />

The program’s name is used for log entries to syslog (see Recipe 13.11 for a<br />

discussion of logging), as well as for the configuration file to use. The priv_init( )<br />

function should be called by the program with root privileges enabled, and it will<br />

take care of splitting the program into two processes and adjusting privileges for each<br />

half appropriately.<br />

The privman library uses configuration files to determine what operations the privileged<br />

half of a program may perform on behalf of the unprivileged half of the same<br />

program. In addition, the configuration file determines what user the unprivileged<br />

half of the program runs as, and what directory is used in the call to chroot( ) in the<br />

unprivileged process (see Recipe 2.12). By default, privman runs the unprivileged<br />

process as the user “nobody” and does a chroot( ) to the root directory, but we<br />

strongly recommend that your program use a user specifically set up for it instead of<br />

“nobody”, and that you chroot( ) to a safe directory (see Recipe 2.4).<br />

When the priv_init( ) function returns control to your program, your code will be<br />

running in the unprivileged child process. The parent process retains its privileges, and<br />

control is never returned to you. Instead, the parent process remains in a loop that<br />

responds to requests from the unprivileged process to perform privileged operations.<br />

22 | Chapter 1: Safe Initialization<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!