NetBSD Problem Report #36038
From ekarknu@uab.ericsson.se Mon Mar 19 12:37:11 2007
Return-Path: <ekarknu@uab.ericsson.se>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id 6DE8363BA6C
for <gnats-bugs@gnats.netbsd.org>; Mon, 19 Mar 2007 12:37:11 +0000 (UTC)
Message-Id: <20070319123708.GA3483@ws11271.uab.ericsson.se>
Date: Mon, 19 Mar 2007 13:37:08 +0100
From: Karl Knutsson <karl.knutsson@ericsson.com>
Reply-To:
To: gnats-bugs@NetBSD.org
Subject: Byte order problem for SADB_GETSPI in FAST_IPSEC
>Number: 36038
>Category: kern
>Synopsis: Byte order problem for SADB_GETSPI in FAST_IPSEC
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Mar 19 12:40:00 +0000 2007
>Closed-Date: Mon Apr 09 20:25:15 +0000 2007
>Last-Modified: Mon Apr 09 20:25:15 +0000 2007
>Originator: Karl Knutsson <karl.knutsson@ericsson.com>
>Release: NetBSD 3.0
>Organization:
LM Ericsson
>Environment:
System: NetBSD zuul 3.0.0_STABLE NetBSD 3.0.0_STABLE (SPEED) #0: Mon Sep 18 16:59:06 CEST 2006
Architecture: i386
Machine: i386
>Description:
When key_do_getnewspi generates new spis it calls key_checkspidup to verify
that the spi isn't already used. The problem is that it does it when
the spi is in host order (it is converted in key_getspi). This makes it
possible to generate SAs with the same destination, protocol and spi.
>How-To-Repeat:
Send a series of SADB_GETSPI commands with the same protocol and destination
address (should be the address of a local interface) and supply the
SADB_EXT_SPIRANGE extensions with sadb_spirange_min and sadb_spirange_max
set to 9999.
# setkey -D
192.168.0.2 192.168.66.2
esp mode=any spi=9999(0x0000270f) reqid=0(0x00000000)
seq=0x00000000 replay=0 flags=0x00000000 state=larval
sadb_seq=4 pid=103 refcnt=1
192.168.0.2 192.168.66.2
esp mode=any spi=9999(0x0000270f) reqid=0(0x00000000)
seq=0x00000000 replay=0 flags=0x00000000 state=larval
sadb_seq=3 pid=103 refcnt=1
192.168.0.2 192.168.66.2
esp mode=any spi=9999(0x0000270f) reqid=0(0x00000000)
seq=0x00000000 replay=0 flags=0x00000000 state=larval
sadb_seq=2 pid=103 refcnt=1
192.168.0.2 192.168.66.2
esp mode=any spi=9999(0x0000270f) reqid=0(0x00000000)
seq=0x00000000 replay=0 flags=0x00000000 state=larval
sadb_seq=1 pid=103 refcnt=1
192.168.0.2 192.168.66.2
esp mode=any spi=9999(0x0000270f) reqid=0(0x00000000)
seq=0x00000000 replay=0 flags=0x00000000 state=larval
sadb_seq=0 pid=103 refcnt=1
>Fix:
Index: key.c
===================================================================
RCS file: /cvsroot/src/sys/netipsec/key.c,v
retrieving revision 1.23
diff -u -r1.23 key.c
--- key.c 28 Feb 2005 17:47:50 -0000 1.23
+++ key.c 16 Mar 2007 09:09:04 -0000
@@ -4826,7 +4826,7 @@
}
if (min == max) {
- if (key_checkspidup(saidx, min) != NULL) {
+ if (key_checkspidup(saidx, htonl(min)) != NULL) {
ipseclog((LOG_DEBUG, "key_do_getnewspi: SPI %u exists al
ready.\n", min));
return 0;
}
@@ -4844,7 +4844,7 @@
/* generate pseudo-random SPI value ranged. */
newspi = min + (key_random() % (max - min + 1));
- if (key_checkspidup(saidx, newspi) == NULL)
+ if (key_checkspidup(saidx, htonl(newspi)) == NULL)
break;
}
>Release-Note:
>Audit-Trail:
Module Name: src
Committed By: degroote
Date: Wed Mar 21 22:38:34 UTC 2007
Modified Files:
src/sys/netipsec: key.c
src/sys/netkey: key.c
Log Message:
Call key_checkspidup with spi in network bit order in order to make correct
comparaison with spi stored into the sadb.
Reported by Karl Knutsson in kern/36038 .
To generate a diff of this commit:
cvs rdiff -r1.42 -r1.43 src/sys/netipsec/key.c
cvs rdiff -r1.153 -r1.154 src/sys/netkey/key.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: degroote@netbsd.org
State-Changed-When: Mon, 09 Apr 2007 20:25:15 +0000
State-Changed-Why:
Patch was commited. Oked by the reporter by private mail
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.