Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2018-11-19
07:34 • Closed ticket [00d04c4f12]: base64 transchan over a refchan: segmentation fault<... artifact: 625eef4f02 user: sebres
2018-11-16
18:45
[00d04c4f12] Repair broken edge cases in [binary encode base64]. closed check-in: 770e6649a4 user: dgp tags: release, core-8-6-9-rc, core-8-6-9
18:38
[00d04c4f12] Repair broken edge cases in [binary encode base64]. check-in: 4b91471ac4 user: dgp tags: core-8-6-branch
2018-11-15
22:35 • Fixed ticket [00d04c4f12]: transchan over a refchan: segmentation fault plus... artifact: b40f453731 user: sebres
22:31
fixes segfault [00d04c4f12], unfulfilled base64 (strict and non-strict mode, etc). closed check-in: ea2419de23 user: sebres tags: bug-00d04c4f12
22:18
test cases for decode base64, bug [00d04c4f12], unfulfilled base64 (strict and non-strict mode, etc)... check-in: 60ba3af5db user: sebres tags: bug-00d04c4f12
16:20 • Ticket [00d04c4f12] transchan over a refchan: segmentation fault status stil... artifact: 6144984a28 user: sebres
2018-11-14
19:53 • New ticket [00d04c4f12]. artifact: 624fc3a85c user: pooryorick

base64 transchan over a refchan: segmentation fault

Closed / Fixed00d04c4f120904aa0c6bd76d542d57f4a0dd2eb3Created 8 years agoUpdated 8 years ago
Descriptionwiki2018-11-14 19:53:36
The following script:

package require base64
package require tcl::chan::string
package require tcl::transform::base64
set chan [tcl::chan::string {T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl
ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt
b3RlLU1UQTogNTMuMjQuMjgyLjE1MA=
}]

tcl::transform::base64 $chan
puts [read $chan]

produces a segmentation fault:

#0  0x00007ffff793df53 in __memmove_avx_unaligned_erms () from /usr/lib/libc.so.6
#1  0x00007ffff7ef1249 in ResultAdd (rPtr=0x55555561bdf8, buf=0x55555566fd88 "\300\306`UUU", toWrite=-1) at /path/to/generic/tclIORTrans.c:3005
#2  0x00007ffff7ef199a in TransformDrain (rtPtr=0x55555561bda0, errorCodePtr=0x7fffffffdac0) at /path/to/generic/tclIORTrans.c:3239

Beware! This is the kind of report that could contain a trojan script that could conduct a terminal attack to execute arbitrary code.

Referenced by4
  • 770e6649a4[00d04c4f12] Repair broken edge cases in [binary encode base64]. check-in2018-11-16 18:45:59
  • 4b91471ac4[00d04c4f12] Repair broken edge cases in [binary encode base64]. check-in2018-11-16 18:38:35
  • ea2419de23fixes segfault [00d04c4f12], unfulfilled base64 (strict and non-strict mode, etc). check-in2018-11-15 22:31:39
  • 60ba3af5dbtest cases for decode base64, bug [00d04c4f12], unfulfilled base64 (strict and non-strict mode, etc). check-in2018-11-15 22:18:29
sebreswiki2018-11-15 16:20:48

I have rewritten this for debug purposes without tcllib and simplest proc-handlers with debugging info:

This produces following result...

  *********** initialize rc0 {read write} -
push rc0 ...
  *********== initialize rt0 {read write} -
read from rc0 ...
  *********** read rc0 4096 - current pos: 0, current buf: 189
    ********* pos: 189, r: `T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl
  ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt
  b3RlLU1UQTogNTMuMjQuMjgyLjE1MA=` --
  *********== read rt0 {T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl
  ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt
  b3RlLU1UQTogNTMuMjQuMjgyLjE1MA=} - current pos: 0, current buf: 0
  *********== base64_Code `T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl
  ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt
  b3RlLU1UQTogNTMuMjQuMjgyLjE1MA=`
  *********== base64_Complete `T3JpZ2luYWwtUmVjaXBpZW50OiA8L2ZheD1ibHViYkBndW1taS5ib290PgpBY3Rpb246IGZhaWxl
  ZApEaWFnbm9zdGljLUNvZGU6IHNtdHA7IDU1MCAjNS4xLjAgQWRkcmVzcyByZWplY3RlZC4KUmVt
  b3RlLU1UQTogNTMuMjQuMjgyLjE1MA=`
  *********== base64_Complete, ret: 187
  *********== base64_Code, ret: `Original-Recipient: </[email protected]>
Action: failed
Diagnostic-Code: smtp; 550 #5.1.0 Address rejected.
Remote-MTA: 53.24.282.150`
  *********== read rt0, res: `Original-Recipient: </[email protected]>
Action: failed
Diagnostic-Code: smtp; 550 #5.1.0 Address rejected.
Remote-MTA: 53.24.282.150`
  *********** read rc0 3960 - current pos: 189, current buf: 189
    ********* pos: 189, r: `` --

*********== drain rt0 - current pos: 0, current buf: 1 *********== drain rt0, rest: `=` max size for a Tcl value (2147483647 bytes) exceeded
How one can possibly see, the proc base64_Complete (using in transform channel rt0) calculates invalid offset (187 in opposite to 189 of the original buffer in reflected channel rc0), but full buffer is already transformed.

Further investigation shows that binary decode on "empty" base64 buffer (only "=") produces a panic, with wrong got out (so segfault) within the drain-handler:

% binary decode base64 =
max size for a Tcl value (2147483647 bytes) exceeded
WiP.

sebreswiki2018-11-15 22:35:29

fixed in branch bug-00d04c4f12.

sebresplain2018-11-19 07:34:58
merged
Log in (anonymous is fine) to add a comment.