diff mbox series

[net] inet_ecn: Fix endianness of checksum update when setting ECT(1)

Message ID 20201130183705.17540-1-toke@redhat.com (mailing list archive)
State Accepted
Delegated to: Netdev Maintainers
Headers show
Series [net] inet_ecn: Fix endianness of checksum update when setting ECT(1) | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 2269 this patch: 2269
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: From:/Signed-off-by: email name mismatch: 'From: "Toke Høiland-Jørgensen" <toke@redhat.com>' != 'Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>'
netdev/build_allmodconfig_warn success Errors and warnings before: 2303 this patch: 2303
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Toke Høiland-Jørgensen Nov. 30, 2020, 6:37 p.m. UTC
When adding support for propagating ECT(1) marking in IP headers it seems I
suffered from endianness-confusion in the checksum update calculation: In
fact the ECN field is in the *lower* bits of the first 16-bit word of the
IP header when calculating in network byte order. This means that the
addition performed to update the checksum field was wrong; let's fix that.

Fixes: b723748750ec ("tunnel: Propagate ECT(1) when decapsulating as recommended by RFC6040")
Reported-by: Jonathan Morton <chromatix99@gmail.com>
Tested-by: Pete Heist <pete@heistp.net>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 include/net/inet_ecn.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski Dec. 2, 2020, 1:24 a.m. UTC | #1
On Mon, 30 Nov 2020 19:37:05 +0100 Toke Høiland-Jørgensen wrote:
> When adding support for propagating ECT(1) marking in IP headers it seems I
> suffered from endianness-confusion in the checksum update calculation: In
> fact the ECN field is in the *lower* bits of the first 16-bit word of the
> IP header when calculating in network byte order. This means that the
> addition performed to update the checksum field was wrong; let's fix that.
> 
> Fixes: b723748750ec ("tunnel: Propagate ECT(1) when decapsulating as recommended by RFC6040")
> Reported-by: Jonathan Morton <chromatix99@gmail.com>
> Tested-by: Pete Heist <pete@heistp.net>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>

Applied and queued, thanks!

> diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
> index e1eaf1780288..563457fec557 100644
> --- a/include/net/inet_ecn.h
> +++ b/include/net/inet_ecn.h
> @@ -107,7 +107,7 @@ static inline int IP_ECN_set_ect1(struct iphdr *iph)
>  	if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
>  		return 0;
>  
> -	check += (__force u16)htons(0x100);
> +	check += (__force u16)htons(0x1);
>  
>  	iph->check = (__force __sum16)(check + (check>=0xFFFF));
>  	iph->tos ^= INET_ECN_MASK;

This seems to be open coding csum16_add() - is there a reason and if
not perhaps worth following up in net-next?
Toke Høiland-Jørgensen Dec. 2, 2020, 10:07 a.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> writes:

> On Mon, 30 Nov 2020 19:37:05 +0100 Toke Høiland-Jørgensen wrote:
>> When adding support for propagating ECT(1) marking in IP headers it seems I
>> suffered from endianness-confusion in the checksum update calculation: In
>> fact the ECN field is in the *lower* bits of the first 16-bit word of the
>> IP header when calculating in network byte order. This means that the
>> addition performed to update the checksum field was wrong; let's fix that.
>> 
>> Fixes: b723748750ec ("tunnel: Propagate ECT(1) when decapsulating as recommended by RFC6040")
>> Reported-by: Jonathan Morton <chromatix99@gmail.com>
>> Tested-by: Pete Heist <pete@heistp.net>
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>
> Applied and queued, thanks!
>
>> diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
>> index e1eaf1780288..563457fec557 100644
>> --- a/include/net/inet_ecn.h
>> +++ b/include/net/inet_ecn.h
>> @@ -107,7 +107,7 @@ static inline int IP_ECN_set_ect1(struct iphdr *iph)
>>  	if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
>>  		return 0;
>>  
>> -	check += (__force u16)htons(0x100);
>> +	check += (__force u16)htons(0x1);
>>  
>>  	iph->check = (__force __sum16)(check + (check>=0xFFFF));
>>  	iph->tos ^= INET_ECN_MASK;
>
> This seems to be open coding csum16_add() - is there a reason and if
> not perhaps worth following up in net-next?

Hmm, good point. I think I originally just copied this from
IP_ECN_set_ce(), which comes all the way back from the initial
Linux-2.6.12-rc2 commit in git. So I suppose it may just predate the
csum helpers? I'll wait for this patch to get propagated to net-next,
then follow up with a fix there :)

-Toke
diff mbox series

Patch

diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h
index e1eaf1780288..563457fec557 100644
--- a/include/net/inet_ecn.h
+++ b/include/net/inet_ecn.h
@@ -107,7 +107,7 @@  static inline int IP_ECN_set_ect1(struct iphdr *iph)
 	if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
 		return 0;
 
-	check += (__force u16)htons(0x100);
+	check += (__force u16)htons(0x1);
 
 	iph->check = (__force __sum16)(check + (check>=0xFFFF));
 	iph->tos ^= INET_ECN_MASK;