Merge pull request #279 from ecsv/batadv-maint
[feed/routing.git] / batman-adv / patches / 0003-batman-adv-Fix-double-free-during-fragment-merge-err.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Sun, 12 Feb 2017 11:26:33 +0100
3 Subject: [PATCH] batman-adv: Fix double free during fragment merge error
4
5 The function batadv_frag_skb_buffer was supposed not to consume the skbuff
6 on errors. This was followed in the helper function
7 batadv_frag_insert_packet when the skb would potentially be inserted in the
8 fragment queue. But it could happen that the next helper function
9 batadv_frag_merge_packets would try to merge the fragments and fail. This
10 results in a kfree_skb of all the enqueued fragments (including the just
11 inserted one). batadv_recv_frag_packet would detect the error in
12 batadv_frag_skb_buffer and try to free the skb again.
13
14 The behavior of batadv_frag_skb_buffer (and its helper
15 batadv_frag_insert_packet) must therefore be changed to always consume the
16 skbuff to have a common behavior and avoid the double kfree_skb.
17
18 Fixes: 9b3eab61754d ("batman-adv: Receive fragmented packets and merge")
19 Signed-off-by: Sven Eckelmann <sven@narfation.org>
20
21 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/e3bab02816097f860545d9ce9ae0808c69d7c92f
22 ---
23 net/batman-adv/fragmentation.c | 8 +++++---
24 1 file changed, 5 insertions(+), 3 deletions(-)
25
26 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
27 index 0854ebd8..31e97e9a 100644
28 --- a/net/batman-adv/fragmentation.c
29 +++ b/net/batman-adv/fragmentation.c
30 @@ -239,8 +239,10 @@ err_unlock:
31 spin_unlock_bh(&chain->lock);
32
33 err:
34 - if (!ret)
35 + if (!ret) {
36 kfree(frag_entry_new);
37 + kfree_skb(skb);
38 + }
39
40 return ret;
41 }
42 @@ -313,7 +315,7 @@ free:
43 *
44 * There are three possible outcomes: 1) Packet is merged: Return true and
45 * set *skb to merged packet; 2) Packet is buffered: Return true and set *skb
46 - * to NULL; 3) Error: Return false and leave skb as is.
47 + * to NULL; 3) Error: Return false and free skb.
48 *
49 * Return: true when packet is merged or buffered, false when skb is not not
50 * used.
51 @@ -338,9 +340,9 @@ bool batadv_frag_skb_buffer(struct sk_buff **skb,
52 goto out_err;
53
54 out:
55 - *skb = skb_out;
56 ret = true;
57 out_err:
58 + *skb = skb_out;
59 return ret;
60 }
61