netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Robert Shearman <rshearma@brocade.com>
Cc: "davem\@davemloft.net" <davem@davemloft.net>,
	"netdev\@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH net-next ] mpls:  In mpls_egress verify the packet length.
Date: Thu, 12 Mar 2015 15:54:52 -0500	[thread overview]
Message-ID: <87wq2mym03.fsf_-_@x220.int.ebiederm.org> (raw)
In-Reply-To: <87385a13jz.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Thu, 12 Mar 2015 13:19:44 -0500")


Robert Shearman noticed that mpls_egress is failing to verify that
the bytes to be examined are in fact present in the packet before
mpls_egress reads those bytes.

Reported-by: Robert Shearman <rshearma@brocade.com>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---
 net/mpls/af_mpls.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 0ad8f7141be2..d5882c5c176b 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -92,17 +92,25 @@ static bool mpls_egress(struct mpls_route *rt, struct sk_buff *skb,
 	 * The strange cases if we choose to support them will require
 	 * manual configuration.
 	 */
-	struct iphdr *hdr4 = ip_hdr(skb);
+	struct iphdr *hdr4;
 	bool success = true;
 
-	if (hdr4->version == 4) {
+	/* If the packet is empty we can't do anything */
+	if (!pskb_may_pull(skb, 1))
+		return false;
+
+	/* Use ip_hdr to find the ip protocol version */
+	hdr4 = ip_hdr(skb);
+	if ((hdr4->version == 4) &&
+	    pskb_may_pull(skb, sizeof(struct iphdr))) {
 		skb->protocol = htons(ETH_P_IP);
 		csum_replace2(&hdr4->check,
 			      htons(hdr4->ttl << 8),
 			      htons(dec.ttl << 8));
 		hdr4->ttl = dec.ttl;
 	}
-	else if (hdr4->version == 6) {
+	else if ((hdr4->version == 6) &&
+		 pskb_may_pull(skb, sizeof(struct ipv6hdr))) {
 		struct ipv6hdr *hdr6 = ipv6_hdr(skb);
 		skb->protocol = htons(ETH_P_IPV6);
 		hdr6->hop_limit = dec.ttl;
-- 
2.2.1

  reply	other threads:[~2015-03-12 20:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-11 12:58 [PATCH net-next] mpls: Infer payload of packet from via address family Robert Shearman
2015-03-11 17:29 ` Eric W. Biederman
2015-03-11 22:02   ` Robert Shearman
2015-03-12 18:19     ` Eric W. Biederman
2015-03-12 20:54       ` Eric W. Biederman [this message]
2015-03-12 22:25         ` [PATCH net-next ] mpls: In mpls_egress verify the packet length David Miller
2015-03-12 22:50           ` Eric W. Biederman
2015-03-12 23:22             ` Eric W. Biederman
2015-03-13  3:05               ` David Miller
2015-03-13 14:51       ` [PATCH net-next] mpls: Infer payload of packet from via address family Robert Shearman
2015-03-13 17:08         ` Eric W. Biederman

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=87wq2mym03.fsf_-_@x220.int.ebiederm.org \
    --to=ebiederm@xmission.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=rshearma@brocade.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;
as well as URLs for NNTP newsgroup(s).