]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
inet: ping: Fix icmp out counting
authoryuan.gao <yuan.gao@ucloud.cn>
Wed, 24 Dec 2025 06:31:45 +0000 (14:31 +0800)
committerJakub Kicinski <kuba@kernel.org>
Sun, 4 Jan 2026 17:48:53 +0000 (09:48 -0800)
When the ping program uses an IPPROTO_ICMP socket to send ICMP_ECHO
messages, ICMP_MIB_OUTMSGS is counted twice.

    ping_v4_sendmsg
      ping_v4_push_pending_frames
        ip_push_pending_frames
          ip_finish_skb
            __ip_make_skb
              icmp_out_count(net, icmp_type); // first count
      icmp_out_count(sock_net(sk), user_icmph.type); // second count

However, when the ping program uses an IPPROTO_RAW socket,
ICMP_MIB_OUTMSGS is counted correctly only once.

Therefore, the first count should be removed.

Fixes: c319b4d76b9e ("net: ipv4: add IPPROTO_ICMP socket kind")
Signed-off-by: yuan.gao <yuan.gao@ucloud.cn>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Link: https://patch.msgid.link/20251224063145.3615282-1-yuan.gao@ucloud.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/ping.c

index ad56588107cc8fb15fa1ff3d56046239a88781e3..cfbd563498e85e42e50ba2043a60ec5d1ea8a69a 100644 (file)
@@ -828,10 +828,8 @@ out:
 out_free:
        if (free)
                kfree(ipc.opt);
-       if (!err) {
-               icmp_out_count(sock_net(sk), user_icmph.type);
+       if (!err)
                return len;
-       }
        return err;
 
 do_confirm: