NetBSD Problem Report #43882
From www@NetBSD.org Wed Sep 15 06:33:18 2010
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by www.NetBSD.org (Postfix) with ESMTP id CDF3963B960
for <gnats-bugs@gnats.NetBSD.org>; Wed, 15 Sep 2010 06:33:17 +0000 (UTC)
Message-Id: <20100915063317.678C963B95D@www.NetBSD.org>
Date: Wed, 15 Sep 2010 06:33:17 +0000 (UTC)
From: bybinary01@gmail.com
Reply-To: bybinary01@gmail.com
To: gnats-bugs@NetBSD.org
Subject: On special condition,you get incorrect TCP checksum.
X-Send-Pr-Version: www-1.0
>Number: 43882
>Category: port-mips
>Synopsis: On special condition,you get incorrect TCP checksum.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: tsutsui
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Sep 15 06:35:00 +0000 2010
>Closed-Date: Tue Oct 12 19:49:59 +0000 2010
>Last-Modified: Tue Oct 12 19:49:59 +0000 2010
>Originator: Fumiyuki.Yoshida
>Release: Netbsd2.0.2(This problem remains on current)
>Organization:
Ricoh
>Environment:
>Description:
You get incorrect TCP checksum on following condition.
(1)mbufs size is 2byte.
(2)align is not 32-bit-align.
For example,mbufs data is 0x1234,we get 0x4600.(Correct sum is 0x1234)
>How-To-Repeat:
>Fix:
Apply following patch to sys/arch/mips/mips/in_cksum.c
(Diff to 1.13(latest))
86d85
<
88,115c87
< if (n < 3){
< /*
< * This code is for following condition.
< * (1)mbufs size is 2byte.
< * (2)align is not 32-bit-align.
< *
< * On this condition,we should get checksum by
< * step1. 8-bit shift upper 1byte.
< * step2. add step1's value and lower 1byte.
< *
< * For example mbufs data is 0x1234,
< * step1. 0x12 << 8 --> 0x1200
< * step2. 0x1200 + 0x34 --> 0x1234
< */
< if (n == 2){
< sum = *(buf.c);
< #if BYTE_ORDER == BIG_ENDIAN
< sum = sum << 8;
< buf.c++;
< sum += *(buf.c);
< #else
< buf.c++;
< sum += *(buf.c) << 8;
< #endif
< buf.c++;
< n -= 2;
< }
<
---
> if (n < 3)
117c89
< }
---
>
>Release-Note:
>Audit-Trail:
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: gnats-bugs@NetBSD.org
Cc: port-mips-maintainer@NetBSD.org, gnats-admin@NetBSD.org,
netbsd-bugs@NetBSD.org, tsutsui@ceres.dti.ne.jp
Subject: Re: port-mips/43882: On special condition,you get incorrect TCP checksum.
Date: Wed, 15 Sep 2010 19:14:43 +0900
> Apply following patch to sys/arch/mips/mips/in_cksum.c
BTW, human readable unified diff (by diff -u) is better in PRs.
> < if (n < 3){
> < /*
> < * This code is for following condition.
> < * (1)mbufs size is 2byte.
> < * (2)align is not 32-bit-align.
Your analysis looks correct, but I don't think we have to
handle unaligned two byte payload as a special case.
It's enough to fix handlings for leading/trailing unaligned words/bytes.
How about this one? (untested)
Index: in_cksum.c
===================================================================
RCS file: /cvsroot/src/sys/arch/mips/mips/in_cksum.c,v
retrieving revision 1.13
diff -u -p -r1.13 in_cksum.c
--- in_cksum.c 24 Jan 2007 13:08:11 -0000 1.13
+++ in_cksum.c 15 Sep 2010 10:02:18 -0000
@@ -56,11 +56,10 @@ __KERNEL_RCSID(0, "$NetBSD: in_cksum.c,v
#include <machine/endian.h>
union memptr {
- unsigned int *i;
- unsigned long *l;
- unsigned long u;
- unsigned short *s;
- unsigned char *c;
+ uint32_t *l;
+ uintptr_t u;
+ uint16_t *s;
+ uint8_t *c;
};
static inline uint32_t fastsum(union memptr, int, unsigned int, int);
@@ -83,10 +82,6 @@ fastsum(union memptr buf, int n, unsigne
/* Align to 32 bits. */
if (buf.u & 0x3) {
- /* Skip to the end for very small mbufs */
- if (n < 3)
- goto verylittleleft;
-
/*
* 16-bit-align.
* If buf is odd-byte-aligned, add the byte and toggle
@@ -107,6 +102,9 @@ fastsum(union memptr buf, int n, unsigne
n -= 1;
odd_aligned = !odd_aligned;
}
+ /* Skip to the end for very small mbufs */
+ if (n <= 2)
+ goto postunaligned;
/* 32-bit-align */
if (buf.u & 0x2) {
@@ -198,7 +196,7 @@ fastsum(union memptr buf, int n, unsigne
notmuchleft:
high = hilo = 0;
- while (n >= 4) {
+ while (n >= sizeof(uint32_t)) {
w0 = *(buf.l++);
hilo += w0;
high += w0 >> 16;
@@ -208,19 +206,21 @@ fastsum(union memptr buf, int n, unsigne
sum += hilo;
sum += high;
- while (n > 1) {
- n -= sizeof(*buf.s);
+ postunaligned:
+ /* handle post 32bit unaligned payloads */
+ if (n >= sizeof(uint16_t)) {
sum += *(buf.s++);
+ n -= sizeof(uint16_t);
}
- verylittleleft:
- /* handle trailing byte and short (possibly) unaligned payloads */
- while (n-- > 0) {
+ /* handle a trailing odd byte */
+ if (n > 0) {
#if BYTE_ORDER == BIG_ENDIAN
sum += *(buf.c++) << 8;
#else
sum += *(buf.c++);
#endif
+ n = 0;
}
/*
---
Izumi Tsutsui
State-Changed-From-To: open->feedback
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Wed, 15 Sep 2010 20:51:45 +0900
State-Changed-Why:
Awaiting feedback.
Note mips/in_cksum.c has not been used since cpu_in_cksum refactering in 2008
and there is a report that MI version is faster than old MD one.
From: akachochin <bybinary01@gmail.com>
To: gnats-bugs@netbsd.org
Cc: port-mips-maintainer@netbsd.org, netbsd-bugs@netbsd.org,
gnats-admin@netbsd.org, tsutsui@netbsd.org
Subject: Re: port-mips/43882 (On special condition,you get incorrect TCP checksum.)
Date: Thu, 16 Sep 2010 21:47:55 +0900
--001485f6dacce371f404905fda13
Content-Type: text/plain; charset=ISO-8859-1
> Note mips/in_cksum.c has not been used since cpu_in_cksum refactering in
> 2008
> and there is a report that MI version is faster than old MD one.
>
Thank you very much for your above information.
I don't know that the source has not been used :-)
I found this problem because our product contains old netbsd.....
--001485f6dacce371f404905fda13
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"m=
argin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); paddin=
g-left: 1ex;">
Note mips/in_cksum.c has not been used since cpu_in_cksum refactering in 20=
08<br>
and there is a report that MI version is faster than old MD one.<br></block=
quote><div><br>Thank you very much for your above information.<br>I don'=
;t know that the source has not been used :-)<br>I found this problem becau=
se our product contains old netbsd.....<br>
<br>=A0<br></div><br></div><br>
--001485f6dacce371f404905fda13--
From: Izumi Tsutsui <tsutsui@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/43882 CVS commit: src/sys/arch/mips/mips
Date: Sat, 18 Sep 2010 16:43:51 +0000
Module Name: src
Committed By: tsutsui
Date: Sat Sep 18 16:43:51 UTC 2010
Modified Files:
src/sys/arch/mips/mips: in_cksum.c
Log Message:
Fix wrong checksum calculations of 32 bit unaligned two byte payloads.
Analyzed in PR port-mips/43882, but applied slightly different patch.
Also put some changes for readability.
Note netbsd-5 doesn't use this MD version but netbsd-4 needs a pullup.
(though it's unclear if it's really faster even on modern aggressive gcc4)
To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/mips/mips/in_cksum.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: port-mips-maintainer->tsutsui
Responsible-Changed-By: tsutsui@NetBSD.org
Responsible-Changed-When: Mon, 20 Sep 2010 15:48:52 +0900
Responsible-Changed-Why:
I committed fix
State-Changed-From-To: feedback->pending-pullups
State-Changed-By: tsutsui@NetBSD.org
State-Changed-When: Mon, 20 Sep 2010 15:48:52 +0900
State-Changed-Why:
netbsd-4 needs pullup
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
To: gnats-bugs@NetBSD.org
Cc: tsutsui@NetBSD.org, gnats-admin@NetBSD.org
Subject: Re: port-mips/43882 (On special condition,you get incorrect TCP checksum.)
Date: Sat, 25 Sep 2010 23:53:50 +0900
> netbsd-4 needs pullup
pullup-4 #1407
---
Izumi Tsutsui
From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/43882 CVS commit: [netbsd-4] src/sys/arch/mips/mips
Date: Tue, 12 Oct 2010 10:13:12 +0000
Module Name: src
Committed By: bouyer
Date: Tue Oct 12 10:13:12 UTC 2010
Modified Files:
src/sys/arch/mips/mips [netbsd-4]: in_cksum.c
Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1407):
sys/arch/mips/mips/in_cksum.c: revision 1.14
Fix wrong checksum calculations of 32 bit unaligned two byte payloads.
Analyzed in PR port-mips/43882, but applied slightly different patch.
Also put some changes for readability.
Note netbsd-5 doesn't use this MD version but netbsd-4 needs a pullup.
(though it's unclear if it's really faster even on modern aggressive gcc4)
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.12.12.1 src/sys/arch/mips/mips/in_cksum.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Tue, 12 Oct 2010 19:49:59 +0000
State-Changed-Why:
pullups done
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.