Patch "xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()" has been added to the 5.18-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()

to the 5.18-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     xfrm-xfrm_policy-fix-a-possible-double-xfrm_pols_put.patch
and it can be found in the queue-5.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 2286e083e407b0e178f167ab95278662bc761d78
Author: Hangyu Hua <hbh25y@xxxxxxxxx>
Date:   Wed Jun 1 14:46:25 2022 +0800

    xfrm: xfrm_policy: fix a possible double xfrm_pols_put() in xfrm_bundle_lookup()
    
    [ Upstream commit f85daf0e725358be78dfd208dea5fd665d8cb901 ]
    
    xfrm_policy_lookup() will call xfrm_pol_hold_rcu() to get a refcount of
    pols[0]. This refcount can be dropped in xfrm_expand_policies() when
    xfrm_expand_policies() return error. pols[0]'s refcount is balanced in
    here. But xfrm_bundle_lookup() will also call xfrm_pols_put() with
    num_pols == 1 to drop this refcount when xfrm_expand_policies() return
    error.
    
    This patch also fix an illegal address access. pols[0] will save a error
    point when xfrm_policy_lookup fails. This lead to xfrm_pols_put to resolve
    an illegal address in xfrm_bundle_lookup's error path.
    
    Fix these by setting num_pols = 0 in xfrm_expand_policies()'s error path.
    
    Fixes: 80c802f3073e ("xfrm: cache bundles instead of policies for outgoing flows")
    Signed-off-by: Hangyu Hua <hbh25y@xxxxxxxxx>
    Signed-off-by: Steffen Klassert <steffen.klassert@xxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index f1876ea61fdc..f1a0bab920a5 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2678,8 +2678,10 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family,
 		*num_xfrms = 0;
 		return 0;
 	}
-	if (IS_ERR(pols[0]))
+	if (IS_ERR(pols[0])) {
+		*num_pols = 0;
 		return PTR_ERR(pols[0]);
+	}
 
 	*num_xfrms = pols[0]->xfrm_nr;
 
@@ -2694,6 +2696,7 @@ static int xfrm_expand_policies(const struct flowi *fl, u16 family,
 		if (pols[1]) {
 			if (IS_ERR(pols[1])) {
 				xfrm_pols_put(pols, *num_pols);
+				*num_pols = 0;
 				return PTR_ERR(pols[1]);
 			}
 			(*num_pols)++;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux