Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-09-29
01:55 • Closed ticket [3027815fff]: Safe interpreters can use Thread to execute unsafe c... artifact: 8e464f6e60 user: vasiljevic
2010-07-13
23:35 • Ticket [3027815fff]: 4 changes artifact: d000413b6b user: kjnash
2010-07-12
04:45 • Ticket [3027815fff]: 4 changes artifact: aa05f67165 user: dkf
04:41 • Ticket [3027815fff]: 4 changes artifact: c8c3f330c7 user: dkf
2010-07-10
23:13 • Ticket [3027815fff]: 4 changes artifact: ee2828d809 user: vasiljevic
15:26 • New ticket [3027815fff]. artifact: 92df7d6db7 user: kjnash

Safe interpreters can use Thread to execute unsafe commands

Closed / Accepted3027815fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-07-10 15:26:41
A safe interpreter can load all the commands of the Thread package.  This is a security issue, because it means that a safe interpreter can create a new thread and send commands to that thread's unsafe master interpreter:

% ::safe::interpCreate iSafe
iSafe
% iSafe eval pwd
invalid command name "pwd"
% iSafe eval {
    package require Thread
    set tid [thread::create]
    ::thread::send $tid {pwd}
}
/home/user
%

At present the safe entry point Thread_SafeInit gives a safe interpreter access to all the commands of the Thread extension.  For security reasons, at least some of these commands should be removed.

Perhaps safe interpreters should not be allowed any access to Thread commands.  I am not familiar with the whole of the Thread package, but it appears that the natural scope of a thread operation is the master interpreter of the thread.  If a safe interpreter needs limited access to Thread commands, it might be best provided by wrapper commands aliased into the safe slave from its unsafe master - not by loading the Thread package itself.

I suggest removing the safe entry point Thread_SafeInit completely.
vasiljevicplain2010-07-10 23:13:08
Interesting point. Actually I could ask Tcl_IsSafe(interp) of the
interp that creates the thread (the one that calls thread::create)
and inherit that state in the new thread so its interp is also safe.
Would that make sense?
dkfplain2010-07-12 04:41:02
I suggest making thread creation a restricted operation and that a safe interpreter should only be able to communicate with other interpreters that it's master has permitted it to do so to (which would require a new operation; sorry!)

But really, it would be better if there was some way for the (non-safe) master to control messages sent (and what variables are shared, what mutexes are available, etc.) more thoroughly. I've tended to assume that it would be best if the thread extension simply wasn't marked as safe at all; let the master expose (safe) aliases to operations as necessary.
dkfplain2010-07-12 04:45:38
BTW, one safe context isn't the same as another because of the ability to grant exceptions to the rules via aliases. It's possible for there to be two sets of exceptions, each of which is safe on its own, but which are not safe in combination. (Child interpreters of safe interpreters are a special case; they start without any restricted operations at all and the parent safe interpreter can't change that.) It's not ever going to be safe to communicate between safe interps in different threads by default.
kjnashplain2010-07-13 23:35:26
> Interesting point. Actually I could ask Tcl_IsSafe(interp) of the
> interp that creates the thread (the one that calls thread::create)
> and inherit that state in the new thread so its interp is also safe.
> Would that make sense?

That's an interesting suggestion!  However, file/network interaction is normally added to a safe interpreter either by [interp alias] or by sharing sockets: in both cases the slave is configured by its master (or higher ancestor) in the same thread.  If there is no unsafe master, the slave would be of limited value, except for computation.

If the Thread package were to add new mechanisms for using safe interpreters, I think it would create a lot of work for the developers of the Thread package, in particular the need to always be thinking about whether Thread facilities will allow a safe interpreter to execute commands in an unsafe interpreter (or, as Donal mentioned, a different kind of safe interpreter).

However, such new mechanisms in Thread would not add much benefit, because safe interpreters are not widely used, and users will tend to use the safe-interpreter commands that they know, and will probably avoid using the new capabilities in Thread because any extra capabilities will introduce additional complications and security risks.

Also, as far as I know, it is unprecedented to have a safe interpreter as the the root interpreter of a thread or process.  I don't know if it would break anything.  It would impact on development of the core, because the core developers would always have to consider the possibility that the root interpreter may be safe.

I think the best solution is to remove the safe entry point Thread_SafeInit completely.  As Donal said, let the master expose (safe) aliases to operations as necessary.

Keith.
vasiljevicplain2010-09-29 01:55:02
allow_comments - 1

This will now appoear in 2.6.7 patch release.
Log in (anonymous is fine) to add a comment.