public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: "'b.a.t.m.a.n@lists.open-mesh.org'" <b.a.t.m.a.n@lists.open-mesh.org>
Cc: Jan-Philipp Litza <janphilipp@litza.de>
Subject: Re: [B.A.T.M.A.N.] [PATCH] alfred: Tighten size check on received packet
Date: Tue, 20 Jan 2015 08:31:18 +0100	[thread overview]
Message-ID: <3346859.V9Mt6glXr0@sven-edge> (raw)
In-Reply-To: <1421705011.612946.10937.nullmailer@sylar.jplitza.de>

[-- Attachment #1: Type: text/plain, Size: 1248 bytes --]

On Monday 19 January 2015 21:59:32 Jan-Philipp Litza wrote:
> When first checking if a received packet is truncated, the size of the
> alfred_tlv structure is ignored, thus allowing packets that are
> truncated by 4 bytes or less to pass the check unnoticed.
> 
> Even the check itself might access memory after the packet if its size
> was only 2 bytes or less.
[...]
>  	/* drop truncated packets */
> -	if (length < ((int)ntohs(packet->length)))
> +	if (length < (int)sizeof(*packet) ||
> +	    length < (int)(ntohs(packet->length) + sizeof(*packet)))
>  		return -1;
> 
>  	/* drop incompatible packet */

Thanks for the patch. It is basically correct but maybe you can modify it
slightly to make it also catch very small packets.

diff --git a/recv.c b/recv.c
index 90db0b3..288f577 100644
--- a/recv.c
+++ b/recv.c
@@ -391,7 +391,12 @@ int recv_alfred_packet(struct globals *globals, struct interface *interface)
 		return -1;
 	}
 
+	/* drop packets smaller than tlv */
+	if (length < (int)sizeof(*packet))
+		return -1;
+
 	packet = (struct alfred_tlv *)buf;
+	length -= sizeof(*packet);
 
 	/* drop packets not sent over link-local ipv6 */
 	if (!is_ipv6_eui64(&source.sin6_addr))

Kind regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2015-01-20  7:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19 20:59 [B.A.T.M.A.N.] [PATCH] alfred: Tighten size check on received packet Jan-Philipp Litza
2015-01-20  7:31 ` Sven Eckelmann [this message]
2015-01-20  8:01   ` Jan-Philipp Litza
2015-01-20  8:28     ` Sven Eckelmann
2015-01-23 16:32 ` Simon Wunderlich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3346859.V9Mt6glXr0@sven-edge \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=janphilipp@litza.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox