Skip to content

Commit 5b16100

Browse files
committed
Merge tag 'batadv-net-for-davem-20190830' of git://git.open-mesh.org/linux-merge
Simon Wunderlich says: ==================== Here are two batman-adv bugfixes: - Fix OGM and OGMv2 header read boundary check, by Sven Eckelmann (2 patches) ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents c3d7a08 + 0ff0f15 commit 5b16100

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

net/batman-adv/bat_iv_ogm.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,23 @@ static u8 batadv_hop_penalty(u8 tq, const struct batadv_priv *bat_priv)
277277
* batadv_iv_ogm_aggr_packet() - checks if there is another OGM attached
278278
* @buff_pos: current position in the skb
279279
* @packet_len: total length of the skb
280-
* @tvlv_len: tvlv length of the previously considered OGM
280+
* @ogm_packet: potential OGM in buffer
281281
*
282282
* Return: true if there is enough space for another OGM, false otherwise.
283283
*/
284-
static bool batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
285-
__be16 tvlv_len)
284+
static bool
285+
batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
286+
const struct batadv_ogm_packet *ogm_packet)
286287
{
287288
int next_buff_pos = 0;
288289

289-
next_buff_pos += buff_pos + BATADV_OGM_HLEN;
290-
next_buff_pos += ntohs(tvlv_len);
290+
/* check if there is enough space for the header */
291+
next_buff_pos += buff_pos + sizeof(*ogm_packet);
292+
if (next_buff_pos > packet_len)
293+
return false;
294+
295+
/* check if there is enough space for the optional TVLV */
296+
next_buff_pos += ntohs(ogm_packet->tvlv_len);
291297

292298
return (next_buff_pos <= packet_len) &&
293299
(next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
@@ -315,7 +321,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
315321

316322
/* adjust all flags and log packets */
317323
while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
318-
batadv_ogm_packet->tvlv_len)) {
324+
batadv_ogm_packet)) {
319325
/* we might have aggregated direct link packets with an
320326
* ordinary base packet
321327
*/
@@ -1704,7 +1710,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
17041710

17051711
/* unpack the aggregated packets and process them one by one */
17061712
while (batadv_iv_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
1707-
ogm_packet->tvlv_len)) {
1713+
ogm_packet)) {
17081714
batadv_iv_ogm_process(skb, ogm_offset, if_incoming);
17091715

17101716
ogm_offset += BATADV_OGM_HLEN;

net/batman-adv/bat_v_ogm.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,17 +631,23 @@ batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv,
631631
* batadv_v_ogm_aggr_packet() - checks if there is another OGM aggregated
632632
* @buff_pos: current position in the skb
633633
* @packet_len: total length of the skb
634-
* @tvlv_len: tvlv length of the previously considered OGM
634+
* @ogm2_packet: potential OGM2 in buffer
635635
*
636636
* Return: true if there is enough space for another OGM, false otherwise.
637637
*/
638-
static bool batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
639-
__be16 tvlv_len)
638+
static bool
639+
batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
640+
const struct batadv_ogm2_packet *ogm2_packet)
640641
{
641642
int next_buff_pos = 0;
642643

643-
next_buff_pos += buff_pos + BATADV_OGM2_HLEN;
644-
next_buff_pos += ntohs(tvlv_len);
644+
/* check if there is enough space for the header */
645+
next_buff_pos += buff_pos + sizeof(*ogm2_packet);
646+
if (next_buff_pos > packet_len)
647+
return false;
648+
649+
/* check if there is enough space for the optional TVLV */
650+
next_buff_pos += ntohs(ogm2_packet->tvlv_len);
645651

646652
return (next_buff_pos <= packet_len) &&
647653
(next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
@@ -818,7 +824,7 @@ int batadv_v_ogm_packet_recv(struct sk_buff *skb,
818824
ogm_packet = (struct batadv_ogm2_packet *)skb->data;
819825

820826
while (batadv_v_ogm_aggr_packet(ogm_offset, skb_headlen(skb),
821-
ogm_packet->tvlv_len)) {
827+
ogm_packet)) {
822828
batadv_v_ogm_process(skb, ogm_offset, if_incoming);
823829

824830
ogm_offset += BATADV_OGM2_HLEN;

0 commit comments

Comments
 (0)