Public bug reported:

[ Impact ]

When fping can't open a raw ICMP socket, it falls back to an unprivileged
ICMP datagram socket (SOCK_DGRAM, allowed by net.ipv4.ping_group_range). In
that mode fping 5.1 reports *every* target as unreachable, including
127.0.0.1 and ::1, even though the replies arrive.

Cause: on a SOCK_DGRAM ICMP socket the Linux kernel replaces the ICMP echo
identifier with the socket's local port. fping 5.1 builds its packets with
htons(getpid()) as the identifier and drops any reply whose identifier differs.
It reads the kernel-assigned identifier back (getsockname()) only when a source
address is given with -S, so without -S every reply is discarded. This was a
regression in 5.1 (upstream issue #248), fixed upstream in 5.2 by a two-line
change.

Who is affected: the packaged /usr/bin/fping gets cap_net_raw+ep in postinst,
so a plain host install uses raw sockets and doesn't hit this. It affects every
case where that file capability doesn't take effect, which is common in
containers:

 * containers run with no-new-privileges (e.g. Docker
   `security_opt: no-new-privileges`, Kubernetes
   `allowPrivilegeEscalation: false`) where fping is started by a process
   without CAP_NET_RAW in its permitted set;
 * rootless / user-namespaced runtimes, and filesystems that drop the
   security.capability xattr;
 * copies of the binary or non-packaged installs run as a normal user.

Real-world case: the official Zabbix server/proxy Docker images based on
Ubuntu (24.04 today; the 8.0 branch is moving to 26.04) take fping from the
archive. With no-new-privileges, every Zabbix ICMP check (icmpping) reports
100% loss for every host:
 * https://github.com/zabbix/zabbix-docker/issues/2008
 * https://github.com/zabbix/zabbix-docker/issues/1836
 * https://github.com/truenas/apps/issues/6742

Affected: jammy, noble, resolute, stonking (all 5.1). Fixed in tenacious
(5.5-2, synced from Debian).

[ Test Plan ]

On any Ubuntu system or container (amd64 or arm64). Unprivileged ICMP must be
allowed, which is the Ubuntu default via systemd's 50-default.conf:

  $ sysctl net.ipv4.ping_group_range
  net.ipv4.ping_group_range = 0 2147483647
  # if it shows "1      0" (e.g. in a minimal container):
  $ sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"

As a normal (non-root) user, run a copy of fping that doesn't carry the file
capability (this forces the SOCK_DGRAM path):

  $ cp /usr/bin/fping /tmp/fping-nocap
  $ /tmp/fping-nocap 127.0.0.1; echo "exit=$?"
  $ /tmp/fping-nocap -6 ::1; echo "exit=$?"
  $ /tmp/fping-nocap -c2 -t500 127.0.0.1 127.0.0.2; echo "exit=$?"

Expected with the current package:
  127.0.0.1 is unreachable   exit=1
  ::1 is unreachable         exit=1
  ... xmt/rcv/%loss = 2/0/100% ...   exit=1

Expected with the fixed package:
  127.0.0.1 is alive         exit=0
  ::1 is alive               exit=0
  ... xmt/rcv/%loss = 2/2/0% ...     exit=0

Container case (same root cause, as hit by Zabbix), as root in a container
started with --cap-add NET_RAW:

  # setpriv --reuid=65534 --regid=65534 --clear-groups --no-new-privs \
      sh -c 'exec /usr/bin/fping -C3 -i0' <<< 127.0.0.1
  current: "127.0.0.1 : - - -"     fixed: "127.0.0.1 : 0.06 0.13 0.14"

Regression checks (must behave identically before and after):

  $ /tmp/fping-nocap -S0.0.0.0 127.0.0.1        # alive (explicit source)
  $ sudo fping 127.0.0.1; sudo fping -6 ::1     # alive (raw socket path)
  $ /tmp/fping-nocap -t200 -r0 192.0.2.1        # "is unreachable", exit=1

I ran all of the above in ubuntu:24.04, ubuntu:26.04 and ubuntu:26.10
containers (arm64, Podman) with the attached debdiffs. The results matched the
expectations above on all three series. Logs available on request.

[ Where problems could occur ]

The change only alters behaviour when fping is using a SOCK_DGRAM socket, i.e.
when raw socket creation already failed. The raw-socket path (the normal
packaged case with cap_net_raw) is unchanged.

In SOCK_DGRAM mode, fping now always calls bind() (to INADDR_ANY /
in6addr_any, port 0, unless -S is given) and getsockname() on its ICMP sockets
before sending. If either call failed, fping would abort with "cannot bind
source address" or "can't get ICMP socket identity" instead of reporting
hosts unreachable. That is the most likely regression. A wildcard bind with
port 0 on a socket that was just created successfully isn't expected to fail,
and it is exactly what -S0.0.0.0 already does today (regression check above).
Today that mode already reports 100% loss for every target, so any SOCK_DGRAM
user is already broken.

The identical code has shipped upstream since fping 5.2 (April 2024) and is in
Debian sid/forky and Ubuntu tenacious (5.5).

[ Other Info ]

 * Upstream fix: 
https://github.com/schweikert/fping/commit/e975a4339b24716fb57bed234b0a1176f2bf3451
   The backport uses the v5.2 form of the IPv6 line (socktype6). The original
   commit compared socktype4 there, which upstream corrected before 5.2.
 * Upstream bug: https://github.com/schweikert/fping/issues/248
 * Versions (keeps the upgrade path noble < resolute < stonking < tenacious):
     noble     5.1-1        -> 5.1-1ubuntu0.24.04.1
     resolute  5.1-1build1  -> 5.1-1ubuntu0.26.04.1
     stonking  5.1-1build1  -> 5.1-1ubuntu0.26.10.1
   jammy (5.1-1) is affected too but not targeted. It can be added if wanted
   (5.1-1ubuntu0.22.04.1); the same patch applies.
 * Attached: one debdiff per series (patch + changelog + update-maintainer).

[ Environment ]

Reproduced on stock Ubuntu container images (arm64), no extra
repositories:

  $ lsb_release -rd                        $ apt-cache policy fping
  Description: Ubuntu 24.04.5 LTS            Installed: 5.1-1        
(noble/universe)
  Release:     24.04
  Description: Ubuntu 26.04.1 LTS            Installed: 5.1-1build1  
(resolute/universe)
  Release:     26.04
  Description: Ubuntu 26.10                  Installed: 5.1-1build1  
(stonking/universe)
  Release:     26.10

Each candidate is the only version available (release pocket only, no
-updates). Originally found on zabbix/zabbix-server-pgsql:8.0.0-ubuntu
(fping 5.1, noble base) on amd64.

What I expected: fping run from an unprivileged ICMP socket reports
reachable hosts as alive.
What happened instead: every host, including 127.0.0.1 and ::1, is reported
unreachable (100% loss), although the echo replies are delivered (confirmed
with tcpdump).

** Affects: fping (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: noble patch resolute stonking

** Description changed:

+ [ Impact ]
+ 
  When fping can't open a raw ICMP socket, it falls back to an unprivileged
  ICMP datagram socket (SOCK_DGRAM, allowed by net.ipv4.ping_group_range). In
  that mode fping 5.1 reports *every* target as unreachable, including
  127.0.0.1 and ::1, even though the replies arrive.
  
  Cause: on a SOCK_DGRAM ICMP socket the Linux kernel replaces the ICMP echo
  identifier with the socket's local port. fping 5.1 builds its packets with
  htons(getpid()) as the identifier and drops any reply whose identifier 
differs.
  It reads the kernel-assigned identifier back (getsockname()) only when a 
source
  address is given with -S, so without -S every reply is discarded. This was a
  regression in 5.1 (upstream issue #248), fixed upstream in 5.2 by a two-line
  change.
  
  Who is affected: the packaged /usr/bin/fping gets cap_net_raw+ep in postinst,
  so a plain host install uses raw sockets and doesn't hit this. It affects 
every
  case where that file capability doesn't take effect, which is common in
  containers:
  
   * containers run with no-new-privileges (e.g. Docker
     `security_opt: no-new-privileges`, Kubernetes
     `allowPrivilegeEscalation: false`) where fping is started by a process
     without CAP_NET_RAW in its permitted set;
   * rootless / user-namespaced runtimes, and filesystems that drop the
     security.capability xattr;
   * copies of the binary or non-packaged installs run as a normal user.
  
  Real-world case: the official Zabbix server/proxy Docker images based on
  Ubuntu (24.04 today; the 8.0 branch is moving to 26.04) take fping from the
  archive. With no-new-privileges, every Zabbix ICMP check (icmpping) reports
  100% loss for every host:
   * https://github.com/zabbix/zabbix-docker/issues/2008
   * https://github.com/zabbix/zabbix-docker/issues/1836
   * https://github.com/truenas/apps/issues/6742
  
  Affected: jammy, noble, resolute, stonking (all 5.1). Fixed in tenacious
  (5.5-2, synced from Debian).
  
  [ Test Plan ]
  
  On any Ubuntu system or container (amd64 or arm64). Unprivileged ICMP must be
  allowed, which is the Ubuntu default via systemd's 50-default.conf:
  
    $ sysctl net.ipv4.ping_group_range
    net.ipv4.ping_group_range = 0       2147483647
    # if it shows "1    0" (e.g. in a minimal container):
    $ sudo sysctl -w net.ipv4.ping_group_range="0 2147483647"
  
  As a normal (non-root) user, run a copy of fping that doesn't carry the file
  capability (this forces the SOCK_DGRAM path):
  
    $ cp /usr/bin/fping /tmp/fping-nocap
    $ /tmp/fping-nocap 127.0.0.1; echo "exit=$?"
    $ /tmp/fping-nocap -6 ::1; echo "exit=$?"
    $ /tmp/fping-nocap -c2 -t500 127.0.0.1 127.0.0.2; echo "exit=$?"
  
  Expected with the current package:
    127.0.0.1 is unreachable   exit=1
    ::1 is unreachable         exit=1
    ... xmt/rcv/%loss = 2/0/100% ...   exit=1
  
  Expected with the fixed package:
    127.0.0.1 is alive         exit=0
    ::1 is alive               exit=0
    ... xmt/rcv/%loss = 2/2/0% ...     exit=0
  
  Container case (same root cause, as hit by Zabbix), as root in a container
  started with --cap-add NET_RAW:
  
    # setpriv --reuid=65534 --regid=65534 --clear-groups --no-new-privs \
        sh -c 'exec /usr/bin/fping -C3 -i0' <<< 127.0.0.1
    current: "127.0.0.1 : - - -"     fixed: "127.0.0.1 : 0.06 0.13 0.14"
  
  Regression checks (must behave identically before and after):
  
    $ /tmp/fping-nocap -S0.0.0.0 127.0.0.1        # alive (explicit source)
    $ sudo fping 127.0.0.1; sudo fping -6 ::1     # alive (raw socket path)
    $ /tmp/fping-nocap -t200 -r0 192.0.2.1        # "is unreachable", exit=1
  
  I ran all of the above in ubuntu:24.04, ubuntu:26.04 and ubuntu:26.10
  containers (arm64, Podman) with the attached debdiffs. The results matched the
  expectations above on all three series. Logs available on request.
  
  [ Where problems could occur ]
  
  The change only alters behaviour when fping is using a SOCK_DGRAM socket, i.e.
  when raw socket creation already failed. The raw-socket path (the normal
  packaged case with cap_net_raw) is unchanged.
  
  In SOCK_DGRAM mode, fping now always calls bind() (to INADDR_ANY /
  in6addr_any, port 0, unless -S is given) and getsockname() on its ICMP sockets
  before sending. If either call failed, fping would abort with "cannot bind
  source address" or "can't get ICMP socket identity" instead of reporting
  hosts unreachable. That is the most likely regression. A wildcard bind with
  port 0 on a socket that was just created successfully isn't expected to fail,
  and it is exactly what -S0.0.0.0 already does today (regression check above).
  Today that mode already reports 100% loss for every target, so any SOCK_DGRAM
  user is already broken.
  
  The identical code has shipped upstream since fping 5.2 (April 2024) and is in
  Debian sid/forky and Ubuntu tenacious (5.5).
  
  [ Other Info ]
  
   * Upstream fix: 
https://github.com/schweikert/fping/commit/e975a4339b24716fb57bed234b0a1176f2bf3451
     The backport uses the v5.2 form of the IPv6 line (socktype6). The original
     commit compared socktype4 there, which upstream corrected before 5.2.
   * Upstream bug: https://github.com/schweikert/fping/issues/248
   * Versions (keeps the upgrade path noble < resolute < stonking < tenacious):
       noble     5.1-1        -> 5.1-1ubuntu0.24.04.1
       resolute  5.1-1build1  -> 5.1-1ubuntu0.26.04.1
       stonking  5.1-1build1  -> 5.1-1ubuntu0.26.10.1
     jammy (5.1-1) is affected too but not targeted. It can be added if wanted
     (5.1-1ubuntu0.22.04.1); the same patch applies.
   * Attached: one debdiff per series (patch + changelog + update-maintainer).
  
  [ Environment ]
  
  Reproduced on stock Ubuntu container images (arm64), no extra
  repositories:
  
    $ lsb_release -rd                        $ apt-cache policy fping
    Description: Ubuntu 24.04.5 LTS            Installed: 5.1-1        
(noble/universe)
    Release:     24.04
    Description: Ubuntu 26.04.1 LTS            Installed: 5.1-1build1  
(resolute/universe)
    Release:     26.04
    Description: Ubuntu 26.10                  Installed: 5.1-1build1  
(stonking/universe)
    Release:     26.10
  
  Each candidate is the only version available (release pocket only, no
  -updates). Originally found on zabbix/zabbix-server-pgsql:8.0.0-ubuntu
  (fping 5.1, noble base) on amd64.
  
  What I expected: fping run from an unprivileged ICMP socket reports
  reachable hosts as alive.
  What happened instead: every host, including 127.0.0.1 and ::1, is reported
  unreachable (100% loss), although the echo replies are delivered (confirmed
  with tcpdump).

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

Title:
  fping 5.1: unprivileged (SOCK_DGRAM) mode reports every target as
  unreachable

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/fping/+bug/2178378/+subscriptions


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

Reply via email to