Skip to content

Commit 73e1ffd

Browse files
committed
Bug#27919254 MYSQL USER ESCALATES ITS PRIVILEGE BY PLACING ARBITRARY PIDS INTO ITS PID FILES
1 parent 98f15da commit 73e1ffd

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

support-files/mysql.server.sh

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ esac
128128

129129
parse_server_arguments() {
130130
for arg do
131+
val=`echo "$arg" | sed -e 's/^[^=]*=//'`
131132
case "$arg" in
132-
--basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`
133+
--basedir=*) basedir="$val"
133134
bindir="$basedir/bin"
134135
if test -z "$datadir_set"; then
135136
datadir="$basedir/data"
@@ -143,14 +144,15 @@ parse_server_arguments() {
143144
fi
144145
libexecdir="$basedir/libexec"
145146
;;
146-
--datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`
147+
--datadir=*) datadir="$val"
147148
datadir_set=1
148149
;;
149150
--log-basename=*|--hostname=*|--loose-log-basename=*)
150-
mysqld_pid_file_path=`echo "$arg.pid" | sed -e 's/^[^=]*=//'`
151+
mysqld_pid_file_path="$val.pid"
151152
;;
152-
--pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
153-
--service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
153+
--pid-file=*) mysqld_pid_file_path="$val" ;;
154+
--service-startup-timeout=*) service_startup_timeout="$val" ;;
155+
--user=*) user="$val"; ;;
154156
esac
155157
done
156158
}
@@ -182,6 +184,12 @@ else
182184
test -z "$print_defaults" && print_defaults="my_print_defaults"
183185
fi
184186

187+
user='@MYSQLD_USER@'
188+
189+
su_kill() {
190+
su - $user -s /bin/sh -c "kill $*" >/dev/null 2>&1
191+
}
192+
185193
#
186194
# Read defaults file from 'basedir'. If there is no defaults file there
187195
# check if it's in the old (depricated) place (datadir) and read it from there
@@ -210,7 +218,7 @@ wait_for_gone () {
210218

211219
while test $i -ne $service_startup_timeout ; do
212220

213-
if kill -0 "$pid" 2>/dev/null; then
221+
if su_kill -0 "$pid" ; then
214222
: # the server still runs
215223
else
216224
if test ! -s "$pid_file_path"; then
@@ -250,7 +258,7 @@ wait_for_ready () {
250258
if $bindir/mysqladmin ping >/dev/null 2>&1; then
251259
log_success_msg
252260
return 0
253-
elif kill -0 $! 2>/dev/null ; then
261+
elif kill -0 $! ; then
254262
: # mysqld_safe is still running
255263
else
256264
# mysqld_safe is no longer running, abort the wait loop
@@ -319,10 +327,9 @@ case "$mode" in
319327
then
320328
mysqld_pid=`cat "$mysqld_pid_file_path"`
321329

322-
if (kill -0 $mysqld_pid 2>/dev/null)
323-
then
330+
if su_kill -0 $mysqld_pid ; then
324331
echo $echo_n "Shutting down MariaDB"
325-
kill $mysqld_pid
332+
su_kill $mysqld_pid
326333
# mysqld should remove the pid file when it exits, so wait for it.
327334
wait_for_gone $mysqld_pid "$mysqld_pid_file_path"; return_value=$?
328335
else
@@ -355,7 +362,7 @@ case "$mode" in
355362
'reload'|'force-reload')
356363
if test -s "$mysqld_pid_file_path" ; then
357364
read mysqld_pid < "$mysqld_pid_file_path"
358-
kill -HUP $mysqld_pid && log_success_msg "Reloading service MariaDB"
365+
su_kill -HUP $mysqld_pid && log_success_msg "Reloading service MariaDB"
359366
touch "$mysqld_pid_file_path"
360367
else
361368
log_failure_msg "MariaDB PID file could not be found!"
@@ -366,7 +373,7 @@ case "$mode" in
366373
# First, check to see if pid file exists
367374
if test -s "$mysqld_pid_file_path" ; then
368375
read mysqld_pid < "$mysqld_pid_file_path"
369-
if kill -0 $mysqld_pid 2>/dev/null ; then
376+
if su_kill -0 $mysqld_pid ; then
370377
log_success_msg "MariaDB running ($mysqld_pid)"
371378
exit 0
372379
else

0 commit comments

Comments
 (0)