mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xfrm: fix refcount leak in __xfrm_policy_check()
@ 2022-07-24  9:55 Xin Xiong
  2022-07-29 13:08 ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Xiong @ 2022-07-24  9:55 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, “David S . Miller ,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, James Morris, netdev,
	linux-kernel
  Cc: yuanxzhang, Xin Xiong, Xin Tan

The issue happens on an error path in __xfrm_policy_check(). When the
fetching process of the object `pols[1]` fails, the function simply
returns 0, forgetting to decrement the reference count of `pols[0]`,
which is incremented earlier by either xfrm_sk_policy_lookup() or
xfrm_policy_lookup(). This may result in memory leaks.

Fix it by decreasing the reference count of `pols[0]` in that path.

Fixes: 134b0fc544ba ("IPsec: propagate security module errors up from flow_cache_lookup")
Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>
---
 net/xfrm/xfrm_policy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index f1a0bab920a5..4f8bbb825abc 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -3599,6 +3599,7 @@ int __xfrm_policy_check(struct sock *sk, int dir, struct sk_buff *skb,
 		if (pols[1]) {
 			if (IS_ERR(pols[1])) {
 				XFRM_INC_STATS(net, LINUX_MIB_XFRMINPOLERROR);
+				xfrm_pol_put(pols[0]);
 				return 0;
 			}
 			pols[1]->curlft.use_time = ktime_get_real_seconds();
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfrm: fix refcount leak in __xfrm_policy_check()
  2022-07-24  9:55 [PATCH] xfrm: fix refcount leak in __xfrm_policy_check() Xin Xiong
@ 2022-07-29 13:08 ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2022-07-29 13:08 UTC (permalink / raw)
  To: Xin Xiong
  Cc: Herbert Xu, “David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, James Morris, netdev, linux-kernel,
	yuanxzhang, Xin Tan

On Sun, Jul 24, 2022 at 05:55:58PM +0800, Xin Xiong wrote:
> The issue happens on an error path in __xfrm_policy_check(). When the
> fetching process of the object `pols[1]` fails, the function simply
> returns 0, forgetting to decrement the reference count of `pols[0]`,
> which is incremented earlier by either xfrm_sk_policy_lookup() or
> xfrm_policy_lookup(). This may result in memory leaks.
> 
> Fix it by decreasing the reference count of `pols[0]` in that path.
> 
> Fixes: 134b0fc544ba ("IPsec: propagate security module errors up from flow_cache_lookup")
> Signed-off-by: Xin Xiong <xiongx18@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.com>

Applied, thanks a lot Xin!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-29 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-24  9:55 [PATCH] xfrm: fix refcount leak in __xfrm_policy_check() Xin Xiong
2022-07-29 13:08 ` Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®