Public bug reported:

[Impact]

After network-manager is upgraded (the postinst restarts
NetworkManager.service), an active `ipv4.method=shared` connection
stops working and NetworkManager retries it in a tight loop until the
old dnsmasq is killed by hand.

NetworkManager.service uses `KillMode=process`, so the shared dnsmasq
survives the restart:

    systemd[1]: NetworkManager.service: Unit process 2521 (dnsmasq)
remains running after unit stopped.

The new NetworkManager is meant to kill it via
`/run/nm-dnsmasq-<iface>.pid` (`kill_existing_by_pidfile()` in
src/core/dnsmasq/nm-dnsmasq-manager.c), but that function never kills
anything: the PID is parsed with `max=G_MAXUINT64` passed as a
`gint64`, i.e. -1, so every PID is rejected and only the pidfile is
deleted. The new dnsmasq then fails:

    dnsmasq: failed to create listening socket for 10.42.0.1: Address already 
in use
    dnsmasq-manager: dnsmasq exited with error: Network access problem (address 
in use, permissions) (2)
    device (enx0): state change: activated -> failed (reason 
'ip-config-unavailable', managed-type: 'full')
    device (enx0): Activation: failed for connection 'shared'

Because the device reaches `activated` before dnsmasq exits, the
autoconnect retry counter is reset every time, so the loop does not
stop despite the default limit of 4 retries (55785 failed activations
in about 6.5 hours here).

Seen with network-manager 1.54.3-2ubuntu3.2, triggered by the
unattended upgrade from 1.54.3-2ubuntu3.1. The bug exists upstream
since NM 1.2 and is unchanged on main.

[Test Plan]

Without restarting NetworkManager, using a decoy dnsmasq that owns the
pidfile:

    sudo ip link add nmtest0 type dummy && sudo ip link set nmtest0 up
    sudo /usr/sbin/dnsmasq --keep-in-foreground --conf-file=/dev/null 
--no-hosts \
        --bind-interfaces --listen-address=127.0.0.1 --port=5399 \
        --pid-file=/run/nm-dnsmasq-nmtest0.pid &
    sudo nmcli connection add type dummy ifname nmtest0 con-name nmtest \
        ipv4.method shared ipv4.addresses 10.42.99.1/24 ipv6.method disabled
    sudo nmcli connection up nmtest
    pgrep -f 'port=5399'

Without the fix the decoy is still running (confirmed on
1.54.3-2ubuntu3.2). With the fix it should be killed when the
connection is activated.

Real-world case: activate a shared connection on an ethernet device,
then `sudo systemctl restart NetworkManager`; without the fix the old
dnsmasq keeps running with PPID 1 and the connection fails with
"Address already in use".

[Where problems could occur]

The fix changes only the upper bound used to parse the PID in
`kill_existing_by_pidfile()` (G_MAXUINT64 -> G_MAXINT). NetworkManager
will then actually SIGKILL a process whose PID is in
/run/nm-dnsmasq-<iface>.pid and whose cmdline is dnsmasq, which is the
intended behaviour since 2014.

[Other Info]

Upstream issues:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/work_items/2080
(stale dnsmasq not killed) and
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/work_items/2081
(endless autoconnect retries).

Proposed one-line fix (merge request to follow):
https://gitlab.freedesktop.org/cryo/NetworkManager/-/commit/296875c02b95

Workaround: kill the stale dnsmasq and re-activate the connection:

    sudo pkill -f '^/usr/sbin/dnsmasq .*--pid-file=/run/nm-dnsmasq-'
    sudo nmcli connection up <name>

or add a systemd drop-in for NetworkManager.service with
`ExecStopPost=-/usr/bin/pkill -f "^/usr/sbin/dnsmasq 
.*--pid-file=/run/nm-dnsmasq-"`.

** Affects: network-manager (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2178314

Title:
  Shared connection (ipv4.method=shared) breaks after network-manager
  upgrade: stale dnsmasq not killed

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/2178314/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to