Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1915502

Summary: Segfault and possible DoS with a crafted query
Product: Red Hat Enterprise Linux 8 Reporter: t_j80
Component: mysqlAssignee: Michal Schorm <mschorm>
Status: CLOSED CURRENTRELEASE QA Contact: Jakub Heger <jheger>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 8.0CC: databases-maint, hhorak, jkejda, ljavorsk, mschorm
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: 8.5Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Rebase: Bug Fixes Only
Doc Text:
Rebase package(s) to version: 8.0.22 Important bug fixes: Crash on a specific SQL query. See comment #1 for more info.
Story Points: ---
Clone Of:
: 1996699 (view as bug list) Environment:
Last Closed: 2021-09-27 13:24:22 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1944766    
Bug Blocks: 1996699    

Description t_j80 2021-01-12 18:35:12 UTC
Description of problem:

A crafted query can trigger a segfault and a server restart, the issue can be exploited to launch a DoS attack.

Version-Release number of selected component (if applicable):

mysql-8.0.21-1.module+el8.2.0+7855+47abd494.x86_64

How reproducible:

It can be reproduced even on a default mysql installation. The query is executed by a popular wordpress plugin (wp slim stats).

Steps to Reproduce:

1) Install mysql

yum -y install @mysql

2) Create a test database and a table

CREATE DATABASE test;

USE test;

CREATE TABLE `test11` (
  `id` int unsigned NOT NULL AUTO_INCREMENT,
  `ip` varchar(39) DEFAULT NULL,
  `other_ip` varchar(39) DEFAULT NULL,
  `username` varchar(256) DEFAULT NULL,
  `email` varchar(256) DEFAULT NULL,
  `country` varchar(16) DEFAULT NULL,
  `location` varchar(36) DEFAULT NULL,
  `city` varchar(256) DEFAULT NULL,
  `referer` varchar(2048) DEFAULT NULL,
  `resource` varchar(2048) DEFAULT NULL,
  `searchterms` varchar(2048) DEFAULT NULL,
  `notes` varchar(2048) DEFAULT NULL,
  `visit_id` int unsigned NOT NULL DEFAULT '0',
  `server_latency` int unsigned DEFAULT '0',
  `page_performance` int unsigned DEFAULT '0',
  `browser` varchar(40) DEFAULT NULL,
  `browser_version` varchar(15) DEFAULT NULL,
  `browser_type` tinyint unsigned DEFAULT '0',
  `platform` varchar(15) DEFAULT NULL,
  `language` varchar(5) DEFAULT NULL,
  `fingerprint` varchar(256) DEFAULT NULL,
  `user_agent` varchar(2048) DEFAULT NULL,
  `resolution` varchar(12) DEFAULT NULL,
  `screen_width` smallint unsigned DEFAULT '0',
  `screen_height` smallint unsigned DEFAULT '0',
  `content_type` varchar(64) DEFAULT NULL,
  `category` varchar(256) DEFAULT NULL,
  `author` varchar(64) DEFAULT NULL,
  `content_id` bigint unsigned DEFAULT '0',
  `outbound_resource` varchar(2048) DEFAULT NULL,
  `tz_offset` smallint DEFAULT '0',
  `dt_out` int unsigned DEFAULT '0',
  `dt` int unsigned DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `wp_slim_stats_dt_idx` (`dt`),
  KEY `wp_stats_resource_idx` (`resource`(20)),
  KEY `wp_stats_browser_idx` (`browser`(10)),
  KEY `wp_stats_searchterms_idx` (`searchterms`(15)),
  KEY `wp_stats_fingerprint_idx` (`fingerprint`(20))
) ENGINE=Innodb;

3) Insert a row

INSERT INTO `test11` VALUES (1,'x',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'1',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1609737845);

4) Execute the following query

SELECT MIN(dt) AS dt, COUNT( ip ) AS v1, COUNT( DISTINCT ip ) AS v2
FROM test11
WHERE 1=1 AND (dt BETWEEN 1605484800 AND 1607903999 OR dt BETWEEN 1607904000 AND 1610279762)
GROUP BY MONTH(CONVERT_TZ(FROM_UNIXTIME(dt), @@session.time_zone, '+00:00')), DAY(CONVERT_TZ(FROM_UNIXTIME(dt), @@session.time_zone, '+00:00'))

Actual results:

ERROR 2013 (HY000): Lost connection to MySQL server during query

Error log:

