netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* pull request (net): ipsec 2019-11-13
@ 2019-11-13 11:26 Steffen Klassert
  2019-11-13 11:26 ` [PATCH 1/2] xfrm: Fix memleak on xfrm state destroy Steffen Klassert
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Steffen Klassert @ 2019-11-13 11:26 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

1) Fix a page memleak on xfrm state destroy.

2) Fix a refcount imbalance if a xfrm_state
   gets invaild during async resumption.
   From Xiaodong Xu.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 99a8efbb6e30b72ac98cecf81103f847abffb1e5:

  NFC: st21nfca: fix double free (2019-11-06 21:48:29 -0800)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master

for you to fetch changes up to 4944a4b1077f74d89073624bd286219d2fcbfce3:

  xfrm: release device reference for invalid state (2019-11-12 08:24:38 +0100)

----------------------------------------------------------------
Steffen Klassert (1):
      xfrm: Fix memleak on xfrm state destroy

Xiaodong Xu (1):
      xfrm: release device reference for invalid state

 net/xfrm/xfrm_input.c | 3 +++
 net/xfrm/xfrm_state.c | 2 ++
 2 files changed, 5 insertions(+)

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

* [PATCH 1/2] xfrm: Fix memleak on xfrm state destroy
  2019-11-13 11:26 pull request (net): ipsec 2019-11-13 Steffen Klassert
@ 2019-11-13 11:26 ` Steffen Klassert
  2019-11-13 11:26 ` [PATCH 2/2] xfrm: release device reference for invalid state Steffen Klassert
  2019-11-13 19:26 ` pull request (net): ipsec 2019-11-13 David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2019-11-13 11:26 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

We leak the page that we use to create skb page fragments
when destroying the xfrm_state. Fix this by dropping a
page reference if a page was assigned to the xfrm_state.

Fixes: cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible")
Reported-by: JD <jdtxs00@gmail.com>
Reported-by: Paul Wouters <paul@nohats.ca>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_state.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index c6f3c4a1bd99..f3423562d933 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -495,6 +495,8 @@ static void ___xfrm_state_destroy(struct xfrm_state *x)
 		x->type->destructor(x);
 		xfrm_put_type(x->type);
 	}
+	if (x->xfrag.page)
+		put_page(x->xfrag.page);
 	xfrm_dev_state_free(x);
 	security_xfrm_state_free(x);
 	xfrm_state_free(x);
-- 
2.17.1


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

* [PATCH 2/2] xfrm: release device reference for invalid state
  2019-11-13 11:26 pull request (net): ipsec 2019-11-13 Steffen Klassert
  2019-11-13 11:26 ` [PATCH 1/2] xfrm: Fix memleak on xfrm state destroy Steffen Klassert
@ 2019-11-13 11:26 ` Steffen Klassert
  2019-11-13 19:26 ` pull request (net): ipsec 2019-11-13 David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2019-11-13 11:26 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Xiaodong Xu <stid.smth@gmail.com>

An ESP packet could be decrypted in async mode if the input handler for
this packet returns -EINPROGRESS in xfrm_input(). At this moment the device
reference in skb is held. Later xfrm_input() will be invoked again to
resume the processing.
If the transform state is still valid it would continue to release the
device reference and there won't be a problem; however if the transform
state is not valid when async resumption happens, the packet will be
dropped while the device reference is still being held.
When the device is deleted for some reason and the reference to this
device is not properly released, the kernel will keep logging like:

unregister_netdevice: waiting for ppp2 to become free. Usage count = 1

The issue is observed when running IPsec traffic over a PPPoE device based
on a bridge interface. By terminating the PPPoE connection on the server
end for multiple times, the PPPoE device on the client side will eventually
get stuck on the above warning message.

This patch will check the async mode first and continue to release device
reference in async resumption, before it is dropped due to invalid state.

v2: Do not assign address family from outer_mode in the transform if the
state is invalid

v3: Release device reference in the error path instead of jumping to resume

Fixes: 4ce3dbe397d7b ("xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0)")
Signed-off-by: Xiaodong Xu <stid.smth@gmail.com>
Reported-by: Bo Chen <chenborfc@163.com>
Tested-by: Bo Chen <chenborfc@163.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_input.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 9b599ed66d97..2c86a2fc3915 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -480,6 +480,9 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 			else
 				XFRM_INC_STATS(net,
 					       LINUX_MIB_XFRMINSTATEINVALID);
+
+			if (encap_type == -1)
+				dev_put(skb->dev);
 			goto drop;
 		}
 
-- 
2.17.1


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

* Re: pull request (net): ipsec 2019-11-13
  2019-11-13 11:26 pull request (net): ipsec 2019-11-13 Steffen Klassert
  2019-11-13 11:26 ` [PATCH 1/2] xfrm: Fix memleak on xfrm state destroy Steffen Klassert
  2019-11-13 11:26 ` [PATCH 2/2] xfrm: release device reference for invalid state Steffen Klassert
@ 2019-11-13 19:26 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-11-13 19:26 UTC (permalink / raw)
  To: steffen.klassert; +Cc: herbert, netdev

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Wed, 13 Nov 2019 12:26:11 +0100

> 1) Fix a page memleak on xfrm state destroy.
> 
> 2) Fix a refcount imbalance if a xfrm_state
>    gets invaild during async resumption.
>    From Xiaodong Xu.
> 
> Please pull or let me know if there are problems.

Pulled, thanks Steffen.

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

end of thread, other threads:[~2019-11-13 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 11:26 pull request (net): ipsec 2019-11-13 Steffen Klassert
2019-11-13 11:26 ` [PATCH 1/2] xfrm: Fix memleak on xfrm state destroy Steffen Klassert
2019-11-13 11:26 ` [PATCH 2/2] xfrm: release device reference for invalid state Steffen Klassert
2019-11-13 19:26 ` pull request (net): ipsec 2019-11-13 David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).