OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [insight/] [tcl/] [doc/] [safe.n] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
'\"
2
'\" Copyright (c) 1995-1996 Sun Microsystems, Inc.
3
'\"
4
'\" See the file "license.terms" for information on usage and redistribution
5
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6
'\"
7
'\" RCS: @(#) $Id: safe.n,v 1.1.1.1 2002-01-16 10:25:25 markom Exp $
8
'\"
9
.so man.macros
10
.TH "Safe Tcl" n 8.0 Tcl "Tcl Built-In Commands"
11
.BS
12
'\" Note:  do not modify the .SH NAME line immediately below!
13
.SH NAME
14
Safe Base \- A mechanism for creating and manipulating safe interpreters.
15
.SH SYNOPSIS
16
.PP
17
\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR?
18
.sp
19
\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR?
20
.sp
21
\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR?
22
.sp
23
\fB::safe::interpDelete\fR \fIslave\fR
24
.sp
25
\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fR
26
.sp
27
\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fR
28
.sp
29
\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR?
30
.SH OPTIONS
31
.PP
32
?\fB\-accessPath\fR \fIpathList\fR?
33
?\fB\-statics\fR \fIboolean\fR? ?\fB\-noStatics\fR?
34
?\fB\-nested\fR \fIboolean\fR? ?\fB\-nestedLoadOk\fR?
35
?\fB\-deleteHook\fR \fIscript\fR?
36
.BE
37
 
38
.SH DESCRIPTION
39
Safe Tcl is a mechanism for executing untrusted Tcl scripts
40
safely and for providing mediated access by such scripts to
41
potentially dangerous functionality.
42
.PP
43
The Safe Base ensures that untrusted Tcl scripts cannot harm the
44
hosting application.
45
The Safe Base prevents integrity and privacy attacks. Untrusted Tcl
46
scripts are prevented from corrupting the state of the hosting
47
application or computer. Untrusted scripts are also prevented from
48
disclosing information stored on the hosting computer or in the
49
hosting application to any party.
50
.PP
51
The Safe Base allows a master interpreter to create safe, restricted
52
interpreters that contain a set of predefined aliases for the \fBsource\fR,
53
\fBload\fR, \fBfile\fR and \fBexit\fR commands and
54
are able to use the auto-loading and package mechanisms.
55
.PP
56
No knowledge of the file system structure is leaked to the
57
safe interpreter, because it has access only to a virtualized path
58
containing tokens. When the safe interpreter requests to source a file, it
59
uses the token in the virtual path as part of the file name to source; the
60
master interpreter transparently
61
translates the token into a real directory name and executes the
62
requested operation (see the section \fBSECURITY\fR below for details).
63
Different levels of security can be selected by using the optional flags
64
of the commands described below.
65
.PP
66
All commands provided in the master interpreter by the Safe Base reside in
67
the \fBsafe\fR namespace:
68
 
