27.11.2014 Views

INTRO (7) NetBSD Miscellaneous Information Manual INTRO (7 ...

INTRO (7) NetBSD Miscellaneous Information Manual INTRO (7 ...

INTRO (7) NetBSD Miscellaneous Information Manual INTRO (7 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

SCRIPT (7) <strong>NetBSD</strong> <strong>Miscellaneous</strong> <strong>Information</strong> <strong>Manual</strong> SCRIPT (7)<br />

"/bin/interp", "-x", "-y", "/tmp/script", "one", "two", "three"<br />

The behavior of the system in the face of multiple arguments is thus not currently standardized, should not be<br />

relied on, and may be changed in future releases. In general, pass at most one argument, and do not rely on<br />

multiple arguments being concatenated.<br />

SEE ALSO<br />

awk(1), csh(1), ksh(1), sh(1), chmod(2), execve(2), intro(2), execlp(3), execvp(3), fd(4),<br />

options(4), setuid(7)<br />

STANDARDS<br />

The behavior of interpreter scripts is obliquely referred to, but never actually described in,<br />

1003.1-2004 " (“POSIX.1”).<br />

IEEE Std<br />

The behavior is partially (but not completely) described in the System V Interface Definition, Fourth Edition<br />

(“SVID4”).<br />

Although it has never been formally standardized, the behavior described is largely portable across POSIX<br />

style systems, with two significant exceptions: the maximum length of the “#!” line, and the behavior if multiple<br />

arguments are passed. Please be aware that some operating systems limit the line to 32 or 64 characters,<br />

and that (as described above) the behavior in the face of multiple arguments is not consistent across systems.<br />

HISTORY<br />

The behavior of the kernel when encountering scripts that start in “#!” was not present in Version 7 AT&T<br />

UNIX. A Usenet posting to net.unix by Guy Harris on October 16, 1984 claims that the idea for the “#!”<br />

behavior was first proposed by Dennis Ritchie but that the first implementation was on BSD.<br />

Historical manuals (specifically the exec man page) indicate that the behavior was present in 4BSD at least as<br />

early as April, 1981. <strong>Information</strong> on precisely when it was first implemented, and in which version of UNIX,<br />

is solicited.<br />

SECURITY CONSIDERATIONS<br />

Numerous security problems are associated with setuid interpreter scripts.<br />

In addition to the fact that many interpreters (and scripts) are simply not designed to be robust in a setuid<br />

context, a race condition exists between the moment that the kernel examines the interpreter script file and<br />

the moment that the newly invoked interpreter opens the file itself.<br />

Because of these security issues, <strong>NetBSD</strong> does not allow setuid interpreter scripts by default. In order to turn<br />

on setuid interpreter scripts,<br />

options SETUIDSCRIPTS<br />

must be set in the configuration of the running kernel. Setting this option implies the FDSCRIPTS option,<br />

which causes the kernel to open the script file on behalf of the interpreter and pass it in argv as<br />

/dev/fd/[fdnum]. (See fd(4) for an explanation of the /dev/fd/[fdnum] devices.) This design<br />

avoids the race condition, at the cost of denying the interpreter the actual name of the script file. See<br />

options(4) for more information.<br />

However, the FDSCRIPTS mechanism is not a cure-all for security issues in setuid interpreters and scripts.<br />

Subtle techniques can be used to subvert even seemingly well written scripts. Scripts executed by Bourne<br />

type shells can be subverted in numerous ways, such as by setting the IFS variable before executing the<br />

script. Other interpreters possess their own vulnerabilities. Turning on SETUIDSCRIPTS is therefore very<br />

dangerous, and should not be done lightly if at all.<br />

<strong>NetBSD</strong> 3.0 May 6, 2005 3

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

Saved successfully!

Ooh no, something went wrong!