Skip to contentSkip to conversation

xfrm: iptfs: only publish mode_data after clone setup

PATCH Superseded Paul Moses 3 participants 3 messages Mar 12 – Mar 13

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Paul Moses

author
#0 lore raw

PATCH v2 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.

Fixes 6be02e3e4f37 ("xfrm: iptfs: handle reordering of received packets")

---
Changes in v2:
- Fix Fixes tag to point to 6be02e3e4f37

 net/xfrm/xfrm_iptfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_iptfs.c +3 -3
index 050a82101ca51..4d7a925f59b7c 100644
@@ -2653,9 +2653,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 = kzalloc_objs(*xtfs->w_saved,
@@ -2666,6 +2663,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
maintainer
#1 lore raw
Quoted 37 lines · Paul Moses

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 6be02e3e4f37 ("xfrm: iptfs: handle reordering of received packets")

---
Changes in v2:
- Fix Fixes tag to point to 6be02e3e4f37

 net/xfrm/xfrm_iptfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
net/xfrm/xfrm_iptfs.c +0 -3
index 050a82101ca51..4d7a925f59b7c 100644
@@ -2653,9 +2653,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 = kzalloc_objs(*xtfs->w_saved,

net/xfrm/xfrm_iptfs.c static int iptfs_clone_state(struct xfrm_state *x, struct xfrm_state *orig) · line 2670

Quoted 8 lines
net/xfrm/xfrm_iptfs.c +3 -0
@@ -2666,6 +2663,9 @@ static int iptfs_clone_state(struct xfrm_state *x, struct xfrm_state *orig)
 		}
 	}
 
+	x->mode_data = xtfs;
+	xtfs->x = x;
+
 	return 0;
 }

This does not apply to the ipsec tree. Can you rebase on top of the current ipsec tree?

Thanks!

reviewer Reviewed-by on v2 1/1
#2 lore raw
In reply to Paul Moses
Quoted 12 lines · Paul Moses

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.

Quoted 6 lines
Fixes 6be02e3e4f37 ("xfrm: iptfs: handle reordering of received packets")

---
Changes in v2:
- Fix Fixes tag to point to 6be02e3e4f37

Thanks for the update.