Skip to contentSkip to conversation

xfrm_user: propagate sec ctx allocation errors

PATCH Applied Mathias Krause 2 participants 2 messages Sep 8, 2016 – Sep 9, 2016

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

PATCH 1/1 xfrm_user: propagate sec ctx allocation errors

When we fail to attach the security context in xfrm_state_construct() we'll return 0 as error value which, in turn, will wrongly claim success to userland when, in fact, we won't be adding / updating the XFRM state.

This is a regression introduced by commit fd21150a0fe1 ("[XFRM] netlink:
Inline attach_encap_tmpl(), attach_sec_ctx(), and attach_one_addr()").

Fix it by propagating the error returned by security_xfrm_state_alloc() in this case.

Fixes fd21150a0fe1 ("[XFRM] netlink: Inline attach_encap_tmpl()...")
Cc Thomas Graf <[email protected]>
---
 net/xfrm/xfrm_user.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
net/xfrm/xfrm_user.c +6 -3
index d516845e16e3..b08440a8f123 100644
@@ -581,9 +581,12 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
 	if (err)
 		goto error;
 
-	if (attrs[XFRMA_SEC_CTX] &&
-	    security_xfrm_state_alloc(x, nla_data(attrs[XFRMA_SEC_CTX])))
-		goto error;
+	if (attrs[XFRMA_SEC_CTX]) {
+		err = security_xfrm_state_alloc(x,
+						nla_data(attrs[XFRMA_SEC_CTX]));
+		if (err)
+			goto error;
+	}
 
 	if ((err = xfrm_alloc_replay_state_esn(&x->replay_esn, &x->preplay_esn,
 					       attrs[XFRMA_REPLAY_ESN_VAL])))
Signature · 1 line
1.7.10.4
maintainer Applied
#1 lore raw
Quoted 4 lines · Mathias Krause

When we fail to attach the security context in xfrm_state_construct() we'll return 0 as error value which, in turn, will wrongly claim success to userland when, in fact, we won't be adding / updating the XFRM state.

Quoted 8 lines

This is a regression introduced by commit fd21150a0fe1 ("[XFRM] netlink:
Inline attach_encap_tmpl(), attach_sec_ctx(), and attach_one_addr()").

Fix it by propagating the error returned by security_xfrm_state_alloc() in this case.

Fixes fd21150a0fe1 ("[XFRM] netlink: Inline attach_encap_tmpl()...")

Applied to the ipsec tree, thanks Mathias!