public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Ward <david.ward@ll.mit.edu>
Cc: netdev@vger.kernel.org, Patrick McHardy <kaber@trash.net>,
	Philip Foulkes <philip.foulkes@gmail.com>
Subject: Re: [PATCH RFC 1/2] net/802: Implement Multiple Registration Protocol (MRP)
Date: Mon, 24 Sep 2012 23:36:48 +0200	[thread overview]
Message-ID: <1348522608.26828.1791.camel@edumazet-glaptop> (raw)
In-Reply-To: <1348520855-8810-2-git-send-email-david.ward@ll.mit.edu>

On Mon, 2012-09-24 at 17:07 -0400, David Ward wrote:

...

> +static int mrp_pdu_parse_end_mark(struct sk_buff *skb)
> +{
> +	__be16 *endmark;
> +
> +	if (!pskb_may_pull(skb, sizeof(*endmark)))
> +		return -1;
> +	endmark = (__be16 *)skb->data;
> +	if (get_unaligned(endmark) == MRP_END_MARK) {

You might try get_unaligned_be16(skb->data) ...

> +		skb_pull(skb, sizeof(*endmark));
> +		return -1;
> +	}
> +	return 0;
> +}
> +

...

> +
> +static int mrp_pdu_parse_msg(struct mrp_applicant *app, struct sk_buff *skb)
> +{
> +	if (!pskb_may_pull(skb, sizeof(*mrp_cb(skb)->mh)))
> +		return -1;
> +	mrp_cb(skb)->mh = (struct mrp_msg_hdr *)skb->data;

here you store a pointer to skb->data, in skb>cb[]

> +	if (mrp_cb(skb)->mh->attrtype == 0 ||
> +	    mrp_cb(skb)->mh->attrtype > app->app->maxattr ||
> +	    mrp_cb(skb)->mh->attrlen == 0)
> +		return -1;
> +	if (sizeof(struct mrp_skb_cb) + mrp_cb(skb)->mh->attrlen >
> +	    FIELD_SIZEOF(struct sk_buff, cb))
> +		return -1;
> +	skb_pull(skb, sizeof(*mrp_cb(skb)->mh));
> +
> +	while (skb->len > 0) {
> +		if (mrp_pdu_parse_end_mark(skb) < 0)
> +			break;

but skb->head can be reallocated by other pskb_may_pull() calls
done in mrp_pdu_parse_end_mark() (and elsewhere)

So skb->cb[] might contain a pointer to a freed memory.

> +		if (mrp_pdu_parse_vecattr(app, skb) < 0)
> +			return -1;
> +	}
> +	return 0;
> +}
> +

You might consider using skb_header_pointer() instead of
pskb_may_pull()/skb_pull(), it might be easier when you have such nested
headers...

  reply	other threads:[~2012-09-24 21:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24 21:07 [PATCH RFC 0/2] Multiple VLAN Registration Protocol (IEEE 802.1Q-2011) David Ward
2012-09-24 21:07 ` [PATCH RFC 1/2] net/802: Implement Multiple Registration Protocol (MRP) David Ward
2012-09-24 21:36   ` Eric Dumazet [this message]
2012-09-24 21:07 ` [PATCH RFC 2/2] net/8021q: Implement Multiple VLAN Registration Protocol (MVRP) David Ward
2012-09-24 21:07 ` [PATCH RFC iproute2] iplink_vlan: Add flag for " David Ward
2013-09-11  0:22 ` [PATCH RFC 0/2] Multiple VLAN Registration Protocol (IEEE 802.1Q-2011) Noel Burton-Krahn

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=1348522608.26828.1791.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=david.ward@ll.mit.edu \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=philip.foulkes@gmail.com \
    /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