home *** CD-ROM | disk | FTP | other *** search
-
-
-
- SETUID(7) PUBLIC FILES, TABLES, AND TROFF MACROS SETUID(7)
-
-
-
- NNNNAAAAMMMMEEEE
- setuid - checklist for security of setuid programs
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- Writing a secure setuid (or setgid) program is tricky.
- There are a number of possible ways of subverting such a
- program. The most conspicuous security holes occur when a
- setuid program is not sufficiently careful to avoid giving
- away access to resources it legitimately has the use of.
- Most of the other attacks are basically a matter of altering
- the program's environment in unexpected ways and hoping it
- will fail in some security-breaching manner. There are gen-
- erally three categories of environment manipulation: supply-
- ing a legal but unexpected environment that may cause the
- program to directly do something insecure, arranging for
- error conditions that the program may not handle correctly,
- and the specialized subcategory of giving the program inade-
- quate resources in hopes that it won't respond properly.
-
- The following are general considerations of security when
- writing a setuid program.
-
- [] The program should run with the weakest userid possible,
- preferably one used only by itself. A security hole in a
- setuid program running with a highly-privileged userid
- can compromise an entire system. Security-critical pro-
- grams like _p_a_s_s_w_d(1) should always have private userids,
- to minimize possible damage from penetrations elsewhere.
-
- [] The result of _g_e_t_l_o_g_i_n or _t_t_y_n_a_m_e may be wrong if the
- descriptors have been meddled with. There is _n_o fool-
- proof way to determine the controlling terminal or the
- login name (as opposed to uid) on V7.
-
- [] On some systems (not ours), the setuid bit may not be
- honored if the program is run by _r_o_o_t, so the program may
- find itself running as _r_o_o_t.
-
- [] Programs that attempt to use _c_r_e_a_t for locking can foul
- up when run by _r_o_o_t; use of _l_i_n_k is preferred when imple-
- menting locking. Using _c_h_m_o_d for locking is an obvious
- disaster.
-
- [] Breaking an existing lock is very dangerous; the break-
- down of a locking protocol may be symptomatic of far
- worse problems. Doing so on the basis of the lock being
- `old' is sometimes necessary, but programs can run for
- surprising lengths of time on heavily-loaded systems.
-
- [] Care must be taken that user requests for i/o are checked
- for permissions using the user's permissions, not the
- program's. Use of _a_c_c_e_s_s is recommended.
-
-
-
- Sun Release 4.0 Last change: local 1
-
-
-
-
-
-
- SETUID(7) PUBLIC FILES, TABLES, AND TROFF MACROS SETUID(7)
-
-
-
- [] Programs executed at user request (e.g. shell escapes)
- must not receive the setuid program's permissions; use of
- daughter processes and _s_e_t_u_i_d(_g_e_t_u_i_d()) plus
- _s_e_t_g_i_d(_g_e_t_g_i_d()) after _f_o_r_k but before _e_x_e_c is vital.
-
- [] Similarly, programs executed at user request must not
- receive other sensitive resources, notably file descrip-
- tors. Use of _c_l_o_s_e_a_l_l(3) or close-on-exec arrangements,
- on systems which have them, is recommended.
-
- [] Programs activated by one user but handling traffic on
- behalf of others (e.g. daemons) should avoid doing
- _s_e_t_u_i_d(_g_e_t_u_i_d()) or _s_e_t_g_i_d(_g_e_t_g_i_d()), since the original
- invoker's identity is almost certainly inappropriate. On
- systems which permit it, use of _s_e_t_u_i_d(_g_e_t_e_u_i_d()) and
- _s_e_t_g_i_d(_g_e_t_e_g_i_d()) is recommended when performing work on
- behalf of the system as opposed to a specific user.
-
- [] There are inherent permission problems when a setuid pro-
- gram executes another setuid program, since the permis-
- sions are not additive. Care should be taken that
- created files are not owned by the wrong person. Use of
- _s_e_t_u_i_d(_g_e_t_e_u_i_d()) and its gid counterpart can help, if
- the system allows them.
-
- [] Care should be taken that newly-created files do not have
- the wrong permission or ownership even momentarily. Per-
- missions should be arranged by using _u_m_a_s_k in advance,
- rather than by creating the file wide-open and then using
- _c_h_m_o_d. Ownership can get sticky due to the limitations
- of the setuid concept, although using a daughter process
- connected by a pipe can help.
-
- [] Setuid programs should be especially careful about error
- checking, and the normal response to a strange situation
- should be termination, rather than an attempt to carry
- on.
-
- The following are ways in which the program may be induced
- to carelessly give away its special privileges.
-
- [] The directory the program is started in, or directories
- it may plausibly _c_h_d_i_r to, may contain programs with the
- same names as system programs, placed there in hopes that
- the program will activate a shell with a permissive PPPPAAAATTTTHHHH
- setting. PPPPAAAATTTTHHHH should _a_l_w_a_y_s be standardized before
- invoking a shell (either directly or via _p_o_p_e_n or
- _e_x_e_c_v_p/_e_x_e_c_l_p).
-
- [] Similarly, a bizarre IIIIFFFFSSSS setting may alter the interpre-
- tation of a shell command in really strange ways, possi-
- bly causing a user-supplied program to be invoked. IIIIFFFFSSSS
-
-
-
- Sun Release 4.0 Last change: local 2
-
-
-
-
-
-
- SETUID(7) PUBLIC FILES, TABLES, AND TROFF MACROS SETUID(7)
-
-
-
- too should always be standardized before invoking a
- shell. (Our shell does this automatically.)
-
- [] Environment variables in general cannot be trusted.
- Their contents should never be taken for granted.
-
- [] Setuid shell files (on systems which implement such) sim-
- ply cannot cope adequately with some of these problems.
- They also have some nasty problems like trying to run a
- ._p_r_o_f_i_l_e when run under a suitable name. They are termi-
- nally insecure, and must be avoided.
-
- [] Relying on the contents of files placed in publically-
- writeable directories, such as /_t_m_p, is a nearly-
- incurable security problem. Setuid programs should avoid
- using /_t_m_p entirely, if humanly possible. The sticky-
- directories modification (sticky bit on for a directory
- means only owner of a file can remove it) (we have this
- feature) helps, but is not a complete solution.
-
- [] A related problem is that spool directories, holding
- information that the program will trust later, must never
- be publically writeable even if the files in the direc-
- tory are protected. Among other sinister manipulations
- that can be performed, note that on many Unixes (not
- ours), a core dump of a setuid program is owned by the
- program's owner and not by the user running it.
-
- The following are unusual but possible error conditions that
- the program should cope with properly (resource-exhaustion
- questions are considered separately, see below).
-
- [] The value of _a_r_g_c might be 0.
-
- [] The setting of the _u_m_a_s_k might not be sensible. In any
- case, it should be standardized when creating files not
- intended to be owned by the user.
-
- [] One or more of the standard descriptors might be closed,
- so that an opened file might get (say) descriptor 1,
- causing chaos if the program tries to do a _p_r_i_n_t_f.
-
- [] The current directory (or any of its parents) may be
- unreadable and unsearchable. On many systems _p_w_d(1) does
- not run setuid-root, so it can fail under such condi-
- tions.
-
- [] Descriptors shared by other processes (i.e., any that are
- open on startup) may be manipulated in strange ways by
- said processes.
-
- [] The standard descriptors may refer to a terminal which
-
-
-
- Sun Release 4.0 Last change: local 3
-
-
-
-
-
-
- SETUID(7) PUBLIC FILES, TABLES, AND TROFF MACROS SETUID(7)
-
-
-
- has a bizarre mode setting, or which cannot be opened
- again, or which gives end-of-file on any read attempt, or
- which cannot be read or written successfully.
-
- [] The process may be hit by interrupt, quit, hangup, or
- broken-pipe signals, singly or in fast succession. The
- user may deliberately exploit the race conditions
- inherent in catching signals; ignoring signals is safe,
- but catching them is not.
-
- [] Although non-keyboard signals cannot be sent by ordinary
- users in V7, they may perhaps be sent by the system
- authorities (e.g. to indicate that the system is about to
- shut down), so the possibility cannot be ignored.
-
- [] On some systems (not ours) there may be an _a_l_a_r_m signal
- pending on startup.
-
- [] The program may have children it did not create. This is
- normal when the process is part of a pipeline.
-
- [] In some non-V7 systems, users can change the ownerships
- of their files. Setuid programs should avoid trusting
- the owner identification of a file.
-
- [] User-supplied arguments and input data _m_u_s_t be checked
- meticulously. Overly-long input stored in an array
- without proper bound checking can easily breach security.
- When software depends on a file being in a specific for-
- mat, user-supplied data should never be inserted into the
- file without being checked first. Meticulous checking
- includes allowing for the possibility of non-ASCII char-
- acters.
-
- [] Temporary files left in public directories like /_t_m_p
- might vanish at inconvenient times.
-
- The following are resource-exhaustion possibilities that the
- program should respond properly to.
-
- [] The user might have used up all of his allowed processes,
- so any attempt to create a new one (via _f_o_r_k or _p_o_p_e_n)
- will fail.
-
- [] There might be many files open, exhausting the supply of
- descriptors. Running _c_l_o_s_e_a_l_l(3), on systems which have
- it, is recommended.
-
- [] There might be many arguments.
-
- [] The arguments and the environment together might occupy a
- great deal of space.
-
-
-
- Sun Release 4.0 Last change: local 4
-
-
-
-
-
-
- SETUID(7) PUBLIC FILES, TABLES, AND TROFF MACROS SETUID(7)
-
-
-
- Systems which impose other resource limitations can open
- setuid programs to similar resource-exhaustion attacks.
-
- Setuid programs which execute ordinary programs without
- reducing authority pass all the above problems on to such
- unprepared children. Standardizing the execution environ-
- ment is only a partial solution.
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- closeall(3), standard(3)
-
- HHHHIIIISSSSTTTTOOOORRRRYYYY
- Locally written, although based on outside contributions.
-
- BBBBUUUUGGGGSSSS
- The list really is rather long... and probably incomplete.
-
- Neither the author nor the University of Toronto accepts any
- responsibility whatever for the use or non-use of this
- information.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Sun Release 4.0 Last change: local 5
-
-
-
-