xfrm: do not call rcu_read_unlock when afinfo is NULL in xfrm_get_tos
authorXin Long <lucien.xin@gmail.com>
Sat, 17 Feb 2018 07:16:22 +0000 (15:16 +0800)
committerSteffen Klassert <steffen.klassert@secunet.com>
Mon, 19 Feb 2018 07:45:25 +0000 (08:45 +0100)
When xfrm_policy_get_afinfo returns NULL, it will not hold rcu
read lock. In this case, rcu_read_unlock should not be called
in xfrm_get_tos, just like other places where it's calling
xfrm_policy_get_afinfo.

Fixes: f5e2bb4f5b22 ("xfrm: policy: xfrm_get_tos cannot fail")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
net/xfrm/xfrm_policy.c

index 8b3811ff002d77f99613f7f81f05f86875e4447b..150d46633ce6f2b7b75bc44253e4b53338c52686 100644 (file)
@@ -1458,10 +1458,13 @@ xfrm_tmpl_resolve(struct xfrm_policy **pols, int npols, const struct flowi *fl,
 static int xfrm_get_tos(const struct flowi *fl, int family)
 {
        const struct xfrm_policy_afinfo *afinfo;
-       int tos = 0;
+       int tos;
 
        afinfo = xfrm_policy_get_afinfo(family);
-       tos = afinfo ? afinfo->get_tos(fl) : 0;
+       if (!afinfo)
+               return 0;
+
+       tos = afinfo->get_tos(fl);
 
        rcu_read_unlock();