[CONC-525] Incorrect handling of the statement LOAD DATA LOCAL INFILE by implementation of libmariadb Created: 2021-02-08 Updated: 2021-02-23 Resolved: 2021-02-23 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | Security |
| Affects Version/s: | None |
| Fix Version/s: | 3.2.0 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Dmitry Shulga | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
The following test case reproduces the bug:
If this test case is run by mtr with the --ps-protocol option it fails
The above listed error message is produced by libmariadb, specifically by the function mysql_handle_local_infile() that is called by mthd_my_read_query_result. Calling trace to invocation point is below:
At the place of calling the function my_set_error(conn, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, "Load data local infile forbidden") in the function mysql_handle_local_infile(), the data member conn->options.client_flag == CLIENT_LOCAL_FILES and the parameter can_local_file has the value false. One level higher in the call stack the data member mysql->extension->auto_local_infile
has the value false, as a consequences the argument value for the parameter can_local_file of the function mysql_handle_local_infile() also has the value false. In case the original test case is run by mtr WITHOUT the option --ps-protocol, the parameter can_local_file of the function mysql_handle_local_infile() has the value true since the data member mysql->extension->auto_local_infile has the value ACCEPT_FILE_REQUEST. The value ACCEPT_FILE_REQUEST is assigned to the the data member mysql->extension->auto_local_infile inside the function ma_simple_command:
If the following modification be applied to the source code of the library libmariadb
then the original failure of the test main.ps_load when it is run with the option --ps-protocol be fixed. So, the major question is what was the reason to write so non-obvious and pretty hacked implementation for handling of statement LOAD DATA LOCAL INFILE on client side? |
| Comments |
| Comment by Sergei Golubchik [ 2021-02-12 ] | ||||||||||||||||
|
You can see the commit 02e7d5654dd83600f3c1e27b7c61ab1f4ea59138. LOAD DATA LOCAL is inherently insecure, the server can request the client to send any local (to the client) file and the client will oblige. Disabling this feature by default would break existing user applications that rely on it. Keeping it enabled — expose users that do not use it (the majority) to possible exploitation. This heuristics is a compromise solution. It temporarily allows one "file request" packet after the client sends an 'L' statement. All users who don't use LOAD DATA will thus become not vulnerable. Users who use LOAD DATA get the window of exploitation significantly reduced. This heuristics is not perfect. For example, it will not recognize statements like
In all cases when it does not work, the user should enable LOAD DATA LOCAL explicitly, just as she would have to do if we'd disabled LOAD DATA LOCAL by default. | ||||||||||||||||
| Comment by Dmitry Shulga [ 2021-02-16 ] | ||||||||||||||||
|
Ok, I see the motivation for this approach. Could I then consider the change originally listed in this bug report
as an acceptable way to fix the bug? | ||||||||||||||||
| Comment by Georg Richter [ 2021-02-16 ] | ||||||||||||||||
|
This issue is linked to CONC-515: Implement safe load data local infile, which I plan to push this week (3.2-georg branch). If you want to test | ||||||||||||||||
| Comment by Sergei Golubchik [ 2021-02-17 ] | ||||||||||||||||
|
shulga, would that work? A file request is sent on execute, not on prepare. And on execute you no longer have the statement text. | ||||||||||||||||
| Comment by Georg Richter [ 2021-02-17 ] | ||||||||||||||||
|
| ||||||||||||||||
| Comment by Georg Richter [ 2021-02-23 ] | ||||||||||||||||
|
Fixed in rev. ca1ea5c1a285b6982edeb19e59c814a4ff4da11b |