dccp: Fix incorrect length check for ICMPv4 packets

Previous thread: dccp: Add check for truncated ICMPv6 DCCP error packets by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:00 am. (1 message)

Next thread: dccp: Bug-Fix - AWL was never updated by Linux Kernel Mailing List on Monday, July 28, 2008 - 9:59 am. (1 message)
From: Linux Kernel Mailing List
Date: Monday, July 28, 2008 - 10:00 am

Gitweb:     http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=18e1d8...
Commit:     18e1d836002ad970f42736bad09b7be9cfe99545
Parent:     e0bcfb0c6a6ed9ebd68746b306298dc5797fd426
Author:     Wei Yongjun <yjwei@cn.fujitsu.com>
AuthorDate: Sat Jul 26 11:59:10 2008 +0100
Committer:  Gerrit Renker <gerrit@erg.abdn.ac.uk>
CommitDate: Sat Jul 26 11:59:10 2008 +0100

    dccp: Fix incorrect length check for ICMPv4 packets
    
    Unlike TCP, which only needs 8 octets of original packet data, DCCP requires
    minimally 12 or 16 bytes for ICMP-payload sequence number checks.
    
    This patch replaces the insufficient length constant of 8 with a two-stage
    test, making sure that 12 bytes are available, before computing the basic
    header length required for sequence number checks.
    
    Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
    Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
---
 net/dccp/ipv4.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 6a2f187..882c5c4 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -196,8 +196,8 @@ static inline void dccp_do_pmtu_discovery(struct sock *sk,
 static void dccp_v4_err(struct sk_buff *skb, u32 info)
 {
 	const struct iphdr *iph = (struct iphdr *)skb->data;
-	const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data +
-							(iph->ihl << 2));
+	const u8 offset = iph->ihl << 2;
+	const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + offset);
 	struct dccp_sock *dp;
 	struct inet_sock *inet;
 	const int type = icmp_hdr(skb)->type;
@@ -207,7 +207,8 @@ static void dccp_v4_err(struct sk_buff *skb, u32 info)
 	int err;
 	struct net *net = dev_net(skb->dev);
 
-	if (skb->len < (iph->ihl << 2) + 8) {
+	if (skb->len < offset + sizeof(*dh) ||
+	    skb->len < offset + __dccp_basic_hdr_len(dh)) {
 		ICMP_INC_STATS_BH(net, ICMP_MIB_INERRORS);
 		return;
 	}
--

Previous thread: dccp: Add check for truncated ICMPv6 DCCP error packets by Linux Kernel Mailing List on Monday, July 28, 2008 - 10:00 am. (1 message)

Next thread: dccp: Bug-Fix - AWL was never updated by Linux Kernel Mailing List on Monday, July 28, 2008 - 9:59 am. (1 message)