Commit 1ab168b9 authored by Guilhem Moulin's avatar Guilhem Moulin
Browse files

initramfs init-bottom script: Wait for drobear to start before bringing the network down.

Closes: #943459
parent 0fd7a862
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ dropbear (2019.78-3) UNRELEASED; urgency=medium
    (Closes: #934146)
  * debian/initramfs/dropbear-hook: Don't mention cryptroot in warning
    messages, only SSH login.
  * debian/initramfs/bottom-dropbear: Wait for drobear to start before
    bringing the network down. This avoids a race where the network stack were
    fully not configured yet by the time the execution is handed over to the
    main system. (Closes: #943459)

 -- Guilhem Moulin <guilhem@debian.org>  Wed, 07 Aug 2019 16:14:58 +0200

+21 −2
Original line number Diff line number Diff line
@@ -15,12 +15,31 @@ esac

. /scripts/functions
EXE="$(readlink -f /sbin/dropbear)" && [ -f "$EXE" ] || exit 1
PIDFILE="/run/dropbear.pid"

# delete authorized_keys(5) file to forbid new SSH sessions
rm -f ~root/.ssh/authorized_keys

if PID="$(cat /run/dropbear.pid)" 2>/dev/null &&
        [ "$(readlink -f "/proc/$PID/exe")" = "$EXE" ]; then
wait_for_dropbear() {
    local pid exe timer=60
    pid="$(cat "$PIDFILE" 2>/dev/null)" || return 1

    # when configure_networking() is run asynchronously dropbear might
    # not have started yet; ipconfig doesn't react to SIGTERM so we wait
    # for the network stack to be configured (and dropbear to start)
    # rather than terminating the shell and its children
    while [ $timer -gt 0 ] && exe="$(readlink -f "/proc/$pid/exe" 2>/dev/null)"; do
        if [ "$exe" = "$EXE" ]; then
            echo "$pid"
            return 0
        fi
        sleep 1
        timer=$(( timer - 1))
    done
    return 1
}

if PID="$(wait_for_dropbear)"; then
    log_begin_msg "Stopping dropbear"

    # Kill all process groups the leader of which is a child of the