xfrm: iptfs: only publish mode_data after clone setup
Subsystems (4)
PATCH v3 1/1 xfrm: iptfs: only publish mode_data after clone setup
iptfs_clone_state() stores x->mode_data before allocating the reorder window. If that allocation fails, the code frees the cloned state and returns -ENOMEM, leaving x->mode_data pointing at freed memory.
The xfrm clone unwind later runs destroy_state() through x->mode_data, so the failed clone path tears down IPTFS state that clone_state() already freed.
Keep the cloned IPTFS state private until all allocations succeed so failed clones leave x->mode_data unset. The destroy path already handles a NULL mode_data pointer.
---
Changes in v3:
- Rebase on top of current ipsec tree
net/xfrm/xfrm_iptfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_iptfs.c +3 -3
@@ -2664,9 +2664,6 @@ static int iptfs_clone_state(struct xfrm_state *x, struct xfrm_state *orig)if (!xtfs)return -ENOMEM ; - x->mode_data = xtfs; - xtfs->x = x; - xtfs->ra_newskb =NULL ;if (xtfs->cfg.reorder_win_size) { xtfs->w_saved = kcalloc(xtfs->cfg.reorder_win_size,
@@ -2677,6 +2674,9 @@ static int iptfs_clone_state(struct xfrm_state *x, struct xfrm_state *orig) } } + x->mode_data = xtfs; + xtfs->x = x; +return 0 ; }
Signature · 1 line
2.53.GIT
Quoted 8 lines · Paul Moses
iptfs_clone_state()storesx->mode_databefore allocating the reorder window. If that allocation fails, the code frees the cloned state and returns-ENOMEM, leavingx->mode_datapointing at freed memory.The xfrm clone unwind later runs
destroy_state()throughx->mode_data, so the failed clone path tears down IPTFS state thatclone_state()already freed.
Quoted 7 lines
Keep the cloned IPTFS state private until all allocations succeed so failed clones leave
x->mode_dataunset. The destroy path already handles a NULLmode_datapointer.Fixes 6be02e3e4f37 ("xfrm: iptfs: handle reordering of received packets")Signed-off-by Paul Moses <[email protected]>
Applied, thanks a lot!