From: Baruch Siach <baruch@tkos.co.il>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] net: fix checksum verification
Date: Fri, 9 Aug 2013 13:16:49 +0300 [thread overview]
Message-ID: <20130809101649.GA3703@tarshish> (raw)
In-Reply-To: <20130809073237.GA26614@pengutronix.de>
Hi Sascha,
On Fri, Aug 09, 2013 at 09:32:37AM +0200, Sascha Hauer wrote:
> On Fri, Aug 09, 2013 at 07:01:24AM +0300, Baruch Siach wrote:
> > Checksum verification on data including its own checksum (as is the case with
> > IP headers) should give zero. Current code works well for the correct checksum
> > case, but fails to identify (most) errors.
> >
> > Signed-off-by: Baruch Siach <baruch@tkos.co.il>
> > ---
> >
> > Untested. From code inspection only.
> >
> > net/net.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/net/net.c b/net/net.c
> > index 0bd9084..bd7a578 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -41,7 +41,7 @@ static unsigned int net_ip_id;
> >
> > int net_checksum_ok(unsigned char *ptr, int len)
> > {
> > - return net_checksum(ptr, len) + 1;
> > + return net_checksum(ptr, len) == 0;
>
> D'oh. There's a bug indeed. For a good packet net_checksum returns
> 0xffff (all ones in an u16). So the check should be:
>
> return net_checksum(ptr, len) == 0xffff;
You're right, of course. I was just blindly copying the kernel that has this
in ip_rcv():
if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
goto csum_error;
But I still don't understand the logic here.
baruch
--
http://baruch.siach.name/blog/ ~. .~ Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
- baruch@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2013-08-09 10:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-09 4:01 [PATCH] net: fix checksum verification Baruch Siach
2013-08-09 7:32 ` Sascha Hauer
2013-08-09 8:50 ` Uwe Kleine-König
2013-08-09 8:57 ` Sascha Hauer
2013-08-09 10:16 ` Baruch Siach [this message]
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=20130809101649.GA3703@tarshish \
--to=baruch@tkos.co.il \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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.