Bug #91603 | stack-use-after-scope in reinit_io_cache() detected by ASan | ||
---|---|---|---|
Submitted: | 11 Jul 2018 17:54 | Modified: | 18 Feb 2021 9:29 |
Reporter: | Yura Sorokin (OCA) | Email Updates: | |
Status: | Duplicate | Impact on me: | |
Category: | MySQL Server: Compiling | Severity: | S2 (Serious) |
Version: | 5.5.60, 5.6.40 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | Contribution |
[11 Jul 2018 17:54]
Yura Sorokin
[11 Jul 2018 17:56]
Yura Sorokin
The problem is already known as Bug #24343330 "READ OF OUT-OF-SCOPE (TEMPFILE) IN MYSQL_UPDATE()" and was fixed in 8.0.4 (https://github.com/mysql/mysql-server/commit/4d5ff7bfbf8) and 5.7.21 (https://github.com/mysql/mysql-server/commit/e49e52a5de7) but never backported to 5.6 and 5.5.
[11 Jul 2018 17:58]
Yura Sorokin
Although 'IO_CACHE tempfile' declared inside an inner block in 'mysql_update()' function is copied by value to 'select->file' select->file=tempfile this operation is not safe as some of the members inside IO_CACHE struct were initialized with addresses of other data members. In particular, in 'setup_io_cache()', called from 'init_functions()', called from 'init_io_cache()', called from 'open_cached_file()' 'current_pos' and 'current_end' are initialized with such addresses. /* Ensure that my_b_tell() and my_b_bytes_in_cache works */ if (info->type == WRITE_CACHE) { info->current_pos= &info->write_pos; info->current_end= &info->write_end; } else { info->current_pos= &info->read_pos; info->current_end= &info->read_end; } Suggested fix: call setup_io_cache(&select->file); after that assignment.
[11 Jul 2018 18:05]
Yura Sorokin
A patch to make 5.5 code compilable with GCC 7.3/8.0 (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: mysql_5_5_gcc_7_3_asan_fix.diff (application/octet-stream, text), 1.33 KiB.
[11 Jul 2018 18:08]
Yura Sorokin
5.5 patch (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: bug91603_5_5.diff (application/octet-stream, text), 421 bytes.
[11 Jul 2018 18:10]
Yura Sorokin
5.6 patch (*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.
Contribution: bug91603_5_6.diff (application/octet-stream, text), 443 bytes.
[12 Jul 2018 8:00]
MySQL Verification Team
Hello Yura Sorokin, Thank you for the report and contribution. Thanks, Umesh
[20 Nov 2018 11:38]
Dyre Tjeldvoll
Posted by developer: Thank you for providing the contribution! As you can see from earlier comments this issue has been fixed in newer versions, and we have chosen not to backport the fix to earlier versions.
[18 Feb 2021 9:29]
Erlend Dahl
Duplicate of Bug#82220 Read of out-of-scope (tempfile) in mysql_update()