[v2,2/2] batman-adv: check for tt_reponse real length

Message ID 1318425058-715-2-git-send-email-ordex@autistici.org (mailing list archive)
State Superseded, archived
Headers

Commit Message

Antonio Quartulli Oct. 12, 2011, 1:10 p.m. UTC
  Before accessing the TT_RESPONSE message payload, we have to ensure that the
real length of the packet reflect the claimed one (contained in
tt_response->tt_data field)

Reported-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---

corrected skb length check

 routing.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
  

Comments

Marek Lindner Oct. 16, 2011, 5:12 p.m. UTC | #1
On Wednesday, October 12, 2011 15:10:58 Antonio Quartulli wrote:
> if (tt_query->flags & TT_FULL_TABLE)
> +                               tt_len = tt_query->tt_data * ETH_ALEN;

Odd, I had the feeling the full table also uses 'struct tt_change' and not 
plain ethernet addresses anymore.

From translation-table.c (send_my_tt_response):
tt_len = (uint16_t)atomic_read(&bat_priv->num_local_tt) * 
                              sizeof(struct tt_change);

Regards,
Marek
  

Patch

diff --git a/routing.c b/routing.c
index 20804f4..af55cf7 100644
--- a/routing.c
+++ b/routing.c
@@ -578,6 +578,7 @@  int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if)
 {
 	struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
 	struct tt_query_packet *tt_query;
+	uint16_t tt_len;
 	struct ethhdr *ethhdr;
 
 	/* drop packet if it has not necessary minimum size */
@@ -622,6 +623,18 @@  int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if)
 			if (skb_linearize(skb) < 0)
 				goto out;
 
+			if (tt_query->flags & TT_FULL_TABLE)
+				tt_len = tt_query->tt_data * ETH_ALEN;
+			else
+				tt_len = tt_query->tt_data *
+					 sizeof(struct tt_change);
+
+			/* Ensure we have all the claimed data */
+			if (unlikely(skb_headlen(skb) <
+					sizeof(struct tt_query_packet) +
+					tt_len))
+				goto out;
+
 			handle_tt_response(bat_priv, tt_query);
 		} else {
 			bat_dbg(DBG_TT, bat_priv,