rstudio/websocket

ASAN memory error

wch opened this issue · 2 comments

wch commented

To reproduce:

docker run --rm -ti wch1/r-debug

RDsan
devtools::install_github('rstudio/websocket')

library(websocket)

ws <- WebSocket$new("ws://echo.websocket.org/")
# Wait for a moment
ws$send("hello\n")

When it sends the message, this error occurs:

=================================================================
==29327==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe20d518a0 at pc 0x7f143c6dfd1d bp 0x7ffe20d51870 sp 0x7ffe20d51018
WRITE of size 8 at 0x7ffe20d518a0 thread T0
    #0 0x7f143c6dfd1c  (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x99d1c)
    #1 0x7f143bec33e2 in Rf_matchArgs /tmp/r-source/src/main/match.c:210
    #2 0x7f143bd06afc in do_substitute /tmp/r-source/src/main/coerce.c:2725
    #3 0x7f143be44ee4 in bcEval /tmp/r-source/src/main/eval.c:6791
    #4 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #5 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #6 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #7 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #8 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #9 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #10 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #11 0x7f143be17f4b in Rf_eval /tmp/r-source/src/main/eval.c:743
    #12 0x7f143be22821 in do_begin /tmp/r-source/src/main/eval.c:2382
    #13 0x7f143be17707 in Rf_eval /tmp/r-source/src/main/eval.c:695
    #14 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #15 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #16 0x7f143be17f4b in Rf_eval /tmp/r-source/src/main/eval.c:743
    #17 0x7f143be22821 in do_begin /tmp/r-source/src/main/eval.c:2382
    #18 0x7f143be17707 in Rf_eval /tmp/r-source/src/main/eval.c:695
    #19 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #20 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #21 0x7f143be17f4b in Rf_eval /tmp/r-source/src/main/eval.c:743
    #22 0x7f143be27f41 in do_eval /tmp/r-source/src/main/eval.c:3186
    #23 0x7f143be4497f in bcEval /tmp/r-source/src/main/eval.c:6771
    #24 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #25 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #26 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #27 0x7f143be17f4b in Rf_eval /tmp/r-source/src/main/eval.c:743
    #28 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #29 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #30 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #31 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #32 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #33 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #34 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #35 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #36 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #37 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #38 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #39 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #40 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #41 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #42 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #43 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #44 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #45 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #46 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #47 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #48 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #49 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #50 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #51 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #52 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #53 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #54 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #55 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #56 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #57 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #58 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #59 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #60 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #61 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #62 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #63 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #64 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #65 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #66 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #67 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #68 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #69 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #70 0x7f143be16493 in forcePromise /tmp/r-source/src/main/eval.c:516
    #71 0x7f143be2e109 in FORCE_PROMISE /tmp/r-source/src/main/eval.c:4897
    #72 0x7f143be2e9c9 in getvar /tmp/r-source/src/main/eval.c:4970
    #73 0x7f143be3d7c2 in bcEval /tmp/r-source/src/main/eval.c:6523
    #74 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #75 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #76 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #77 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #78 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #79 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #80 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #81 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #82 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #83 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #84 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #85 0x7f143be440cb in bcEval /tmp/r-source/src/main/eval.c:6739
    #86 0x7f143be16c82 in Rf_eval /tmp/r-source/src/main/eval.c:620
    #87 0x7f143be1cb1e in R_execClosure /tmp/r-source/src/main/eval.c:1780
    #88 0x7f143be1c26c in Rf_applyClosure /tmp/r-source/src/main/eval.c:1706
    #89 0x7f143be17f4b in Rf_eval /tmp/r-source/src/main/eval.c:743
    #90 0x7f142cb3bdce in Rcpp::internal::Rcpp_eval_impl(SEXPREC*, SEXPREC*) /usr/local/RDsan/lib/R/site-library/Rcpp/include/Rcpp/api/meat/Rcpp_eval.h:49
    #91 0x7f142cb3c155 in Rcpp::Rcpp_eval(SEXPREC*, SEXPREC*) /usr/local/RDsan/lib/R/site-library/Rcpp/include/Rcpp/api/meat/Rcpp_eval.h:92
    #92 0x7f142cb3bdf3 in Rcpp::Rcpp_fast_eval(SEXPREC*, SEXPREC*) /usr/local/RDsan/lib/R/site-library/Rcpp/include/Rcpp/api/meat/Rcpp_eval.h:69
    #93 0x7f142cb5ce8c in Rcpp::Function_Impl<Rcpp::PreserveStorage>::operator()() const (/usr/local/RDsan/lib/R/site-library/later/libs/later.so+0x142e8c)
    #94 0x7f142cb5a933 in boost::detail::function::void_function_obj_invoker0<Rcpp::Function_Impl<Rcpp::PreserveStorage>, void>::invoke(boost::detail::function::function_buffer&) (/usr/local/RDsan/lib/R/site-library/later/libs/later.so+0x140933)
    #95 0x7f142cb64706 in boost::function0<void>::operator()() const /usr/local/RD/lib/R/library/BH/include/boost/function/function_template.hpp:763
    #96 0x7f142cb6363b in Callback::operator()() const /tmp/Rtmpm9zFKv/R.INSTALL75159ef503/later/src/callback_registry.h:26
    #97 0x7f142cb619fe in execCallbacks(double, bool) /tmp/Rtmpm9zFKv/R.INSTALL75159ef503/later/src/later.cpp:98
    #98 0x7f142cb61bb7 in execCallbacksForTopLevel() /tmp/Rtmpm9zFKv/R.INSTALL75159ef503/later/src/later.cpp:116
    #99 0x7f142cb6a20a in async_input_handler /tmp/Rtmpm9zFKv/R.INSTALL75159ef503/later/src/later_posix.cpp:124
    #100 0x7f143c0b6086 in R_runHandlers /tmp/r-source/src/unix/sys-std.c:410
    #101 0x7f143c0b865e in Rstd_ReadConsole /tmp/r-source/src/unix/sys-std.c:1060
    #102 0x7f143c0ba579 in R_ReadConsole /tmp/r-source/src/unix/system.c:72
    #103 0x7f143bebbaee in Rf_ReplIteration /tmp/r-source/src/main/main.c:208
    #104 0x7f143bebc1d4 in R_ReplConsole /tmp/r-source/src/main/main.c:310
    #105 0x7f143bebe644 in run_Rmainloop /tmp/r-source/src/main/main.c:1086
    #106 0x7f143bebe65a in Rf_mainloop /tmp/r-source/src/main/main.c:1093
    #107 0x565478400ac0 in main /tmp/r-source/src/main/Rmain.c:29
    #108 0x7f143aa42b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #109 0x565478400999 in _start (/usr/local/RDsan/lib/R/bin/exec/R+0x999)

Address 0x7ffe20d518a0 is located in stack of thread T0
SUMMARY: AddressSanitizer: stack-use-after-scope (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x99d1c) 
Shadow bytes around the buggy address:
  0x1000441a22c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a22d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a22e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a22f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a2300: 00 00 00 00 00 00 00 00 f8 f8 f8 f8 f8 f8 f8 f8
=>0x1000441a2310: ca ca ca ca[f8]cb cb cb cb cb cb cb 00 00 00 00
  0x1000441a2320: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a2330: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a2340: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a2350: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1000441a2360: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==29327==ABORTING

This is with:

R Under development (unstable) (2019-02-25 r76159) -- "Unsuffered Consequences"
wch commented

Looking at the source, that it refers to, I don't see how it could be usage of a stack variable that has gone out of scope:

https://github.com/wch/r-source/blob/247ec801e191a6f77e08c38176ada7f9c4a46421/src/main/match.c#L210

wch commented

Closing because this is probably a false alarm.