Commit d849a2f7 authored by Paul Moses's avatar Paul Moses Committed by Steffen Klassert
Browse files

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.

Fixes: 6be02e3e ("xfrm: iptfs: handle reordering of received packets")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarPaul Moses <p@1g4.org>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
parent eb2d16a7
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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;
}