Skip to contentSkip to conversation

xfrm: NULL dereference on allocation failure

PATCH In review Dan Carpenter 2 participants 2 messages Jun 14, 2017 – Jun 15, 2017

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

PATCH 1/1 xfrm: NULL dereference on allocation failure

The default error code in pfkey_msg2xfrm_state() is -ENOBUFS. We added a new call to security_xfrm_state_alloc() which sets "err" to zero so there several places where we can return ERR_PTR(0) if kmalloc() fails. The caller is expecting error pointers so it leads to a NULL dereference.

Fixes df71837d5024 ("[LSM-IPSec]: Security association restriction.")
net/key/af_key.c +1 -0
index 86051b5879f2..02e6865421e8 100644
@@ -1157,6 +1157,7 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
 			goto out;
 	}
 
+	err = -ENOBUFS;
 	key = ext_hdrs[SADB_EXT_KEY_AUTH - 1];
 	if (sa->sadb_sa_auth) {
 		int keysize = 0;
maintainer
#1 lore raw
Quoted 8 lines · Dan Carpenter

The default error code in pfkey_msg2xfrm_state() is -ENOBUFS. We added a new call to security_xfrm_state_alloc() which sets "err" to zero so there several places where we can return ERR_PTR(0) if kmalloc() fails. The caller is expecting error pointers so it leads to a NULL dereference.

Fixes df71837d5024 ("[LSM-IPSec]: Security association restriction.")

Also applied, thanks a lot Dan!