Subject: [PATCH net] ipv6: Do cleanup if attribute validation fails in multipath route

From: David Ahern <[email-masked]>
Date: Mon, 3 Jan 2022 10:05:55 -0700

As Nicolas noted, if gateway validation fails walking the multipath
attribute the code should jump to the cleanup to free previously
allocated memory.

Fixes: 23fb261977fd ("ipv6: Check attribute length for RTA_GATEWAY in multipath route")
Signed-off-by: David Ahern <[email-masked]>
Cc: Nicolas Dichtel <[email-masked]>
---
 net/ipv6/route.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index d2ff8a7e1709..3f36f9603f00 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5277,12 +5277,10 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
 
 			nla = nla_find(attrs, attrlen, RTA_GATEWAY);
 			if (nla) {
-				int ret;
-
-				ret = fib6_gw_from_attr(&r_cfg.fc_gateway, nla,
+				err = fib6_gw_from_attr(&r_cfg.fc_gateway, nla,
 							extack);
-				if (ret)
-					return ret;
+				if (err)
+					goto cleanup;
 
 				r_cfg.fc_flags |= RTF_GATEWAY;
 			}
-- 
2.24.3 (Apple Git-128)