| Ticket UUID: | 2835313 | ||
| Title: | crash in exception handling | ||
| Type: | Bug | Created on: | 2009-08-11 03:09:56 |
| Submitter: | dgp | Assigned to: | dkf |
| Subsystem: | 47. Bytecode Compiler | Severity: | Severe |
| Priority: | 7 High | Last modified: | 2014-10-11 16:03:42 |
| Status: | Closed | Closed by: | dkf |
| Resolution: | Fixed | Closed on: | 2014-10-11 16:03:42 |
| Version: | obsolete: 8.5.7 | ||
| Description: | ||||
% proc foo args {puts $args}
% while 1 {foo 1 2 3 [continue] 5 6}
Segmentation fault
Also crashes 8.4.19, 8.3.5, 8.2.3, 8.1.0
Hangs 8.0.5
Something deep in the design of
ExceptionRanges etc. just doesn't
handle this right.
| ||||
| User Comments: | ||||
dgp added on 2009-08-11 10:38:45:
Joe Mistachkin kindly reminds me that hanging it proper functioning for this example. dgp added on 2009-08-11 11:27:50:
From a debug build:
% while 1 {foo [continue]}
Bad stack top 2 at pc 2 in TclExecuteByteCode (min 0, max 1)
executing continue
TclExecuteByteCode execution failure: bad stack top
Program received signal SIGABRT, Aborted.
0x40000402 in __kernel_vsyscall ()
msofer added on 2009-08-22 04:42:06:
This cannot be fixed easily without deep changes in the exception range mechanism, or possibly some costly extra functionality in INST_START_CMD. The problem is that the exec stack depth is not recorded on entering an exception range: neither at compile time, which would be iffy, nor at run time (catch does it with INST_BEGIN_CATCH). Given this, there is no way to restore the stack when jumping to one of the special targets (continue or break). The whole mechanism just ASSUMES that the stack is at its proper depth when a jump to one of the targets occurs. That is: a solution to this problem is possible, but it will definitely break in a difficult-to-fix way [tbcloading] old precompiled programs. Some day we might decide to do that. dkf added on 2010-09-01 17:56:20:
This issue was encountered yesterday on the Tcler's chat when kbk was trying to explain to dogeen what an exception range is. One possible fix would be to create an extra instruction which clears the stack down to a given mark. Old code wouldn't use it, but that's also probably not having a problem anyway. dkf added on 2013-06-05 15:15:17:
allow_comments - 1
Fixed on trunk. Will not backport as the changes were quite extensive internally (and dealing with jumping past {*}expansion required a new opcode).
dkf added on 2013-10-20 18:41:35:
Dealt with the other ways in which exceptions could be generated. Evilness abounded! Analysis! This was in fact one of the most serious bugs in Tcl's implementation that existed; it allowed a whole range of attacks against Tcl deployments that were impossible to guard against without totally crippling the language. I'm only willing to admit just how serious this was now that I've got code in place that makes the problem impossible to exploit, though it should be noted that a backport to 8.5 is definitely impossible.Execution of untrusted code in a critical environment will be strongly recommended against until Tcl 8.6.2. This applies even in a safe interpreter. It is not believed possible to exploit this in any way other than forcing a process to hang or crash, as it is not possible for the attacker to control the locations of any values in Tcl or to force them to be placed at any known location. Mitigation StrategiesA mitigation is to use a build of Tcl that has been configured with --enable-symbols=compile, as that will trap Tcl execution stack imbalances and convert them into definite crashes (i.e., a call to Tcl_Panic()); the disadvantage of that mechanism is that there is a substantial performance penalty. Code must also be written to cope with the process crashing (if desired), perhaps via a watchdog parent process; at the point where the problem is detected, insufficient information remains in the process to determine what the cause was.dgp added on 2013-10-21 14:51:13:
Troubles on the trunk (--enable-symbols=all testing):
---- assemble-16.5 start
Test file error: bad stack adjustment when compiling tcl::unsupported::assemble (was -1 instead of 1)
---- for-7.14 start
Test file error:
Bad stack top 13 at pc 182 in TclNRExecuteByteCode (min 0, max 12)
executing for {set x 0} {[incr x]<50} {} {
puts [puts {*}$l {*}[puts a b c {*}$l {*}[apply {{} {
re...
TclNRExecuteByteCode execution failure: bad stack top
dgp added on 2013-10-21 16:24:09:
Other panicking tests: assemble-16.6 assemble-30.[123] for-7.22 dkf added on 2013-10-21 18:28:45:
for-7.* are the tests I've committed specifically to detect issues relating to this bug; they try very hard to break things. dkf added on 2013-10-22 14:31:21:
Problems in for.test were due to a total think-o. Still investigating assemble.test… dkf added on 2013-10-22 18:28:45:
Only simple fix for assemble.test problems is to roll back the changes in tclAssemble.c.
dgp added on 2014-10-09 15:12:33:
Anything left to do here? dkf added on 2014-10-11 16:03:42:
No. The issues that remain with the assembler are deep and nasty, but need addressing in the assembler through different mechanisms. Since there's no explicit break, continue or return... instructions, the problems are as averted as I can manage. (The real fix would involve using something like beginCatch/endCatch for all loops. Which is heavyweight.) | ||||
