SUID permission on Bash script

perryh at pluto.rain.com perryh at pluto.rain.com
Sun Aug 30 21:36:37 UTC 2009


Matthew Seaman <m.seaman at infracaninophile.co.uk> wrote:

> > It would do no good for the kernel to hand the interpreter an
> > open descriptor if the interpreter did not somehow know to read
> > the script from that open descriptor instead of opening the
> > script file by name.
>
> Errr -- no.  That's what fdescfs(5) is for.   When the kernel
> execs the interpreter, it tells the script to open /dev/fd/5 (for
> example) and doing that just connects the script to the open file
> descriptor the kernel used previously to taste the magic number
> and the #! line of the script.

which -- again absent some special arrangement in the interpreter
-- would cause the script to receive $0 as "/dev/fd/5" instead of
the actual name of the script, no?  I'd expect this to at least
break any messages that the script might try to produce via
constructs like

  echo "$0: whatever"


More information about the freebsd-questions mailing list