MDEV-40644: Slave SQL Thread Overflow on Malformed Table_map_log_event - #5523
Open
bnestere wants to merge 2 commits into
Open
MDEV-40644: Slave SQL Thread Overflow on Malformed Table_map_log_event#5523bnestere wants to merge 2 commits into
bnestere wants to merge 2 commits into
Conversation
A slave can crash when its master sends a Table_map event whose table name is longer than an identifier can be. The SQL thread applying the event copies the name into a fixed buffer and overruns it, and the SQL thread crashes. A Table_map event carries its database and table names each behind a one-byte length. The constructor that parses the event sizes a buffer for each name from its declared length, and do_apply_event() copies both names out of the event into NAME_LEN+1 byte buffers with strmov(). strmov() copies up to the terminating null. A real identifier is at most NAME_LEN bytes, so the name fits the buffer and carries that null. The constructor never bounded the two lengths. Each length is read as a byte, so each can reach 255. The constructor copied each name with strncpy() over the declared length, which writes no terminating null when the source holds none. do_apply_event() then copied the name into its NAME_LEN+1 byte buffer with strmov(), which ran past the buffer until it reached a null elsewhere in the heap. pack_info() read the same names with %s for SHOW RELAYLOG EVENTS, past the buffer in the same way. Bound the lengths in the constructor. It now rejects a Table_map event whose declared database name, or whose declared table name, exceeds NAME_LEN, before it sizes the name buffers, so is_valid() returns false. It also terminates each name it copies, so a source that holds no null does not leave the name unterminated. A master naming a table with an oversized name now stops the slave's SQL thread with ER_SLAVE_RELAY_LOG_READ_FAILURE instead of crashing it. Reviewed-by: TODO Signed-off-by: Brandon Nesterenko <brandon.nesterenko@mariadb.com>
Member
|
Brandon Nesterenko ***@***.***> writes:
A slave can crash when its master sends a Table_map event whose table
name is longer than an identifier can be. The SQL thread applying the
event copies the name into a fixed buffer and overruns it, and the SQL
thread crashes.
Looks fine Brandon, thanks!
Reviewed-by: Kristian Nielsen ***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
** This will actually go into 10.11, but the work I did was on 10.6, so let's do the review on 10.6 and I'll just push it to 10.11**
A slave can crash when its master sends a Table_map event whose table
name is longer than an identifier can be. The SQL thread applying the
event copies the name into a fixed buffer and overruns it, and the SQL
thread crashes.
A Table_map event carries its database and table names each behind a
one-byte length. The constructor that parses the event sizes a buffer
for each name from its declared length, and do_apply_event() copies
both names out of the event into NAME_LEN+1 byte buffers with strmov().
strmov() copies up to the terminating null. A real identifier is at
most NAME_LEN bytes, so the name fits the buffer and carries that null.
The constructor never bounded the two lengths. Each length is read as a
byte, so each can reach 255. The constructor copied each name with
strncpy() over the declared length, which writes no terminating null
when the source holds none. do_apply_event() then copied the name into
its NAME_LEN+1 byte buffer with strmov(), which ran past the buffer
until it reached a null elsewhere in the heap. pack_info() read the
same names with %s for SHOW RELAYLOG EVENTS, past the buffer in the
same way.
Bound the lengths in the constructor. It now rejects a Table_map event
whose declared database name, or whose declared table name, exceeds
NAME_LEN, before it sizes the name buffers, so is_valid() returns
false. It also terminates each name it copies, so a source that holds
no null does not leave the name unterminated. A master naming a table
with an oversized name now stops the slave's SQL thread with
ER_SLAVE_RELAY_LOG_READ_FAILURE instead of crashing it.
This PR is organized as follows. The first commit shows the regression, and
the second commit contains the fix.