xfrm: fix refcount leak in xfrm_migrate_policy_find
Subsystems (3)
PATCH 1/1 xfrm: fix refcount leak in xfrm_migrate_policy_find
syzkaller reported a memory leak in xfrm_policy_alloc:
BUG: memory leak
unreferenced object 0xffff888114d79000 (size 1024):
comm "syz.1.17", pid 931
...
xfrm_policy_alloc+0xb3/0x4b0 net/xfrm/xfrm_policy.c:432The root cause is a double call to xfrm_pol_hold_rcu() in xfrm_migrate_policy_find(). The lookup function already returns a policy with held reference, making the second call redundant.
Remove the redundant xfrm_pol_hold_rcu() call to fix the refcount imbalance and prevent the memory leak.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- net/xfrm/xfrm_policy.c | 3 --- 1 file changed, 3 deletions(-)
net/xfrm/xfrm_policy.c +0 -3
@@ -4517,9 +4517,6 @@ static struct xfrm_policy *xfrm_migrate_policy_find(const struct xfrm_selector * pol =xfrm_policy_lookup_bytype (net, type, &fl, sel->family, dir, if_id);if (IS_ERR_OR_NULL (pol)) goto out_unlock; - -if (!xfrm_pol_hold_rcu (pol)) - pol =NULL ; out_unlock:rcu_read_unlock ();return pol;
Signature · 1 line
2.53.0
Quoted 8 lines · Kotlyarov Mihail
syzkaller reported a memory leak in
xfrm_policy_alloc:BUG: memory leak unreferenced object 0xffff888114d79000 (size 1024): comm "syz.1.17", pid 931 ... xfrm_policy_alloc+0xb3/0x4b0 net/xfrm/xfrm_policy.c:432
Quoted 5 lines
The root cause is a double call to
xfrm_pol_hold_rcu()inxfrm_migrate_policy_find(). The lookup function already returns a policy with held reference, making the second call redundant. Remove the redundantxfrm_pol_hold_rcu()call to fix the refcount imbalance and prevent the memory leak.
Quoted 12 lines · Kotlyarov Mihail
syzkaller reported a memory leak in
xfrm_policy_alloc:BUG: memory leak unreferenced object 0xffff888114d79000 (size 1024): comm "syz.1.17", pid 931 ... xfrm_policy_alloc+0xb3/0x4b0 net/xfrm/xfrm_policy.c:432The root cause is a double call to
xfrm_pol_hold_rcu()inxfrm_migrate_policy_find(). The lookup function already returns a policy with held reference, making the second call redundant.
Quoted 7 lines
Remove the redundant
xfrm_pol_hold_rcu()call to fix the refcount imbalance and prevent the memory leak.Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes 563d5ca93e88 ("xfrm: switch migrate to xfrm_policy_lookup_bytype")Signed-off-by Kotlyarov Mihail <[email protected]>
Applied, thanks a lot!