Skip to content

Commit e619492

Browse files
committed
esp: Fix memleaks on error paths.
We leak the temporary allocated resources in error paths, fix this by freeing them. Fixes: fca11eb ("esp4: Reorganize esp_output") Fixes: 383d035 ("esp6: Reorganize esp_output") Fixes: 3f29770 ("ipsec: check return value of skb_to_sgvec always") Signed-off-by: Steffen Klassert <[email protected]>
1 parent edaf382 commit e619492

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

net/ipv4/esp4.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
381381
(unsigned char *)esph - skb->data,
382382
assoclen + ivlen + esp->clen + alen);
383383
if (unlikely(err < 0))
384-
goto error;
384+
goto error_free;
385385

386386
if (!esp->inplace) {
387387
int allocsize;
@@ -392,7 +392,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
392392
spin_lock_bh(&x->lock);
393393
if (unlikely(!skb_page_frag_refill(allocsize, pfrag, GFP_ATOMIC))) {
394394
spin_unlock_bh(&x->lock);
395-
goto error;
395+
goto error_free;
396396
}
397397

398398
skb_shinfo(skb)->nr_frags = 1;
@@ -409,7 +409,7 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
409409
(unsigned char *)esph - skb->data,
410410
assoclen + ivlen + esp->clen + alen);
411411
if (unlikely(err < 0))
412-
goto error;
412+
goto error_free;
413413
}
414414

415415
if ((x->props.flags & XFRM_STATE_ESN))
@@ -442,8 +442,9 @@ int esp_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
442442

443443
if (sg != dsg)
444444
esp_ssg_unref(x, tmp);
445-
kfree(tmp);
446445

446+
error_free:
447+
kfree(tmp);
447448
error:
448449
return err;
449450
}
@@ -695,8 +696,10 @@ static int esp_input(struct xfrm_state *x, struct sk_buff *skb)
695696

696697
sg_init_table(sg, nfrags);
697698
err = skb_to_sgvec(skb, sg, 0, skb->len);
698-
if (unlikely(err < 0))
699+
if (unlikely(err < 0)) {
700+
kfree(tmp);
699701
goto out;
702+
}
700703

701704
skb->ip_summed = CHECKSUM_NONE;
702705

net/ipv6/esp6.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
345345
(unsigned char *)esph - skb->data,
346346
assoclen + ivlen + esp->clen + alen);
347347
if (unlikely(err < 0))
348-
goto error;
348+
goto error_free;
349349

350350
if (!esp->inplace) {
351351
int allocsize;
@@ -356,7 +356,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
356356
spin_lock_bh(&x->lock);
357357
if (unlikely(!skb_page_frag_refill(allocsize, pfrag, GFP_ATOMIC))) {
358358
spin_unlock_bh(&x->lock);
359-
goto error;
359+
goto error_free;
360360
}
361361

362362
skb_shinfo(skb)->nr_frags = 1;
@@ -373,7 +373,7 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
373373
(unsigned char *)esph - skb->data,
374374
assoclen + ivlen + esp->clen + alen);
375375
if (unlikely(err < 0))
376-
goto error;
376+
goto error_free;
377377
}
378378

379379
if ((x->props.flags & XFRM_STATE_ESN))
@@ -406,8 +406,9 @@ int esp6_output_tail(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
406406

407407
if (sg != dsg)
408408
esp_ssg_unref(x, tmp);
409-
kfree(tmp);
410409

410+
error_free:
411+
kfree(tmp);
411412
error:
412413
return err;
413414
}

0 commit comments

Comments
 (0)