Skip to content

Commit 7aa05d3

Browse files
antonyantonyklassert
authored andcommitted
xfrm: clone XFRMA_SEC_CTX in xfrm_do_migrate
XFRMA_SEC_CTX was not cloned from the old to the new. Migrate this attribute during XFRMA_MSG_MIGRATE v1->v2: - return -ENOMEM on error v2->v3: - fix return type to int Fixes: 80c9aba ("[XFRM]: Extension for dynamic update of endpoint address(es)") Signed-off-by: Antony Antony <antony.antony@secunet.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent 91a46c6 commit 7aa05d3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

net/xfrm/xfrm_state.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,30 @@ int xfrm_state_add(struct xfrm_state *x)
14411441
EXPORT_SYMBOL(xfrm_state_add);
14421442

14431443
#ifdef CONFIG_XFRM_MIGRATE
1444+
static inline int clone_security(struct xfrm_state *x, struct xfrm_sec_ctx *security)
1445+
{
1446+
struct xfrm_user_sec_ctx *uctx;
1447+
int size = sizeof(*uctx) + security->ctx_len;
1448+
int err;
1449+
1450+
uctx = kmalloc(size, GFP_KERNEL);
1451+
if (!uctx)
1452+
return -ENOMEM;
1453+
1454+
uctx->exttype = XFRMA_SEC_CTX;
1455+
uctx->len = size;
1456+
uctx->ctx_doi = security->ctx_doi;
1457+
uctx->ctx_alg = security->ctx_alg;
1458+
uctx->ctx_len = security->ctx_len;
1459+
memcpy(uctx + 1, security->ctx_str, security->ctx_len);
1460+
err = security_xfrm_state_alloc(x, uctx);
1461+
kfree(uctx);
1462+
if (err)
1463+
return err;
1464+
1465+
return 0;
1466+
}
1467+
14441468
static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
14451469
struct xfrm_encap_tmpl *encap)
14461470
{
@@ -1497,6 +1521,10 @@ static struct xfrm_state *xfrm_state_clone(struct xfrm_state *orig,
14971521
goto error;
14981522
}
14991523

1524+
if (orig->security)
1525+
if (clone_security(x, orig->security))
1526+
goto error;
1527+
15001528
if (orig->coaddr) {
15011529
x->coaddr = kmemdup(orig->coaddr, sizeof(*x->coaddr),
15021530
GFP_KERNEL);

0 commit comments

Comments
 (0)