69
.SH COMMANDS
70
The following commands are provided in the master interpreter:
71
.TP
72
\fB::safe::interpCreate\fR ?\fIslave\fR? ?\fIoptions...\fR?
73
Creates a safe interpreter, installs the aliases described in the section
74
\fBALIASES\fR and initializes the auto-loading and package mechanism as
75
specified by the supplied \fBoptions\fR.
76
See the \fBOPTIONS\fR section below for a description of the
77
optional arguments.
78
If the \fIslave\fR argument is omitted, a name will be generated.
79
\fB::safe::interpCreate\fR always returns the interpreter name.
80
.TP
81
\fB::safe::interpInit\fR \fIslave\fR ?\fIoptions...\fR?
82
This command is similar to \fBinterpCreate\fR except it that does not
83
create the safe interpreter. \fIslave\fR must have been created by some
84
other means, like \fBinterp create \-safe\fR.
85
.TP
86
\fB::safe::interpConfigure\fR \fIslave\fR ?\fIoptions...\fR?
87
If no \fIoptions\fR are given, returns the settings for all options for the
88
named safe interpreter as a list of options and their current values
89
for that \fIslave\fR.
90
If a single additional argument is provided,
91
it will return a list of 2 elements \fIname\fR and \fIvalue\fR where
92
\fIname\fR is the full name of that option and \fIvalue\fR the current value
93
for that option and the \fIslave\fR.
94
If more than two additional arguments are provided, it will reconfigure the
95
safe interpreter and change each and only the provided options.
96
See the section on \fBOPTIONS\fR below for options description.
97
Example of use:
98
.RS
99
.CS
100
# Create a new interp with the same configuration as "$i0" :
101
set i1 [eval safe::interpCreate [safe::interpConfigure $i0]]
102
# Get the current deleteHook
103
set dh [safe::interpConfigure $i0  \-del]
104
# Change (only) the statics loading ok attribute of an interp
105
# and its deleteHook (leaving the rest unchanged) :
106
safe::interpConfigure $i0  \-delete {foo bar} \-statics 0 ;
107
.CE
108
.RE
109
.TP
110
\fB::safe::interpDelete\fR \fIslave\fR
111
Deletes the safe interpreter and cleans up the corresponding
112
master interpreter data structures.
113
If a \fIdeleteHook\fR script was specified for this interpreter it is
114
evaluated before the interpreter is deleted, with the name of the
115
interpreter as an additional argument.
116
.TP
117
\fB::safe::interpFindInAccessPath\fR \fIslave\fR \fIdirectory\fR
118
This command finds and returns the token for the real directory
119
\fIdirectory\fR in the safe interpreter's current virtual access path.
120
It generates an error if the directory is not found.
121
Example of use:
122
.RS
123
.CS
124
$slave eval [list set tk_library [::safe::interpFindInAccessPath $name $tk_library]]
125
.CE
126
.RE
127
.TP
128
\fB::safe::interpAddToAccessPath\fR \fIslave\fR \fIdirectory\fR
129
This command adds \fIdirectory\fR to the virtual path maintained for the
130
safe interpreter in the master, and returns the token that can be used in
131
the safe interpreter to obtain access to files in that directory.
132
If the directory is already in the virtual path, it only returns the token
133
without adding the directory to the virtual path again.
134
Example of use:
135
.RS
136
.CS
137
$slave eval [list set tk_library [::safe::interpAddToAccessPath $name $tk_library]]
138
.CE
139
.RE
140
.TP
141
\fB::safe::setLogCmd\fR ?\fIcmd arg...\fR?
142
This command installs a script that will be called when interesting
143
life cycle events occur for a safe interpreter.
144
When called with no arguments, it returns the currently installed script.
145
When called with one argument, an empty string, the currently installed
146
script is removed and logging is turned off.
147
The script will be invoked with one additional argument, a string
148
describing the event of interest.
149
The main purpose is to help in debugging safe interpreters.
150
Using this facility you can get complete error messages while the safe
151
interpreter gets only generic error messages.
152
This prevents a safe interpreter from seeing messages about failures
153
and other events that might contain sensitive information such as real
154
directory names.
155
.RS
156
Example of use:
157
.CS
158
::safe::setLogCmd puts stderr
159
.CE
160
Below is the output of a sample session in which a safe interpreter
161
attempted to source a file not found in its virtual access path.
162
Note that the safe interpreter only received an error message saying that
163
the file was not found:
164
.CS
165
NOTICE for slave interp10 : Created
166
NOTICE for slave interp10 : Setting accessPath=(/foo/bar) staticsok=1 nestedok=0 deletehook=()
167
NOTICE for slave interp10 : auto_path in interp10 has been set to {$p(:0:)}
168
ERROR for slave interp10 : /foo/bar/init.tcl: no such file or directory
169
.CE
170
.RE
171
 
