From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753184AbbJKXKC (ORCPT ); Sun, 11 Oct 2015 19:10:02 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:34494 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752517AbbJKXJc (ORCPT ); Sun, 11 Oct 2015 19:09:32 -0400 Message-ID: <1444604969.27760.149.camel@edumazet-glaptop2.roam.corp.google.com> Subject: Re: [PATCH] icmp: Fixed bug in raw sockets causing incorrect ICMP SNMP counter values From: Eric Dumazet To: Ben Cox Cc: davem@davemloft.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, ben+patches@benjojo.co.uk, David L Stevens Date: Sun, 11 Oct 2015 16:09:29 -0700 In-Reply-To: <1444603443.27760.147.camel@edumazet-glaptop2.roam.corp.google.com> References: <20151011205528.GA4322@benjojo.co.uk> <1444601448.27760.143.camel@edumazet-glaptop2.roam.corp.google.com> <1444603382.27760.146.camel@edumazet-glaptop2.roam.corp.google.com> <1444603443.27760.147.camel@edumazet-glaptop2.roam.corp.google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2015-10-11 at 15:44 -0700, Eric Dumazet wrote: > On Sun, 2015-10-11 at 15:43 -0700, Eric Dumazet wrote: > > > But your code reads 21th byte. > > BTW, nice catch ! Maybe the following one. 1) We properly set transport header 2) We use icmp_hdr() helper. diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index 561cd4b8fc6e..ffe25cd1f0e0 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -406,11 +406,11 @@ static int raw_send_hdrinc(struct sock *sk, struct flowi4 *fl4, ip_select_ident(net, skb, NULL); iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl); + skb->transport_header += iphlen; + if (iph->protocol == IPPROTO_ICMP && + length >= iphlen + sizeof(struct icmphdr)) + icmp_out_count(net, icmp_hdr(skb)->type); } - if (iph->protocol == IPPROTO_ICMP) - icmp_out_count(net, ((struct icmphdr *) - skb_transport_header(skb))->type); - err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, sk, skb, NULL, rt->dst.dev, dst_output_sk); if (err > 0)