setuid Tcl scripts don't work on Solaris
Open488530ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 21 years ago
Descriptionplain2001-12-03 19:35:41
On Solaris, create a script, "foo.tcl", that looks like the following:
#!/bin/sh
#\
exec tclsh8.3 "$0" ${1+"$@"}
puts "----------------------------------------------------------------------"
puts "----------------------------------------------------------------------"
puts "----------------------------------------------------------------------"
puts "----------------------------------------------------------------------"
puts "----------------------------------------------------------------------"
Now change its permissions to 2755 (rwsr-xr-x). Attempt to execute ./foo.tcl
from the command line. An error results:
invalid command name "---------------------------------------------------------------------""
while executing
"---------------------------------------------------------------------""
(file "/dev/fd/3" line 1)
What's happening here is that Solaris, for security reasons, doesn't pass the name of the script file
into the shell. Instead, it opens the script file, leaves it open, and launches the shell with argv[0]
equal to /dev/fd/N, where N is the number of the script file's filedescriptor.
When this file is opened, the kernel simply dup's the filedescriptor. The file is not rewound. The
result is that the Tcl_EvalFileEx that's been called from Tcl_Main starts reading the file in the
middle.
One obvious potential fix is to have Tcl_EvalFileEx seek the file to the beginning before reading it.
The only problem I can see with this is if someone's [source]ing a device file and depending on its
being left in place. I think I'd be prepared to break this behavior in order to make setuid scripts
work.
dkfplain2001-12-04 18:04:34
Logged In: YES user_id=79902 Possible workaround: Put an extra blank line or *any* comment line after the exec line; the problem is really that the Solaris /bin/sh reads too far from the FD...
kennykbplain2001-12-04 22:01:14
Logged In: YES user_id=99768 The user in question already has a workaround of separating the setuid shell script from the Tcl script: http://mini.net/tcl/2654.html The proposed workaround depends on the size of the buffer used in /bin/sh. There really isn't any reason for the shell to reposition its script file before doing an exec, so I'd be really reluctant to call this a shell bug. Note that one expects the script to restart from the beginning, as it would if the /dev/fd hack weren't there. I think that the underlying bug is in the kernel, that opening /dev/fd/N doesn't do a rewind. It should, if the implementors are going to use this hack on setuid shell scripts.
kennykbplain2001-12-13 03:47:56
Logged In: YES user_id=99768 The right place to rewind the file is most likely in Tcl_FSEvalFile, after the channel is opened but before reading from it. Once again, failure to seek should not be treated as an error, in case anyone decides to 'source' a character special device.
kennykb Ticket [488530ffff]: 1 change
[History diff]2001-12-13 03:49:57
vincentdarleyplain2001-12-14 02:18:41
Logged In: YES user_id=32170 I don't think I'm particularly qualified to judge what should be done here. It seems the proposed change is inoccuous enough,... Given that, I'll argue this is more of a channel issue than a filesystem issue, so I'm assigning to Andreas ;-)
andreas_kupriesplain2006-03-15 07:28:13
Logged In: YES user_id=75003 Kevin, should we do anything anymore with this entry ?
Log in (anonymous is fine) to add a comment.