Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random SEGV in do_send_query() #1150

Merged
merged 1 commit into from Feb 24, 2021
Merged

Random SEGV in do_send_query() #1150

merged 1 commit into from Feb 24, 2021

Conversation

unak
Copy link
Contributor

@unak unak commented Dec 18, 2020

We found an random SEGV in mysql2 0.5.3, such as:

-- C level backtrace information -------------------------------------------
/usr/local/lib/libruby.so.2.6(rb_vm_bugreport+0x4f1) [0x7f53f023c251] vm_dump.c:715
/usr/local/lib/libruby.so.2.6(rb_bug_context+0xe7) [0x7f53f008ca27] error.c:609
/usr/local/lib/libruby.so.2.6(sigsegv+0x42) [0x7f53f01a5672] signal.c:998
/lib/x86_64-linux-gnu/libpthread.so.0(__restore_rt+0x0) [0x7f53efbac0e0]
/lib/x86_64-linux-gnu/libc.so.6(0x7f53eed5a0ba) [0x7f53eed5a0ba]
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18(0x7f53e3c595a9) [0x7f53e3c595a9]
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18(0x7f53e3c59b3f) [0x7f53e3c59b3f]
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18(0x7f53e3c512e4) [0x7f53e3c512e4]
/usr/lib/x86_64-linux-gnu/libmariadbclient.so.18(mysql_send_query+0x3e) [0x7f53e3c4e96e]
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.so(nogvl_send_query+0x14) [0x7f53e42267a4] client.c:511
/usr/local/lib/libruby.so.2.6(rb_thread_call_without_gvl+0x7d) [0x7f53f01e9d2d] thread.c:1442
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.so(do_send_query+0x1d) [0x7f53e422709d] client.c:519
/usr/local/lib/libruby.so.2.6(rb_rescue2+0xe6) [0x7f53f0096ac6] eval.c:935
/home/circleci/project/vendor/bundle/ruby/2.6.0/gems/mysql2-0.5.3/lib/mysql2/mysql2.so(rb_mysql_query+0xf7) [0x7f53e4228747] client.c:787

(this log is token from CircleCI)

In rb_mysql_query(), the raw pointer of the sql string is extracted,
and it is passed to do_send_query() via args.
do_send_query() internally releases the GVL, then ruby might do GC
in the function.
Then, the sql string may be GC'ed, and causes SEGV.
Therefore, should guard the sql string until do_send_query() ends.

In `rb_mysql_query()`, the raw pointer of the sql string is extracted,
and it is passed to `do_send_query()` via `args`.
`do_send_query()` internally releases the GVL, then ruby might do GC
in the function.
Then, the sql string may be GC'ed, and causes SEGV.
Therefore, should guard the sql string until `do_send_query()` ends.
@sodabrew sodabrew merged commit 88fddbc into brianmario:master Feb 24, 2021
@sodabrew sodabrew added this to the 0.5.4 milestone Feb 24, 2021
@sodabrew
Copy link
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants