Skip to content

Commit cc01572

Browse files
Yossi Kupermanklassert
authored andcommitted
xfrm: Add SA to hardware at the end of xfrm_state_construct()
Current code configures the hardware with a new SA before the state has been fully initialized. During this time interval, an incoming ESP packet can cause a crash due to a NULL dereference. More specifically, xfrm_input() considers the packet as valid, and yet, anti-replay mechanism is not initialized. Move hardware configuration to the end of xfrm_state_construct(), and mark the state as valid once the SA is fully initialized. Fixes: d77e38e ("xfrm: Add an IPsec hardware offloading API") Signed-off-by: Aviad Yehezkel <[email protected]> Signed-off-by: Aviv Heller <[email protected]> Signed-off-by: Yossi Kuperman <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent ad9294d commit cc01572

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

net/xfrm/xfrm_state.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,6 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay, bool offload)
22722272
goto error;
22732273
}
22742274

2275-
x->km.state = XFRM_STATE_VALID;
2276-
22772275
error:
22782276
return err;
22792277
}
@@ -2282,7 +2280,13 @@ EXPORT_SYMBOL(__xfrm_init_state);
22822280

22832281
int xfrm_init_state(struct xfrm_state *x)
22842282
{
2285-
return __xfrm_init_state(x, true, false);
2283+
int err;
2284+
2285+
err = __xfrm_init_state(x, true, false);
2286+
if (!err)
2287+
x->km.state = XFRM_STATE_VALID;
2288+
2289+
return err;
22862290
}
22872291

22882292
EXPORT_SYMBOL(xfrm_init_state);

net/xfrm/xfrm_user.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,6 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
598598
goto error;
599599
}
600600

601-
if (attrs[XFRMA_OFFLOAD_DEV]) {
602-
err = xfrm_dev_state_add(net, x,
603-
nla_data(attrs[XFRMA_OFFLOAD_DEV]));
604-
if (err)
605-
goto error;
606-
}
607-
608601
if ((err = xfrm_alloc_replay_state_esn(&x->replay_esn, &x->preplay_esn,
609602
attrs[XFRMA_REPLAY_ESN_VAL])))
610603
goto error;
@@ -620,6 +613,14 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
620613
/* override default values from above */
621614
xfrm_update_ae_params(x, attrs, 0);
622615

616+
/* configure the hardware if offload is requested */
617+
if (attrs[XFRMA_OFFLOAD_DEV]) {
618+
err = xfrm_dev_state_add(net, x,
619+
nla_data(attrs[XFRMA_OFFLOAD_DEV]));
620+
if (err)
621+
goto error;
622+
}
623+
623624
return x;
624625

625626
error:
@@ -662,6 +663,9 @@ static int xfrm_add_sa(struct sk_buff *skb, struct nlmsghdr *nlh,
662663
goto out;
663664
}
664665

666+
if (x->km.state == XFRM_STATE_VOID)
667+
x->km.state = XFRM_STATE_VALID;
668+
665669
c.seq = nlh->nlmsg_seq;
666670
c.portid = nlh->nlmsg_pid;
667671
c.event = nlh->nlmsg_type;

0 commit comments

Comments
 (0)