lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221108124344.192326-1-liuhangbin@gmail.com>
Date:   Tue,  8 Nov 2022 20:43:44 +0800
From:   Hangbin Liu <liuhangbin@...il.com>
To:     netdev@...r.kernel.org
Cc:     Ido Schimmel <idosch@...sch.org>,
        Guillaume Nault <gnault@...hat.com>,
        David Ahern <dsahern@...nel.org>,
        Stephen Hemminger <stephen@...workplumber.org>,
        Hangbin Liu <liuhangbin@...il.com>
Subject: [PATCH iproute2] ip: fix return value for rtnl_talk failures

Since my last commit "rtnetlink: add new function rtnl_echo_talk()" we
return the kernel rtnl exit code directly, which breaks some kernel
selftest checking. As there are still a lot of tests checking -2 as the
error return value, to keep backward compatibility, let's keep using
-2 for all the rtnl return values.

Reported-by: Ido Schimmel <idosch@...sch.org>
Fixes: 6c09257f1bf6 ("rtnetlink: add new function rtnl_echo_talk()")
Signed-off-by: Hangbin Liu <liuhangbin@...il.com>
---
 ip/ipaddress.c | 10 ++++++++--
 ip/iplink.c    |  2 +-
 ip/ipnexthop.c | 10 ++++++++--
 ip/iproute.c   | 10 ++++++++--
 ip/iprule.c    | 10 ++++++++--
 5 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 456545bb..5e833482 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -2422,6 +2422,7 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
 	__u32 preferred_lft = INFINITY_LIFE_TIME;
 	__u32 valid_lft = INFINITY_LIFE_TIME;
 	unsigned int ifa_flags = 0;
+	int ret;
 
 	while (argc > 0) {
 		if (strcmp(*argv, "peer") == 0 ||
@@ -2604,9 +2605,14 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
 	}
 
 	if (echo_request)
-		return rtnl_echo_talk(&rth, &req.n, json, print_addrinfo);
+		ret = rtnl_echo_talk(&rth, &req.n, json, print_addrinfo);
+	else
+		ret = rtnl_talk(&rth, &req.n, NULL);
 
-	return rtnl_talk(&rth, &req.n, NULL);
+	if (ret)
+		return -2;
+
+	return 0;
 }
 
 int do_ipaddr(int argc, char **argv)
diff --git a/ip/iplink.c b/ip/iplink.c
index 92ce6c47..301a535e 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -1129,7 +1129,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 		ret = rtnl_talk(&rth, &req.n, NULL);
 
 	if (ret)
-		return ret;
+		return -2;
 
 	/* remove device from cache; next use can refresh with new data */
 	ll_drop_by_index(req.i.ifi_index);
diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index c87e847f..9f16b809 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -920,6 +920,7 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
 		.nhm.nh_family = preferred_family,
 	};
 	__u32 nh_flags = 0;
+	int ret;
 
 	while (argc > 0) {
 		if (!strcmp(*argv, "id")) {
@@ -1000,9 +1001,14 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
 	req.nhm.nh_flags = nh_flags;
 
 	if (echo_request)
-		return rtnl_echo_talk(&rth, &req.n, json, print_nexthop_nocache);
+		ret = rtnl_echo_talk(&rth, &req.n, json, print_nexthop_nocache);
+	else
+		ret = rtnl_talk(&rth, &req.n, NULL);
+
+	if (ret)
+		return -2;
 
-	return rtnl_talk(&rth, &req.n, NULL);
+	return 0;
 }
 
 static int ipnh_get_id(__u32 id)
diff --git a/ip/iproute.c b/ip/iproute.c
index b4b9d1b2..f34289e8 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -1134,6 +1134,7 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 	int raw = 0;
 	int type_ok = 0;
 	__u32 nhid = 0;
+	int ret;
 
 	if (cmd != RTM_DELROUTE) {
 		req.r.rtm_protocol = RTPROT_BOOT;
@@ -1588,9 +1589,14 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv)
 		req.r.rtm_type = RTN_UNICAST;
 
 	if (echo_request)
-		return rtnl_echo_talk(&rth, &req.n, json, print_route);
+		ret = rtnl_echo_talk(&rth, &req.n, json, print_route);
+	else
+		ret = rtnl_talk(&rth, &req.n, NULL);
+
+	if (ret)
+		return -2;
 
-	return rtnl_talk(&rth, &req.n, NULL);
+	return 0;
 }
 
 static int iproute_flush_cache(void)
diff --git a/ip/iprule.c b/ip/iprule.c
index 8f750425..8e5a2287 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -787,6 +787,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
 		.frh.family = preferred_family,
 		.frh.action = FR_ACT_UNSPEC,
 	};
+	int ret;
 
 	if (cmd == RTM_NEWRULE) {
 		if (argc == 0) {
@@ -1017,9 +1018,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
 		req.frh.table = RT_TABLE_MAIN;
 
 	if (echo_request)
-		return rtnl_echo_talk(&rth, &req.n, json, print_rule);
+		ret = rtnl_echo_talk(&rth, &req.n, json, print_rule);
+	else
+		ret = rtnl_talk(&rth, &req.n, NULL);
+
+	if (ret)
+		return -2;
 
-	return rtnl_talk(&rth, &req.n, NULL);
+	return 0;
 }
 
 int do_iprule(int argc, char **argv)
-- 
2.38.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