xfrm: Assign esn pointers when cloning a state

When we clone a xfrm state we have to assign the replay_esn
and the preplay_esn pointers to the state if we use the
new replay detection method. To this end, we add a
xfrm_replay_clone() function that allocates memory for
the replay detection and takes over the necessary values
from the original state.

Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by Steffen Klassert and committed by David S. Miller af2f464e 36ae0148

+28
+22
include/net/xfrm.h
··· 1601 1601 } 1602 1602 1603 1603 #ifdef CONFIG_XFRM_MIGRATE 1604 + static inline int xfrm_replay_clone(struct xfrm_state *x, 1605 + struct xfrm_state *orig) 1606 + { 1607 + x->replay_esn = kzalloc(xfrm_replay_state_esn_len(orig->replay_esn), 1608 + GFP_KERNEL); 1609 + if (!x->replay_esn) 1610 + return -ENOMEM; 1611 + 1612 + x->replay_esn->bmp_len = orig->replay_esn->bmp_len; 1613 + x->replay_esn->replay_window = orig->replay_esn->replay_window; 1614 + 1615 + x->preplay_esn = kmemdup(x->replay_esn, 1616 + xfrm_replay_state_esn_len(x->replay_esn), 1617 + GFP_KERNEL); 1618 + if (!x->preplay_esn) { 1619 + kfree(x->replay_esn); 1620 + return -ENOMEM; 1621 + } 1622 + 1623 + return 0; 1624 + } 1625 + 1604 1626 static inline struct xfrm_algo *xfrm_algo_clone(struct xfrm_algo *orig) 1605 1627 { 1606 1628 return kmemdup(orig, xfrm_alg_len(orig), GFP_KERNEL);
+6
net/xfrm/xfrm_state.c
··· 1181 1181 goto error; 1182 1182 } 1183 1183 1184 + if (orig->replay_esn) { 1185 + err = xfrm_replay_clone(x, orig); 1186 + if (err) 1187 + goto error; 1188 + } 1189 + 1184 1190 memcpy(&x->mark, &orig->mark, sizeof(x->mark)); 1185 1191 1186 1192 err = xfrm_init_state(x);