Stable fixes for batman-adv
Subsystems (3)
Sven Eckelmann
maintainerHi,
it seems that patches aren't forwarded anymore (since August?) from batman-adv to the netdev mailing list. Please correct me if I am wrong.
I would hereby try to send some patches directly to the netdev mailing list instead of waiting any longer for the patches to be forwarded. There are more non-feature patches [1] waiting in the batman-adv repo (everything after "batman-adv: fix alignment" from 2014-05-15) but these don't seem to be related to crashes.
At least the first patch caused crashes in real world scenarios [2] and could also be used to crash a mesh node on-demand. The last patch has its bug report in the linux bug tracker [3]. The second patch is a wrong size calculation but no problem was yet observed in the wild.
All patches fix problems which were introduced in Linux 3.13.
Kind regards,
Sven
[1] http://git.open-mesh.org/batman-adv.git/shortlog/refs/heads/maint
[2] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2014-November/012561.html
[3] https://bugzilla.kernel.org/show_bug.cgi?id=84061
Sven Eckelmann
maintainerPATCH 1/3 batman-adv: Calculate extra tail size based on queued fragments
The fragmentation code was replaced in 610bfc6bc99bc83680d190ebc69359a05fc7f605 ("batman-adv: Receive fragmented packets and merge"). The new code provided a mostly unused parameter skb for the merging function. It is used inside the function to calculate the additionally needed skb tailroom. But instead of increasing its own tailroom, it is only increasing the tailroom of the first queued skb. This is not correct in some situations because the first queued entry can be a different one than the parameter.
An observed problem was:
1. packet with size 104, total_size 1464, fragno 1 was received
- packet is queued
2. packet with size 1400, total_size 1464, fragno 0 was received
- packet is queued at the end of the list
3. enough data was received and can be given to the merge function (1464 == (1400 - 20) + (104 - 20))
- merge functions gets 1400 byte large packet as skb argument
4. merge function gets first entry in queue (104 byte)
- stored as skb_out
5. merge function calculates the required extra tail as total_size - skb->len
- pskb_expand_head tail of skb_out with 64 bytes
6. merge function tries to squeeze the extra 1380 bytes from the second queued skb (1400 byte aka skb parameter) in the 64 extra tail bytes of skb_out
Instead calculate the extra required tail bytes for skb_out also using skb_out instead of using the parameter skb. The skb parameter is only used to get the total_size from the last received packet. This is also the total_size used to decide that all fragments were received.
---
Problem is in the kernel since v3.13 and may be important for the stable tree.
net/batman-adv/fragmentation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/fragmentation.c +1 -1
@@ -251,7 +251,7 @@ batadv_frag_merge_packets(struct hlist_head *chain, struct sk_buff *skb)kfree (entry);/* Make room for the rest of the fragments. */ -if (pskb_expand_head (skb_out,0 , size - skb->len,GFP_ATOMIC ) <0 ) { +if (pskb_expand_head (skb_out,0 , size - skb_out->len,GFP_ATOMIC ) <0 ) {kfree_skb (skb_out); skb_out =NULL ; goto free;
Signature · 1 line
2.1.4
Sven Eckelmann
maintainerPATCH 2/3 batman-adv: Unify fragment size calculation
In reply to Sven EckelmannThe fragmentation code was replaced in 610bfc6bc99bc83680d190ebc69359a05fc7f605 ("batman-adv: Receive fragmented packets and merge") by an implementation which can handle up to 16 fragments of a packet. The packet is prepared for the split in fragments by the function batadv_frag_send_packet and the actual split is done by batadv_frag_create.
Both functions calculate the size of a fragment themself. But their calculation differs because batadv_frag_send_packet also subtracts ETH_HLEN. Therefore, the check in batadv_frag_send_packet "can a full fragment can be created?" may return true even when batadv_frag_create cannot create a full fragment.
The function batadv_frag_create doesn't check the size of the skb before splitting it and therefore might try to create a larger fragment than the remaining buffer. This creates an integer underflow and an invalid len is given to skb_split.
---
Problem is in the kernel since v3.13 and may be important for the stable tree.
net/batman-adv/fragmentation.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/fragmentation.c +1 -1
@@ -434,7 +434,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,* fragments larger than BATADV_FRAG_MAX_FRAG_SIZE */ mtu =min_t (unsigned, mtu,BATADV_FRAG_MAX_FRAG_SIZE ); - max_fragment_size = (mtu - header_size -ETH_HLEN ); + max_fragment_size = mtu - header_size; max_packet_size = max_fragment_size *BATADV_FRAG_MAX_FRAGMENTS ;/* Don't even try to fragment, if we need more than 16 fragments */
Signature · 1 line
2.1.4
Sven Eckelmann
maintainerPATCH 3/3 batman-adv: avoid NULL dereferences and fix if check
In reply to Sven EckelmannFrom: Antonio Quartulli <[email protected]>
Gateway having bandwidth_down equal to zero are not accepted at all and so never added to the Gateway list.
For this reason checking the bandwidth_down member in batadv_gw_out_of_range() is useless.
This is probably a copy/paste error and this check was supposed to be "!gw_node" only. Moreover, the way the check is written now may also lead to a NULL dereference.
Fix this by rewriting the if-condition properly.
Introduced by 414254e342a0d58144de40c3da777521ebaeeb07 ("batman-adv: tvlv - gateway download/upload bandwidth container")
---
Problem is in the kernel since v3.13 and may be important for the stable tree.
net/batman-adv/gateway_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/gateway_client.c +1 -1
@@ -810,7 +810,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, goto out; gw_node =batadv_gw_node_get (bat_priv, orig_dst_node); -if (!gw_node->bandwidth_down ==0 ) +if (!gw_node) goto out;switch (atomic_read (&bat_priv->gw_mode)) {
Signature · 1 line
2.1.4
Hi Sven,
Quoted 5 lines · Sven Eckelmann
Hi,
it seems that patches aren't forwarded anymore (since August?) from batman-adv to the netdev mailing list. Please correct me if I am wrong.
Thank you very much for sending these patches to stable. Unfortunately in the last months I've been really busy with work and my focus has been shifted a bit away ... I should be able to get back in sync after these Christmas and New Year holidays.
David, please merge these fixes and queue them for stable even if this is not the standard pull request we usually do.
Thank you all again for your work.
Regards,
Signature · 1 line
Antonio Quartulli
David Miller
maintainerFrom: Antonio Quartulli <[email protected]>
Date: Sun, 21 Dec 2014 10:39:13 +0100
Quoted 2 lines
David, please merge these fixes and queue them for stable even if this is not the standard pull request we usually do.
Fair enough, will do.