Skip to contentSkip to conversation

: Avoid u16 checksum coverage wrap-around

PATCH In review Gerrit Renker 2 participants 3 messages Jul 3, 2008 – Jul 7, 2008

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : Avoid u16 checksum coverage wrap-around

udplite: Protection against coverage value wrap-around

This protects UDP-Lite against illegal checksum coverage values and against illegal checksum coverage values caused by the `int' argument wrapping around at 0xffff.

---
 Documentation/networking/udplite.txt |   12 ++++--------
 include/net/udplite.h                |    6 ++++++
 net/ipv4/udp.c                       |    8 ++++----
 3 files changed, 14 insertions(+), 12 deletions(-)
include/net/udplite.h +6 -0
@@ -29,6 +29,12 @@ static inline int udplite_sk_init(struct sock *sk)
 	return 0;
 }
 
+/* Values between 1..7 are invalid. IPv6 jumbograms are not supported (3.5) */
+static inline bool udplite_valid_cscov(const u32 cscov)
+{
+	return cscov == 0 || (cscov >= 8 && cscov <= USHORT_MAX);
+}
+
 /*
  * 	Checksumming routines
  */
net/ipv4/udp.c +4 -4
@@ -1317,8 +1317,8 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
 	case UDPLITE_SEND_CSCOV:
 		if (!is_udplite)         /* Disable the option on UDP sockets */
 			return -ENOPROTOOPT;
-		if (val != 0 && val < 8) /* Illegal coverage: use default (8) */
-			val = 8;
+		if (!udplite_valid_cscov(val))
+			return -EINVAL;
 		up->pcslen = val;
 		up->pcflag |= UDPLITE_SEND_CC;
 		break;
@@ -1329,8 +1329,8 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
 	case UDPLITE_RECV_CSCOV:
 		if (!is_udplite)         /* Disable the option on UDP sockets */
 			return -ENOPROTOOPT;
-		if (val != 0 && val < 8) /* Avoid silly minimal values.       */
-			val = 8;
+		if (!udplite_valid_cscov(val))
+			return -EINVAL;
 		up->pcrlen = val;
 		up->pcflag |= UDPLITE_RECV_CC;
 		break;
Documentation/networking/udplite.txt +4 -8
@@ -118,10 +118,9 @@
 
   If the sender specifies a value of 0 as coverage length, the module
   assumes full coverage, transmits a packet with coverage length of 0
-  and according checksum.  If the sender specifies a coverage < 8 and
-  different from 0, the kernel assumes 8 as default value.  Finally,
-  if the specified coverage length exceeds the packet length, the packet
-  length is used instead as coverage length.
+  and according checksum. Values between 1..7 and greater than 65535 are
+  invalid. Finally, if the specified coverage length exceeds the packet 
+  length, the packet length is used instead as coverage length.
 
   2) Receiver Socket Options
 
@@ -130,9 +129,6 @@
   always wants the whole of the packet covered. In this case, all
   partially covered packets are dropped and an error is logged.
 
-  It is not possible to specify illegal values (<0 and <8); in these
-  cases the default of 8 is assumed.
-
   All packets arriving with a coverage value less than the specified
   threshold are discarded, these events are also logged.
 
@@ -148,7 +144,7 @@
         getsockopt(sockfd, SOL_SOCKET, SO_NO_CHECK, &value, ...);
 
   is meaningless (as in TCP). Packets with a zero checksum field are
-  illegal (cf. RFC 3828, sec. 3.1) will be silently discarded.
+  illegal (cf. RFC 3828, sec. 3.1) and will be silently discarded.
 
   4) Fragmentation
 
maintainer
#1 lore raw

From: Gerrit Renker <[email protected]>
Date: Thu, 3 Jul 2008 12:31:41 +0100

Quoted 7 lines

udplite: Protection against coverage value wrap-around

This protects UDP-Lite against illegal checksum coverage values and against illegal checksum coverage values caused by the `int' argument wrapping around at 0xffff.

Please preserve the current of using the default value of "8" when an illegal value is specified. This behavior might be important and specified somewhere, such as the BSD socket API for udplite used on other systems. The fact that it's even explicitly mentioned in the documentation file is a strong indication that it might be that way for a good reason.

Also, even if we should change the behvaior, it's a seperate change from correcting the test.

Gerrit, you like to mix up multiple things at the same time and it makes your stuff harder to review. It also, as a result, makes it take longer to integrate your work.

#2 lore raw
| > udplite: Protection against coverage value wrap-around
| > 
| > This protects UDP-Lite against illegal checksum coverage values and
| > against illegal checksum coverage values caused by the `int' argument
| > wrapping around at 0xffff.
| > 
| > Signed-off-by: Gerrit Renker <[email protected]>
| 
| Please preserve the current of using the default value of "8" when an
| illegal value is specified.  This behavior might be important and
| specified somewhere, such as the BSD socket API for udplite used on
| other systems.  The fact that it's even explicitly mentioned in the
| documentation file is a strong indication that it might be that way
| for a good reason.
| 

Can I just clarify illegal checksum values, as there are two different cases:

(a) Values between 1..7
The specification marks these as illegal in RFC 3828, sec. 3.1. The Linux UDP-Lite API allowed the user to get away with these illegal coverage values and documented this fact in udplite.txt. Since I am guilty of having written this file, I can add that I am not aware that the same behaviour is specified in another place -- other than RFC 3828.

(b) Values greater than 0xFFFF
The UDP-Lite checksum coverage field has the same u16 size as the UDP Length field but, in contrast, IPv6 jumbograms are not supported (RFC 3828, 3.5). This means that checksum coverage values greater than 65535 are undefined.
Since the internal field is u16 and since the setsockopt() argument is `int', there is a need to protect against this range, not only since the wrap-around can again cause values in the range 1..7.

Can you and/or other people please provide input what to do API-wise in the two above cases, since this information is needed for the manpage also?

These options come to mind:

(1) Keep behaviour for (a), return EINVAL for (b).
(2) Keep behaviour for (a) and silently ignore values > 0xffff by replacing these with "full coverage" (0) - problematic if negative values were supplied.
(3) Return EINVAL in both cases (as sketched by the patch).
(4) Other alternative?

| Gerrit, you like to mix up multiple things at the same time and it
| makes your stuff harder to review.  It also, as a result, makes it
| take longer to integrate your work.

You have a point here. I think I will have to work more with asking how things should best be done rather than by sending patches.

However, as other people who I work with will be able to confirm, there is in general a lot of effort being put in to make cooperative work easy.