From 9a14df6b950c6ad1eaa7680385797505fb14d868 Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Thu, 29 Aug 2024 10:39:09 +0200 Subject: [PATCH] ping: Fix socket error reporting Resolves: RHEL-4608 --- 010-ping-Fix-socket-error-reporting.patch | 51 +++++++++++++++++++++++ iputils.spec | 8 ++-- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 010-ping-Fix-socket-error-reporting.patch diff --git a/010-ping-Fix-socket-error-reporting.patch b/010-ping-Fix-socket-error-reporting.patch new file mode 100644 index 0000000..a6f6d27 --- /dev/null +++ b/010-ping-Fix-socket-error-reporting.patch @@ -0,0 +1,51 @@ +From 42ff1833920e2524b07790243ef9146125f5b2c4 Mon Sep 17 00:00:00 2001 +From: Petr Vorel +Date: Wed, 10 Aug 2022 21:05:22 +0200 +Subject: [PATCH] ping: Fix socket error reporting + +There is actually no need for errno EAFNOSUPPORT special handling, +nor for any other errno. *All* errors needs to be reported on verbose +mode or when socket is required. If AF_INET6 socket is used with +disabled IPv6, error reporting is done by gai_strerror() (ipv6.disable=1) +or by connect() error handling in ping6_run() (EADDRNOTAVAIL on +net.ipv6.conf.all.disable_ipv6=1). + +Bug was hidden because condition "errno == EAFNOSUPPORT && socktype == +AF_INET6" introduced in d141cb6 was always false as AF_INET6 is is an address +family not a socket type, until otherwise correct fix 904cdb6. Attempt +to fix it in 79d713e introduced regression that other errors weren't +reported (e.g. EPERM on RAW socket on non-root, see #406). + +Closes: https://github.com/iputils/iputils/pull/418 +Fixes: https://github.com/iputils/iputils/issues/406 +Fixes: 79d713e ("ping: Remove 'unsupported IPv6' warning on disabled IPv6") +Fixes: d141cb6 ("ping: work with older kernels that don't support ping sockets") + +Reported-by: Benjamin Poirier +Tested-by: Benjamin Poirier +Signed-off-by: Petr Vorel +(cherry picked from commit bbe451f91ecc769ac5f70c1269372a6cc28d6814) +--- + ping/ping.c | 6 +----- + 1 file changed, 1 insertion(+), 5 deletions(-) + +diff --git a/ping/ping.c b/ping/ping.c +index 81ee7c8..ff7e742 100644 +--- a/ping/ping.c ++++ b/ping/ping.c +@@ -147,11 +147,7 @@ static void create_socket(struct ping_rts *rts, socket_st *sock, int family, + } + + if (sock->fd == -1) { +- /* Report error related to disabled IPv6 only when IPv6 also failed or in +- * verbose mode. Report other errors always. +- */ +- if ((errno == EAFNOSUPPORT && family == AF_INET6 && requisite) || +- rts->opt_verbose) ++ if (requisite || rts->opt_verbose) + error(0, errno, "socket"); + if (requisite) + exit(2); +-- +2.46.0 + diff --git a/iputils.spec b/iputils.spec index 38afed1..6cad551 100644 --- a/iputils.spec +++ b/iputils.spec @@ -25,9 +25,10 @@ Patch003: 003-arping-Fix-unsolicited-ARP-regressions-on-c-1.patch Patch004: 004-arping-fix-typo-in-error-checking.patch Patch005: 005-arping-exit-0-if-running-in-deadline-mode-and-we-see.patch Patch006: 006-Revert-Add-strict-pattern-matching-on-response-when-.patch -Patch010: 007-ping-Move-ping_rts-multicast.patch -Patch007: 008-ping-Print-reply-from-Subnet-Router-anycast-address.patch -Patch008: 009-ping-Print-reply-with-wrong-source-with-warning.patch +Patch007: 007-ping-Move-ping_rts-multicast.patch +Patch008: 008-ping-Print-reply-from-Subnet-Router-anycast-address.patch +Patch009: 009-ping-Print-reply-with-wrong-source-with-warning.patch +Patch010: 010-ping-Fix-socket-error-reporting.patch # Downstream-only patches Patch100: 100-iputils-ifenslave.patch @@ -142,6 +143,7 @@ install -cp ifenslave.8 ${RPM_BUILD_ROOT}%{_mandir}/man8/ - arping: Fix 1s delay on exit for unsolicited arpings (RHEL-34110) - arping: exit 0 if running in deadline mode and we see replies (RHEL-27718) - ping: Print reply with wrong source with warning & some follow-up fixes (RHEL-12789, RHEL-13480) +- ping: Fix socket error reporting (RHEL-4608) * Wed May 03 2023 Jan Macku - 20210202-9 - ping: Remove 'unsupported IPv6' warning on disabled IPv6 (rhbz#2152511)