172
.SH OPTIONS
173
The following options are common to
174
\fB::safe::interpCreate\fR, \fB::safe::interpInit\fR,
175
and \fB::safe::interpConfigure\fR.
176
Any option name can be abbreviated to its minimal
177
non-ambiguous name.
178
Option names are not case sensitive.
179
.TP
180
\fB\-accessPath\fR \fIdirectoryList\fR
181
This option sets the list of directories from which the safe interpreter
182
can \fBsource\fR and \fBload\fR files.
183
If this option is not specified, or if it is given as the
184
empty list, the safe interpreter will use the same directories as its
185
master for auto-loading.
186
See the section \fBSECURITY\fR below for more detail about virtual paths,
187
tokens and access control.
188
.TP
189
\fB\-statics\fR \fIboolean\fR
190
This option specifies if the safe interpreter will be allowed
191
to load statically linked packages (like \fBload {} Tk\fR).
192
The default value is \fBtrue\fR :
193
safe interpreters are allowed to load statically linked packages.
194
.TP
195
\fB\-noStatics\fR
196
This option is a convenience shortcut for \fB-statics false\fR and
197
thus specifies that the safe interpreter will not be allowed
198
to load statically linked packages.
199
.TP
200
\fB\-nested\fR \fIboolean\fR
201
This option specifies if the safe interpreter will be allowed
202
to load packages into its own sub-interpreters.
203
The default value is \fBfalse\fR :
204
safe interpreters are not allowed to load packages into
205
their own sub-interpreters.
206
.TP
207
\fB\-nestedLoadOk\fR
208
This option is a convenience shortcut for \fB-nested true\fR and
209
thus specifies the safe interpreter will be allowed
210
to load packages into its own sub-interpreters.
211
.TP
212
\fB\-deleteHook\fR \fIscript\fR
213
When this option is given an non empty \fIscript\fR, it will be
214
evaluated in the master with the name of
215
the safe interpreter as an additional argument
216
just before actually deleting the safe interpreter.
217
Giving an empty value removes any currently installed deletion hook
218
script for that safe interpreter.
219
The default value (\fB{}\fR) is not to have any deletion call back.
220
.SH ALIASES
221
The following aliases are provided in a safe interpreter:
222
.TP
223
\fBsource\fR \fIfileName\fR
224
The requested file, a Tcl source file, is sourced into the safe interpreter
225
if it is found.
226
The \fBsource\fR alias can only source files from directories in
227
the virtual path for the safe interpreter. The \fBsource\fR alias requires
228
the safe interpreter to
229
use one of the token names in its virtual path to denote the directory in
230
which the file to be sourced can be found.
231
See the section on \fBSECURITY\fR for more discussion of restrictions on
232
valid filenames.
233
.TP
234
\fBload\fR \fIfileName\fR
235
The requested file, a shared object file, is dynamically loaded into the
236
safe interpreter if it is found.
237
The filename must contain a token name mentioned in the virtual path for
238
the safe interpreter for it to be found successfully.
239
Additionally, the shared object file must contain a safe entry point; see
240
the manual page for the \fBload\fR command for more details.
241
.TP
242
\fBfile\fR ?\fIsubCmd args...\fR?
243
The \fBfile\fR alias provides access to a safe subset of the subcommands of
244
the \fBfile\fR command; it allows only \fBdirname\fR, \fBjoin\fR,
245
\fBextension\fR, \fBroot\fR, \fBtail\fR, \fBpathname\fR and \fBsplit\fR
246
subcommands. For more details on what these subcommands do see the manual
247
page for the \fBfile\fR command.
248
.TP
249
\fBexit\fR
250
The calling interpreter is deleted and its computation is stopped, but the
251
Tcl process in which this interpreter exists is not terminated.
252
 
