Commit f6f29764 authored by Dan Carpenter's avatar Dan Carpenter Committed by Ben Hutchings

xfrm: Oops on error in pfkey_msg2xfrm_state()

commit 1e3d0c2c upstream.

There are some missing error codes here so we accidentally return NULL
instead of an error pointer.  It results in a NULL pointer dereference.

Fixes: df71837d ("[LSM-IPSec]: Security association restriction.")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 96769d9b
...@@ -1163,8 +1163,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1163,8 +1163,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
if (key) if (key)
keysize = (key->sadb_key_bits + 7) / 8; keysize = (key->sadb_key_bits + 7) / 8;
x->aalg = kmalloc(sizeof(*x->aalg) + keysize, GFP_KERNEL); x->aalg = kmalloc(sizeof(*x->aalg) + keysize, GFP_KERNEL);
if (!x->aalg) if (!x->aalg) {
err = -ENOMEM;
goto out; goto out;
}
strcpy(x->aalg->alg_name, a->name); strcpy(x->aalg->alg_name, a->name);
x->aalg->alg_key_len = 0; x->aalg->alg_key_len = 0;
if (key) { if (key) {
...@@ -1183,8 +1185,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1183,8 +1185,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
goto out; goto out;
} }
x->calg = kmalloc(sizeof(*x->calg), GFP_KERNEL); x->calg = kmalloc(sizeof(*x->calg), GFP_KERNEL);
if (!x->calg) if (!x->calg) {
err = -ENOMEM;
goto out; goto out;
}
strcpy(x->calg->alg_name, a->name); strcpy(x->calg->alg_name, a->name);
x->props.calgo = sa->sadb_sa_encrypt; x->props.calgo = sa->sadb_sa_encrypt;
} else { } else {
...@@ -1198,8 +1202,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1198,8 +1202,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
if (key) if (key)
keysize = (key->sadb_key_bits + 7) / 8; keysize = (key->sadb_key_bits + 7) / 8;
x->ealg = kmalloc(sizeof(*x->ealg) + keysize, GFP_KERNEL); x->ealg = kmalloc(sizeof(*x->ealg) + keysize, GFP_KERNEL);
if (!x->ealg) if (!x->ealg) {
err = -ENOMEM;
goto out; goto out;
}
strcpy(x->ealg->alg_name, a->name); strcpy(x->ealg->alg_name, a->name);
x->ealg->alg_key_len = 0; x->ealg->alg_key_len = 0;
if (key) { if (key) {
...@@ -1247,8 +1253,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net, ...@@ -1247,8 +1253,10 @@ static struct xfrm_state * pfkey_msg2xfrm_state(struct net *net,
struct xfrm_encap_tmpl *natt; struct xfrm_encap_tmpl *natt;
x->encap = kmalloc(sizeof(*x->encap), GFP_KERNEL); x->encap = kmalloc(sizeof(*x->encap), GFP_KERNEL);
if (!x->encap) if (!x->encap) {
err = -ENOMEM;
goto out; goto out;
}
natt = x->encap; natt = x->encap;
n_type = ext_hdrs[SADB_X_EXT_NAT_T_TYPE-1]; n_type = ext_hdrs[SADB_X_EXT_NAT_T_TYPE-1];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment