summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sql_common.h1
-rw-r--r--mysql-test/include/mtr_warnings.sql8
-rw-r--r--sql-common/my_path_permissions.cc54
-rw-r--r--sql/CMakeLists.txt2
-rw-r--r--sql/mysqld.cc36
5 files changed, 98 insertions, 3 deletions
diff --git a/include/sql_common.h b/include/sql_common.h
index 05bbb5a4f53..45e90d438fb 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -107,6 +107,7 @@ void mysql_client_plugin_deinit();
struct st_mysql_client_plugin;
extern struct st_mysql_client_plugin *mysql_client_builtins[];
extern my_bool libmysql_cleartext_plugin_enabled;
+int is_file_or_dir_world_writable(const char *filepath);
#ifdef __cplusplus
}
diff --git a/mysql-test/include/mtr_warnings.sql b/mysql-test/include/mtr_warnings.sql
index 0a3c3bc60b3..fb6d24c03e9 100644
--- a/mysql-test/include/mtr_warnings.sql
+++ b/mysql-test/include/mtr_warnings.sql
@@ -1,4 +1,4 @@
--- Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+-- Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
@@ -209,6 +209,12 @@ INSERT INTO global_suppressions VALUES
*/
("Insecure configuration for --secure-file-priv:*"),
+ /*
+ Bug#26585560, warning related to --pid-file
+ */
+ ("Insecure configuration for --pid-file:*"),
+ ("Few location(s) are inaccessible while checking PID filepath"),
+
("THE_LAST_SUPPRESSION")||
diff --git a/sql-common/my_path_permissions.cc b/sql-common/my_path_permissions.cc
new file mode 100644
index 00000000000..22cd748ff03
--- /dev/null
+++ b/sql-common/my_path_permissions.cc
@@ -0,0 +1,54 @@
+/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA */
+
+#include "my_dir.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ Check if a file/dir is world-writable (only on non-Windows platforms)
+
+ @param [in] Path of the file/dir to be checked
+
+ @returns Status of the file/dir check
+ @retval -2 Permission denied to check attributes of file/dir
+ @retval -1 Error in reading file/dir
+ @retval 0 File/dir is not world-writable
+ @retval 1 File/dir is world-writable
+ */
+
+int is_file_or_dir_world_writable(const char *path)
+{
+ MY_STAT stat_info;
+ (void)path; // avoid unused param warning when built on Windows
+#ifndef _WIN32
+ if (!my_stat(path, &stat_info, MYF(0)))
+ {
+ return (errno == EACCES) ? -2 : -1;
+ }
+ if ((stat_info.st_mode & S_IWOTH) &&
+ ((stat_info.st_mode & S_IFMT) == S_IFREG || /* file */
+ (stat_info.st_mode & S_IFMT) == S_IFDIR)) /* or dir */
+ return 1;
+#endif
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 531561ac36d..aa7e0312e05 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -78,7 +78,7 @@ SET (SQL_SOURCE
sql_profile.cc event_parse_data.cc sql_alter.cc
sql_signal.cc rpl_handler.cc mdl.cc sql_admin.cc
transaction.cc sys_vars.cc sql_truncate.cc datadict.cc
- sql_reload.cc
+ sql_reload.cc ../sql-common/my_path_permissions.cc
${GEN_SOURCES}
${CONF_SOURCES}
${MYSYS_LIBWRAP_SOURCE})
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index c969fd8a62a..fd39e252c26 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights
+/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights
reserved.
This program is free software; you can redistribute it and/or modify
@@ -7996,6 +7996,40 @@ static int test_if_case_insensitive(const char *dir_name)
static void create_pid_file()
{
File file;
+ bool check_parent_path= 1, is_path_accessible= 1;
+ char pid_filepath[FN_REFLEN], *pos= NULL;
+ /* Copy pid file name to get pid file path */
+ strcpy(pid_filepath, pidfile_name);
+
+ /* Iterate through the entire path to check if even one of the sub-dirs
+ is world-writable */
+ while (check_parent_path && (pos= strrchr(pid_filepath, FN_LIBCHAR))
+ && (pos != pid_filepath)) /* shouldn't check root */
+ {
+ *pos= '\0'; /* Trim the inner-most dir */
+ switch (is_file_or_dir_world_writable(pid_filepath))
+ {
+ case -2:
+ is_path_accessible= 0;
+ break;
+ case -1:
+ sql_perror("Can't start server: can't check PID filepath");
+ exit(1);
+ case 1:
+ sql_print_warning("Insecure configuration for --pid-file: Location "
+ "'%s' in the path is accessible to all OS users. "
+ "Consider choosing a different directory.",
+ pid_filepath);
+ check_parent_path= 0;
+ break;
+ case 0:
+ continue; /* Keep checking the parent dir */
+ }
+ }
+ if (!is_path_accessible)
+ {
+ sql_print_warning("Few location(s) are inaccessible while checking PID filepath.");
+ }
if ((file= mysql_file_create(key_file_pid, pidfile_name, 0664,
O_WRONLY | O_TRUNC, MYF(MY_WME))) >= 0)
{