Skip to content

Commit 0ff0f15

Browse files
ecsvsimonwunderlich
authored andcommitted
batman-adv: Only read OGM2 tvlv_len after buffer len check
Multiple batadv_ogm2_packet can be stored in an skbuff. The functions batadv_v_ogm_send_to_if() uses batadv_v_ogm_aggr_packet() to check if there is another additional batadv_ogm2_packet in the skb or not before they continue processing the packet. The length for such an OGM2 is BATADV_OGM2_HLEN + batadv_ogm2_packet->tvlv_len. The check must first check that at least BATADV_OGM2_HLEN bytes are available before it accesses tvlv_len (which is part of the header. Otherwise it might try read outside of the currently available skbuff to get the content of tvlv_len. Fixes: 9323158 ("batman-adv: OGMv2 - implement originators logic") Signed-off-by: Sven Eckelmann <[email protected]> Signed-off-by: Simon Wunderlich <[email protected]>
1 parent a15d56a commit 0ff0f15

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

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)