253
.SH SECURITY
254
The Safe Base does not attempt to completely prevent annoyance and
255
denial of service attacks. These forms of attack prevent the
256
application or user from temporarily using the computer to perform
257
useful work, for example by consuming all available CPU time or
258
all available screen real estate.
259
These attacks, while aggravating, are deemed to be of lesser importance
260
in general than integrity and privacy attacks that the Safe Base
261
is to prevent.
262
.PP
263
The commands available in a safe interpreter, in addition to
264
the safe set as defined in \fBinterp\fR manual page, are mediated aliases
265
for \fBsource\fR, \fBload\fR, \fBexit\fR, and a safe subset of \fBfile\fR.
266
The safe interpreter can also auto-load code and it can request that
267
packages be loaded.
268
.PP
269
Because some of these commands access the local file system, there is a
270
potential for information leakage about its directory structure.
271
To prevent this, commands that take file names as arguments in a safe
272
interpreter use tokens instead of the real directory names.
273
These tokens are translated to the real directory name while a request to,
274
e.g., source a file is mediated by the master interpreter.
275
This virtual path system is maintained in the master interpreter for each safe
276
interpreter created by \fB::safe::interpCreate\fR or initialized by
277
\fB::safe::interpInit\fR and
278
the path maps tokens accessible in the safe interpreter into real path
279
names on the local file system thus preventing safe interpreters
280
from gaining knowledge about the
281
structure of the file system of the host on which the interpreter is
282
executing.
283
The only valid file names arguments
284
for the \fBsource\fR and \fBload\fR aliases provided to the slave
285
are path in the form of
286
\fB[file join \fR\fItoken filename\fR\fB]\fR (ie, when using the
287
native file path formats: \fItoken\fR\fB/\fR\fIfilename\fR
288
on Unix, \fItoken\fR\fB\\\fIfilename\fR on Windows,
289
and \fItoken\fR\fB:\fR\fIfilename\fR on the Mac),
290
where \fItoken\fR is representing one of the directories
291
of the \fIaccessPath\fR list and \fIfilename\fR is
292
one file in that directory (no sub directories access are allowed).
293
.PP
294
When a token is used in a safe interpreter in a request to source or
295
load a file, the token is checked and
296
translated to a real path name and the file to be
297
sourced or loaded is located on the file system.
298
The safe interpreter never gains knowledge of the actual path name under
299
which the file is stored on the file system.
300
.PP
301
To further prevent potential information leakage from sensitive files that
302
are accidentally included in the set of files that can be sourced by a safe
303
interpreter, the \fBsource\fR alias restricts access to files
304
meeting the following constraints: the file name must
305
fourteen characters or shorter, must not contain more than one dot ("\fB.\fR"),
306
must end up with the extension \fB.tcl\fR or be called \fBtclIndex\fR.
307
.PP
308
Each element of the initial access path
309
list will be assigned a token that will be set in
310
the slave \fBauto_path\fR and the first element of that list will be set as
311
the \fBtcl_library\fR for that slave.
312
.PP
313
If the access path argument is not given or is the empty list,
314
the default behavior is to let the slave access the same packages
315
as the master has access to (Or to be more precise:
316
only packages written in Tcl (which by definition can't be dangerous
317
as they run in the slave interpreter) and C extensions that
318
provides a Safe_Init entry point). For that purpose, the master's
319
\fBauto_path\fR will be used to construct the slave access path.
320
In order that the slave successfully loads the Tcl library files
321
(which includes the auto-loading mechanism itself) the \fBtcl_library\fR will be
322
added or moved to the first position if necessary, in the
323
slave access path, so the slave
324
\fBtcl_library\fR will be the same as the master's (its real
325
path will still be invisible to the slave though).
326
In order that auto-loading works the same for the slave and
327
the master in this by default case, the first-level
328
sub directories of each directory in the master \fBauto_path\fR will
329
also be added (if not already included) to the slave access path.
330
You can always specify a more
331
restrictive path for which sub directories will never be searched by
332
explicitly specifying your directory list with the \fB\-accessPath\fR flag
333
instead of relying on this default mechanism.
334
.PP
335
When the \fIaccessPath\fR is changed after the first creation or
336
initialization (ie through \fBinterpConfigure -accessPath \fR\fIlist\fR),
337
an \fBauto_reset\fR is automatically evaluated in the safe interpreter
338
to synchronize its \fBauto_index\fR with the new token list.
339
 
340
.SH "SEE ALSO"
341
interp(n), library(n), load(n), package(n), source(n), unknown(n)
342
 
343
.SH KEYWORDS
344
alias, auto\-loading, auto_mkindex, load, master interpreter, safe
345
interpreter, slave interpreter, source

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.