1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-21 12:05:57 +03:00

start-scripts: switch to $PGUSER before opening $PGLOG.

By default, $PGUSER has permission to unlink $PGLOG.  If $PGUSER
replaces $PGLOG with a symbolic link, the server will corrupt the
link-targeted file by appending log messages.  Since these scripts open
$PGLOG as root, the attack works regardless of target file ownership.

"make install" does not install these scripts anywhere.  Users having
manually installed them in the past should repeat that process to
acquire this fix.  Most script users have $PGLOG writable to root only,
located in $PGDATA.  Just before updating one of these scripts, such
users should rename $PGLOG to $PGLOG.old.  The script will then recreate
$PGLOG with proper ownership.

Reviewed by Peter Eisentraut.  Reported by Antoine Scemama.

Security: CVE-2017-12172
This commit is contained in:
Noah Misch 2017-11-06 07:11:10 -08:00
parent d4fcc0ceaa
commit 29d0670519
3 changed files with 8 additions and 8 deletions

View File

@ -44,7 +44,7 @@ test -x $DAEMON ||
case $1 in case $1 in
start) start)
su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1 su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo -n ' postgresql' echo -n ' postgresql'
;; ;;
stop) stop)
@ -52,7 +52,7 @@ case $1 in
;; ;;
restart) restart)
su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w" su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1 su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
;; ;;
status) status)
su -l $PGUSER -c "$PGCTL status -D '$PGDATA'" su -l $PGUSER -c "$PGCTL status -D '$PGDATA'"

View File

@ -84,7 +84,7 @@ case $1 in
echo -n "Starting PostgreSQL: " echo -n "Starting PostgreSQL: "
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1 su - $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo "ok" echo "ok"
;; ;;
stop) stop)
@ -97,7 +97,7 @@ case $1 in
su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w" su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s -m fast -w"
test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj test x"$OOM_SCORE_ADJ" != x && echo "$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj test x"$OOM_ADJ" != x && echo "$OOM_ADJ" > /proc/self/oom_adj
su - $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1 su - $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
echo "ok" echo "ok"
;; ;;
reload) reload)

View File

@ -81,9 +81,9 @@ StartService () {
if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting PostgreSQL database server" ConsoleMessage "Starting PostgreSQL database server"
if [ "${ROTATELOGS}" = "1" ]; then if [ "${ROTATELOGS}" = "1" ]; then
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} "${PGLOG}" ${ROTATESEC} & sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 | ${LOGUTIL} \"${PGLOG}\" ${ROTATESEC} &"
else else
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' >>\"$PGLOG\" 2>&1 &"
fi fi
fi fi
} }
@ -100,9 +100,9 @@ RestartService () {
sudo -u $PGUSER sh -c "$PGCTL stop -D '${PGDATA}' -s -m fast" sudo -u $PGUSER sh -c "$PGCTL stop -D '${PGDATA}' -s -m fast"
# should match StartService: # should match StartService:
if [ "${ROTATELOGS}" = "1" ]; then if [ "${ROTATELOGS}" = "1" ]; then
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" 2>&1 | ${LOGUTIL} "${PGLOG}" ${ROTATESEC} & sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' 2>&1 | ${LOGUTIL} \"${PGLOG}\" ${ROTATESEC} &"
else else
sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1 sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' >>\"$PGLOG\" 2>&1 &"
fi fi
else else
StopService StopService