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.

strings suitable for use here. Each of these macros begins with SE_, which is followed<br />

by the name of the privilege. For example, the SeBackupPrivilege privilege<br />

has a corresponding macro named SE_BACKUP_NAME.<br />

lpLuid<br />

Pointer to a caller-allocated LUID object that will receive the LUID information if<br />

the lookup is successful. LUID objects are a fixed size, so they may be allocated<br />

either dynamically or on the stack.<br />

See Also<br />

Recipe 1.8<br />

1.3 Dropping Privileges in setuid Programs<br />

<strong>Problem</strong><br />

Your program runs setuid or setgid (see the “Discussion” section for definitions),<br />

thus providing your program with extra privileges when it is executed. After the<br />

work requiring the extra privileges is done, those privileges need to be dropped so<br />

that an attacker cannot leverage your program during an attack that results in privilege<br />

elevation.<br />

Solution<br />

If your program must run setuid or setgid, make sure to use the privileges properly so<br />

that an attacker cannot exploit other possible vulnerabilities in your program and<br />

gain these additional privileges. You should perform whatever work requires the<br />

additional privileges as early in the program as possible, and you should drop the<br />

extra privileges immediately after that work is done.<br />

While many programmers may be aware of the need to drop privileges, many more<br />

are not. Worse, those who do know to drop privileges rarely know how to do so<br />

properly and securely. Dropping privileges is tricky business because the semantics<br />

of the system calls to manipulate IDs for setuid/setgid vary from one Unix variant to<br />

another—sometimes only slightly, but often just enough to make the code that<br />

works on one system fail on another.<br />

On modern Unix systems, the extra privileges resulting from using the setuid or setgid<br />

bits on an executable can be dropped either temporarily or permanently. It is best<br />

if your program can do what it needs to with elevated privileges, then drop those<br />

privileges permanently, but that’s not always possible. If you must be able to restore<br />

the extra privileges, you will need to be especially careful in your program to do<br />

everything possible to prevent an attacker from being able to take control of those<br />

16 | 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!