[MDEV-11896] thd_get_error_context_description race condition Created: 2017-01-24 Updated: 2020-12-17 Resolved: 2017-07-20 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server |
| Affects Version/s: | 5.5.54, 10.1.21, 10.2.4, 10.0.28-galera |
| Fix Version/s: | 10.1.26, 10.0.32, 10.2.8 |
| Type: | Bug | Priority: | Major |
| Reporter: | TYNDALE BANZA | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | contribution, foundation, patch, security | ||
| Environment: |
OS Ubuntu 14.04.5 LTS |
||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
A Galera Cluster node crashed with the stack trace below
|
| Comments |
| Comment by Elena Stepanova [ 2017-01-30 ] | ||||||||||||||||||||||||||||
|
Is it reproducible, or happens periodically, or happened only once? | ||||||||||||||||||||||||||||
| Comment by TYNDALE BANZA [ 2017-01-31 ] | ||||||||||||||||||||||||||||
|
This error is not reproducible . It happened only once . Only one node crashed . The log files do not show anything significant before the crash . | ||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2017-02-24 ] | ||||||||||||||||||||||||||||
|
I'm afraid there isn't much we can do about it at the moment, only wait till somebody else reports something similar and then compare circumstances and information. | ||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-02-25 ] | ||||||||||||||||||||||||||||
|
Looking at the stack trace thd_get_error_context_description calls string append and then segfaults. Under http://www.cplusplus.com/reference/string/string/append/ a string.append with insufficient space results in undefined behaviour, in this case a segfault. https://github.com/MariaDB/server/blob/10.1/sql/sql_class.cc#L715 does append a lot of information like IP, username and query is appended to the str of length provided to it by its caller and at no point during this function is there an examination as to how much space is left. At least one call passes a 1K buffer - myisam::_mi_report_crashed. Innodb and xtradb also pass a 1k buffer (innobase_mysql_print_thd). Queries of over 1K as messy as they are are plausible. Rewriting thd_get_error_context_description to protect against buffer overflows even if all the information doesn't get in the buffer seems like a prudent and feasible solution. | ||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-02-25 ] | ||||||||||||||||||||||||||||
|
Also appears in 5.5 as thd_security_context | ||||||||||||||||||||||||||||
| Comment by Daniel Black [ 2017-02-25 ] | ||||||||||||||||||||||||||||
|
quite a few other upstream mysql bugs too but still appears in mysql-5.7 | ||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2017-03-09 ] | ||||||||||||||||||||||||||||
|
String::append() reallocates automatically, it can never overflow a buffer. That's why this code at the end:
| ||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2020-01-30 ] | ||||||||||||||||||||||||||||
|
The attempt to fix this caused server hangs when InnoDB detects a deadlock between transactions ( tbanza, if you can repeat this problem with 10.1.41, 10.2.25, or 10.3 or later, please file a new bug and mark it related to this one. | ||||||||||||||||||||||||||||