diff mbox

xfrm: NULL dereference on allocation failure

Message ID 20170614103537.GJ29394@elgon.mountain
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show

Commit Message

Dan Carpenter June 14, 2017, 10:35 a.m. UTC
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 <dan.carpenter@oracle.com>

Comments

Steffen Klassert June 15, 2017, 11:57 a.m. UTC | #1
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 <dan.carpenter@oracle.com>

Also applied, thanks a lot Dan!
diff mbox

Patch

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;