Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
start-scripts: switch to $PGUSER before opening $PGLOG.
authorNoah Misch <noah@leadboat.com>
Mon, 6 Nov 2017 15:11:10 +0000 (07:11 -0800)
committerNoah Misch <noah@leadboat.com>
Mon, 6 Nov 2017 15:11:13 +0000 (07:11 -0800)
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

contrib/start-scripts/freebsd
contrib/start-scripts/linux
contrib/start-scripts/osx/PostgreSQL

index c6ac8cd47a70d70b593e803fa142b0e302f7ab73..3323237a54b4fca1dcd54b43657ad19f4589b287 100644 (file)
@@ -43,7 +43,7 @@ test -x $DAEMON ||
 
 case $1 in
     start)
-   su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+   su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
    echo -n ' postgresql'
    ;;
     stop)
@@ -51,7 +51,7 @@ case $1 in
    ;;
     restart)
    su -l $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
-   su -l $PGUSER -c "$DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+   su -l $PGUSER -c "$DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
    ;;
     status)
    su -l $PGUSER -c "$PGCTL status -D '$PGDATA'"
index 44a775b03005151531df7860bf0d53d1f9c89a46..a7757162fc4b6978fd887ca058eed51b8470755f 100644 (file)
@@ -91,7 +91,7 @@ case $1 in
   start)
    echo -n "Starting PostgreSQL: "
    test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
-   su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+   su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
    echo "ok"
    ;;
   stop)
@@ -103,7 +103,7 @@ case $1 in
    echo -n "Restarting PostgreSQL: "
    su - $PGUSER -c "$PGCTL stop -D '$PGDATA' -s"
    test -e "$PG_OOM_ADJUST_FILE" && echo "$PG_MASTER_OOM_SCORE_ADJ" > "$PG_OOM_ADJUST_FILE"
-   su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' &" >>$PGLOG 2>&1
+   su - $PGUSER -c "$DAEMON_ENV $DAEMON -D '$PGDATA' >>$PGLOG 2>&1 &"
    echo "ok"
    ;;
   reload)
index 7ff1d0e377fe4b76376439a352996b30efdd8afd..7ac12bb9e33b4443ce4d5cb9837265e66a90dbd6 100755 (executable)
@@ -80,9 +80,9 @@ StartService () {
     if [ "${POSTGRESQL:=-NO-}" = "-YES-" ]; then
         ConsoleMessage "Starting PostgreSQL database server"
         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
-            sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1
+            sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' >>\"$PGLOG\" 2>&1 &"
         fi
     fi
 }
@@ -99,9 +99,9 @@ RestartService () {
         sudo -u $PGUSER sh -c "$PGCTL stop -D '${PGDATA}' -s"
         # should match StartService:
         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
-            sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' &" >>"$PGLOG" 2>&1
+            sudo -u $PGUSER sh -c "${DAEMON} -D '${PGDATA}' >>\"$PGLOG\" 2>&1 &"
         fi
     else
         StopService