netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 1/3] xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0)
@ 2017-10-24 15:10 avivh
  2017-10-24 15:10 ` [PATCH net-next 2/3] xfrm: Fix offload dev state addition to occur after insertion avivh
  2017-10-24 15:10 ` [PATCH net-next 3/3] xfrm: Remove redundant state assignment in xfrm_input() avivh
  0 siblings, 2 replies; 9+ messages in thread
From: avivh @ 2017-10-24 15:10 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu
  Cc: Boris Pismenny, Yossi Kuperman, Yevgeny Kliteynik, netdev,
	Aviv Heller

From: Aviv Heller <avivh@mellanox.com>

Code path when (encap_type < 0) does not verify the state is valid
before progressing.

This will result in a crash if, for instance, x->km.state ==
XFRM_STATE_ACQ.

Fixes: 7785bba299a8 ("esp: Add a software GRO codepath")
Signed-off-by: Aviv Heller <avivh@mellanox.com>
Signed-off-by: Yevgeny Kliteynik <kliteyn@mellanox.com>
---
 net/xfrm/xfrm_input.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 2515cd2..ea9407f 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -206,7 +206,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 	xfrm_address_t *daddr;
 	struct xfrm_mode *inner_mode;
 	u32 mark = skb->mark;
-	unsigned int family;
+	unsigned int family = AF_UNSPEC;
 	int decaps = 0;
 	int async = 0;
 	bool xfrm_gro = false;
@@ -215,6 +215,16 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
 
 	if (encap_type < 0) {
 		x = xfrm_input_state(skb);
+
+		if (unlikely(x->km.state != XFRM_STATE_VALID)) {
+			if (x->km.state == XFRM_STATE_ACQ)
+				XFRM_INC_STATS(net, LINUX_MIB_XFRMACQUIREERROR);
+			else
+				XFRM_INC_STATS(net,
+					       LINUX_MIB_XFRMINSTATEINVALID);
+			goto drop;
+		}
+
 		family = x->outer_mode->afinfo->family;
 
 		/* An encap_type of -1 indicates async resumption. */
-- 
1.8.3.1

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

end of thread, other threads:[~2017-10-26 15:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-24 15:10 [PATCH net-next 1/3] xfrm: Fix xfrm_input() to verify state is valid when (encap_type < 0) avivh
2017-10-24 15:10 ` [PATCH net-next 2/3] xfrm: Fix offload dev state addition to occur after insertion avivh
2017-10-25  7:22   ` Steffen Klassert
2017-10-25 13:09     ` Aviv Heller
2017-10-26  6:16       ` Steffen Klassert
2017-10-26 14:55         ` Aviv Heller
     [not found]         ` <mail.59f1f759.3bc0.5118b0751bd8f084@storage.wm.amazon.com>
2017-10-26 15:47           ` Aviv Heller
2017-10-26  0:27   ` kbuild test robot
2017-10-24 15:10 ` [PATCH net-next 3/3] xfrm: Remove redundant state assignment in xfrm_input() avivh

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).