16:35:36 UTC - mysqld got signal 11 ;
Most likely, you have hit a bug, but this error can also be caused by malfunctioning hardware.
Thread pointer: 0x7fcce8006740
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 7fcd047f7d90 thread_stack 0x46000
/usr/libexec/mysqld(my_print_stacktrace(unsigned char const*, unsigned long)+0x41) [0x55729610cdf1]
/usr/libexec/mysqld(handle_fatal_signal+0x32b) [0x557295189cdb]
/lib64/libpthread.so.0(+0x12b20) [0x7fcd1d839b20]
/usr/libexec/mysqld(Sys_var_tz::session_value_ptr(THD*, THD*, MYSQL_LEX_STRING*)+0x21) [0x55729512e701]
/usr/libexec/mysqld(Item_func_get_system_var::val_str(String*)+0x433) [0x5572953573d3]
/usr/libexec/mysqld(Item::val_str_ascii(String*)+0x31) [0x5572952cbe31]
/usr/libexec/mysqld(Item_func_convert_tz::get_date(MYSQL_TIME*, unsigned int)+0x89) [0x5572953c3399]
/usr/libexec/mysqld(Item_func_month::val_int()+0x3b) [0x5572953bf67b]
/usr/libexec/mysqld(Sort_param::make_sortkey(Bounds_checked_array<unsigned char>, unsigned char const*, unsigned long*)+0x6f8) [0x557295286db8]
/usr/libexec/mysqld(+0x1202777) [0x557295287777]
/usr/libexec/mysqld(filesort(THD*, Filesort*, RowIterator*, Filesort_info*, Sort_result*, unsigned long long*)+0xdf8) [0x557295288618]
/usr/libexec/mysqld(SortingIterator::DoSort()+0x87) [0x557294fb3337]
/usr/libexec/mysqld(SortingIterator::Init()+0x1b) [0x557294fb33cb]
/usr/libexec/mysqld(AggregateIterator::Init()+0x2b) [0x55729524e92b]
/usr/libexec/mysqld(SELECT_LEX_UNIT::ExecuteIteratorQuery(THD*)+0x362) [0x5572951159a2]
/usr/libexec/mysqld(SELECT_LEX_UNIT::execute(THD*)+0x30) [0x557295115c10]
/usr/libexec/mysqld(Sql_cmd_dml::execute_inner(THD*)+0x3bb) [0x5572950a527b]
/usr/libexec/mysqld(Sql_cmd_dml::execute(THD*)+0x5f9) [0x5572950aec99]
/usr/libexec/mysqld(mysql_execute_command(THD*, bool)+0x20bd) [0x5572950513dd]
/usr/libexec/mysqld(mysql_parse(THD*, Parser_state*)+0x384) [0x557295054cc4]
/usr/libexec/mysqld(dispatch_command(THD*, COM_DATA const*, enum_server_command)+0x162b) [0x55729505677b]
/usr/libexec/mysqld(do_command(THD*)+0x1a4) [0x557295057d84]
/usr/libexec/mysqld(+0x10f5ff0) [0x55729517aff0]
/usr/libexec/mysqld(+0x25d6cb8) [0x55729665bcb8]
/lib64/libpthread.so.0(+0x814a) [0x7fcd1d82f14a]
/lib64/libc.so.6(clone+0x43) [0x7fcd1ad6cf23]

Trying to get some variables.
Some pointers may be invalid and cause the dump to abort.
Query (7fcce8116688): is an invalid pointer
Connection ID (thread ID): 8
Status: NOT_KILLED

The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
2021-01-12T16:35:37.289590Z 0 [System] [MY-010116] [Server] /usr/libexec/mysqld (mysqld 8.0.21) starting as process 15295

Expected results:

+------------+----+----+
| dt         | v1 | v2 |
+------------+----+----+
| 1609737845 |  1 |  1 |
+------------+----+----+
1 row in set (0.00 sec)

Additional info:

The issue can be reproduced also in 8.0.21 community version for rhel 8: https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.21-1.el8.x86_64.rpm-bundle.tar

While it CANNOT be reproduced in 8.0.22 community version for rhel 8, looks like it has been fixed.

Since the severity of the issue an upgrade of the shipped mysql server version from 8.0.21 to 8.0.22 should be provided as soon as possible.

Thanks

Comment 1 Michal Schorm 2021-01-14 17:18:22 UTC
Hello,
Thank you for the report.

I can confirm the issue exists. I minimised your reproducer to the following form:

-----

DROP DATABASE IF EXISTS test; CREATE DATABASE test; USE test;

CREATE TABLE `test` (
  `ip` varchar(10) DEFAULT NULL,
  `dt` int DEFAULT '0' KEY
) ENGINE=Innodb;

INSERT INTO `test` VALUES (NULL,0);

SELECT MIN(dt) AS dt, COUNT( DISTINCT ip ) AS v2
FROM test
GROUP BY MONTH(CONVERT_TZ(FROM_UNIXTIME(dt), @@session.time_zone, '+00:00'));

-----

It appears, the issue is with using "COUNT( DISTINCT )" as well as "CONVERT_TZ". If either is removed / changed; the command will pass.

I can also confirm that the 8.0.22 release of community MySQL solves the issue for both above reproducers.
I went through the MySQL 8.0.22 release notes in hope to spot a fixed issue which would correspond with this reproducer, but nothing there caught my eye.
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-22.html

Comment 2 Michal Schorm 2021-01-15 11:53:35 UTC
I agree this issue deserves fixing.
The MySQL components in Red Hat products are *usually* updated about once a year or more often because of medium and high priority CVEs discovered by upstream in their product.
However the planning and decision making are not purely engineering driven, so I can't promise any dates nor confirm any plans.

Thank you for taking the time to report this issue to us.
You can watch Oracle quarterly announcements, which can provide some idea about the current priority of the update:
    https://www.oracle.com/security-alerts/

That being said, this bug tracking system is not a mechanism for requesting support, and we are not able to guarantee the timeliness or suitability of a resolution.
 
If this issue is critical or in any way time sensitive, please raise a ticket through the regular Red Hat support channels to ensure it receives the proper attention and prioritization to assure a timely resolution.
 
For information on how to contact the Red Hat production support team, please visit:
    https://access.redhat.com/support

Comment 9 Lukas Javorsky 2021-08-23 13:19:01 UTC
Pushed in the rpms (stream-8.0-rhel-8.5.0 branch), modules (8.0-rhel-8.5.0 branch)