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]>
Signed-off-by: Cong Wang <[email protected]>
---
 net/ipv4/ip_sockglue.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index fffcc130900e..0d69f0823c08 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -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);
-- 
2.19.1

Reply via email to