Skip to contentSkip to conversation

xfrm: fix a race in xfrm_state_lookup_byspi

PATCH Applied [email protected] 3 participants 3 messages Apr 29, 2015 – Apr 30, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfrm: fix a race in xfrm_state_lookup_byspi

From: Li RongQing <[email protected]>

The returned xfrm_state should be hold before unlock xfrm_state_lock, otherwise the returned xfrm_state maybe be released.

Fixes c454997e6[{pktgen, xfrm} Introduce xfrm_state_lookup_byspi..]
Cc Fan Du <[email protected]>
---
 net/xfrm/xfrm_state.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
index f5e39e3..96688cd 100644
@@ -927,8 +927,8 @@ struct xfrm_state *xfrm_state_lookup_byspi(struct net *net, __be32 spi,
 			x->id.spi != spi)
 			continue;
 
-		spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 		xfrm_state_hold(x);
+		spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 		return x;
 	}
 	spin_unlock_bh(&net->xfrm.xfrm_state_lock);
Signature · 1 line
2.1.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, April 29, 2015 8:43 AM
To: [email protected]
Cc: Du, Fan; [email protected]
Subject: [PATCH] xfrm: fix a race in xfrm_state_lookup_byspi

Quoted 8 lines

From: Li RongQing <[email protected]>

The returned xfrm_state should be hold before unlock xfrm_state_lock, otherwise the returned xfrm_state maybe be released.

Fixes c454997e6[{pktgen, xfrm} Introduce xfrm_state_lookup_byspi..]
Cc Fan Du <[email protected]>
Quoted 21 lines

---
net/xfrm/xfrm_state.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_state.c +1 -1
index f5e39e3..96688cd 100644
@@ -927,8 +927,8 @@ struct xfrm_state *xfrm_state_lookup_byspi(struct net
 *net, __be32 spi,
 			x->id.spi != spi)
 			continue;
 
-		spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 		xfrm_state_hold(x);
+		spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 		return x;
 	}
	spin_unlock_bh(&net->xfrm.xfrm_state_lock);

--
2.1.0

maintainer Applied
#2 lore raw
Quoted 10 lines · Fan
Quoted 10 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Wednesday, April 29, 2015 8:43 AM
To: [email protected]
Cc: Du, Fan; [email protected]
Subject: [PATCH] xfrm: fix a race in xfrm_state_lookup_byspi

From: Li RongQing <[email protected]>

Quoted 8 lines
Quoted 6 lines

The returned xfrm_state should be hold before unlock xfrm_state_lock, otherwise the returned xfrm_state maybe be released.

Fixes c454997e6[{pktgen, xfrm} Introduce xfrm_state_lookup_byspi..]
Cc Fan Du <[email protected]>

Applied to the ipsec tree, thanks a lot!