[PATCH] xfrm: NULL dereference on allocation failure

Subsystems: networking [general], networking [ipsec], the rest

STALE3413d

2 messages, 2 authors, 2017-06-15 · open the first message on its own page

[PATCH] xfrm: NULL dereference on allocation failure

From: Dan Carpenter <hidden>
Date: 2017-06-14 10:35:59

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.")
Signed-off-by: Dan Carpenter <redacted>
diff --git a/net/key/af_key.c b/net/key/af_key.c
index 86051b5879f2..02e6865421e8 100644
--- a/net/key/af_key.c
+++ b/net/key/af_key.c
@@ -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;

Re: [PATCH] xfrm: NULL dereference on allocation failure

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: 2017-06-15 11:57:43

On Wed, Jun 14, 2017 at 01:35:37PM +0300, Dan Carpenter wrote:
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.")
Signed-off-by: Dan Carpenter <redacted>
Also applied, thanks a lot Dan!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help