Skip to contentSkip to conversation

ip: fix csum_sub() with csum_block_sub()

PATCH In review Cong Wang 2 participants 3 messages Nov 9, 2018

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 ip: fix csum_sub() with csum_block_sub()

When subtracting the checksum of a block of data, csum_block_sub() must be used to respect the offset.

We learned this lesson from both commit d55bef5059dd
("net: fix pskb_trim_rcsum_slow() with odd trim offset") and commit d48051c5b837 ("net/mlx5e: fix csum adjustments caused by RXFCS").

Fixes ca4ef4574f1e ("ip: fix IP_CHECKSUM handling")
Cc Paolo Abeni <[email protected]>
Cc Eric Dumazet <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/ip_sockglue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv4/ip_sockglue.c +4 -1
index fffcc130900e..0d69f0823c08 100644
@@ -122,7 +122,10 @@ static void ip_cmsg_recv_checksum(struct msghdr *msg, struct sk_buff *skb,
 
 	if (offset != 0) {
 		int tend_off = skb_transport_offset(skb) + tlen;
-		csum = csum_sub(csum, skb_checksum(skb, tend_off, offset, 0));
+
+		csum = csum_block_sub(csum,
+				      skb_checksum(skb, tend_off, offset, 0),
+				      tend_off);
 	}
 
 	put_cmsg(msg, SOL_IP, IP_CHECKSUM, sizeof(__wsum), &csum);
Signature · 1 line
2.19.1
#1 lore raw
Quoted 9 lines · Cong Wang

When subtracting the checksum of a block of data, csum_block_sub() must be used to respect the offset.

We learned this lesson from both commit d55bef5059dd
("net: fix pskb_trim_rcsum_slow() with odd trim offset") and commit d48051c5b837 ("net/mlx5e: fix csum adjustments caused by RXFCS").

Fixes ca4ef4574f1e ("ip: fix IP_CHECKSUM handling")

I do not believe you fix any bug here...

I do not know of any inet protocol having odd header sizes.

author
#2 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 8 lines · Cong Wang

When subtracting the checksum of a block of data, csum_block_sub() must be used to respect the offset.

We learned this lesson from both commit d55bef5059dd
("net: fix pskb_trim_rcsum_slow() with odd trim offset") and commit d48051c5b837 ("net/mlx5e: fix csum adjustments caused by RXFCS").

Quoted 5 lines
Quoted 1 line
Fixes ca4ef4574f1e ("ip: fix IP_CHECKSUM handling")

I do not believe you fix any bug here...

I do not know of any inet protocol having odd header sizes.

That offset is payload offset, but yeah, the payload offset must be aligned some way. Good point!

Let's drop it.