All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: Re: [B.A.T.M.A.N.] [PATCHv5] batctl: tcpdump - parse TVLV containers
Date: Tue, 11 Nov 2014 23:56:03 +0100	[thread overview]
Message-ID: <2091412.EK1SUSK0CW@sven-edge> (raw)
In-Reply-To: <1414917484-13213-1-git-send-email-antonio@meshcoding.com>

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

> +typedef void (*batctl_tvlv_parser_t)(void *buff, ssize_t buff_len);
> +
> +/* location [i][j] contains the parsing function for TVLV of type 'i' and
> + * version 'j + 1'
> + */
> +batctl_tvlv_parser_t tvlv_parsers[][1] = {
> +       [BATADV_TVLV_GW][0] = batctl_tvlv_parse_gw_v1,
> +       [BATADV_TVLV_DAT][0] = batctl_tvlv_parse_dat_v1,
> +       [BATADV_TVLV_NC][0] = batctl_tvlv_parse_nc_v1,
> +       [BATADV_TVLV_TT][0] = batctl_tvlv_parse_tt_v1,
> +       [BATADV_TVLV_ROAM][0] = batctl_tvlv_parse_roam_v1,
> +};
[....]
> +       while (tvlv_len > 0) {
> +               tvlv_hdr = (struct batadv_tvlv_hdr *)ptr;
> +               len = ntohs(tvlv_hdr->len);
> +
> +               parser = tvlv_parsers[tvlv_hdr->type][tvlv_hdr->version - 1];
> +               parser(tvlv_hdr + 1, len);
> +
> +               /* go to the next container */
> +               ptr = (uint8_t *)(tvlv_hdr + 1) + len;
> +               tvlv_len -= sizeof(*tvlv_hdr) + len;
> +       }
> +}
> +
[....]
> +       while (tvlv_len > 0) {
> +               tvlv_hdr = (struct batadv_tvlv_hdr *)ptr;
> +               len = ntohs(tvlv_hdr->len);
> +
> +               parser = tvlv_parsers[tvlv_hdr->type][tvlv_hdr->version - 1];
> +               parser(tvlv_hdr + 1, len);
> +
> +               /* go to the next container */
> +               ptr = (uint8_t *)(tvlv_hdr + 1) + len;
> +               tvlv_len -= sizeof(*tvlv_hdr) + len;
> +       }
>  }

I've already explained this to Antonio but here again in public:

 * neither type nor version are validated
 * the type can point in tvlv_parsers  to an invalid (non-existing) entry
 * the version of this entry can also point to an invalid parser
 * this is a big problem because I can crash batctl td with data packets
   send from other people (even valid data packets with mcast tvlv)
 * I've already experienced this problem when using nodes from a company
   which ships this patch since a while (> 4 months)

Maybe it can be redone with some switch statements or
(more space consuming) full tables which can handle all input data. Of course
a check of the returned parser is still necessary inside the loops.

Kind regards,
	Sven

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

  parent reply	other threads:[~2014-11-11 22:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-02  8:38 [B.A.T.M.A.N.] [PATCHv5] batctl: tcpdump - parse TVLV containers Antonio Quartulli
2014-11-09  4:37 ` Marek Lindner
2014-11-11 22:56 ` Sven Eckelmann [this message]
2014-11-12  9:26   ` Sven Eckelmann

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=2091412.EK1SUSK0CW@sven-edge \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.