UPSTREAM: xfrm: Return detailed errors from xfrmi_newlink
authorBenedict Wong <benedictwong@google.com>
Wed, 25 Jul 2018 20:45:29 +0000 (13:45 -0700)
committerxiest1 <xiest1@lenovo.com>
Tue, 5 Nov 2019 09:32:14 +0000 (17:32 +0800)
Currently all failure modes of xfrm interface creation return EEXIST.
This change improves the granularity of errnos provided by also
returning ENODEV or EINVAL if failures happen in looking up the
underlying interface, or a required parameter is not provided.

This change has been tested against the Android Kernel Networking Tests,
with additional xfrmi_newlink tests here:

https://android-review.googlesource.com/c/kernel/tests/+/715755

Signed-off-by: Benedict Wong <benedictwong@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
(cherry picked from commit 44e2b838c24d883dae8496dc7b6ddac7956ba53c)
Bug: 113046120
Change-Id: Ic680bf1e4a828aaae01b289223d9396a551eefd2

net/xfrm/xfrm_interface.c

index 31acc6f33d98929ec2be31b0aec0469b4d5551fb..481d7307ab51884dcf6902b21fe4862adab9bd3b 100644 (file)
@@ -689,7 +689,10 @@ static int xfrmi_newlink(struct net *src_net, struct net_device *dev,
        nla_strlcpy(p->name, tb[IFLA_IFNAME], IFNAMSIZ);
 
        xi = xfrmi_locate(net, p, 1);
-       return PTR_ERR_OR_ZERO(xi);
+       if (IS_ERR(xi))
+               return PTR_ERR(xi);
+
+       return 0;
 }
 
 static void xfrmi_dellink(struct net_device *dev, struct list_head *head)