sctp: get sctphdr by offset in sctp_compute_cksum [Linux 3.16.72]

This Linux kernel change "sctp: get sctphdr by offset in sctp_compute_cksum" is included in the Linux 3.16.72 release. This change is authored by Xin Long <lucien.xin [at] gmail.com> on Mon Mar 18 19:47:00 2019 +0800. The commit for this change in Linux stable tree is 3ef66b6 (patch) which is from upstream commit 273160f. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 273160f.

sctp: get sctphdr by offset in sctp_compute_cksum

commit 273160ffc6b993c7c91627f5a84799c66dfe4dee upstream.

sctp_hdr(skb) only works when skb->transport_header is set properly.

But in Netfilter, skb->transport_header for ipv6 is not guaranteed
to be right value for sctphdr. It would cause to fail to check the
checksum for sctp packets.

So fix it by using offset, which is always right in all places.

v1->v2:
  - Fix the changelog.

Fixes: e6d8b64b34aa ("net: sctp: fix and consolidate SCTP checksumming code")
Reported-by: Li Shuang <[email protected]>
Signed-off-by: Xin Long <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Ben Hutchings <[email protected]>

There are 2 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 include/net/sctp/checksum.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
index 32ee65a..1c6e6c0 100644
--- a/include/net/sctp/checksum.h
+++ b/include/net/sctp/checksum.h
@@ -61,7 +61,7 @@ static inline __wsum sctp_csum_combine(__wsum csum, __wsum csum2,
 static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
                    unsigned int offset)
 {
-   struct sctphdr *sh = sctp_hdr(skb);
+   struct sctphdr *sh = (struct sctphdr *)(skb->data + offset);
    const struct skb_checksum_ops ops = {
        .update  = sctp_csum_update,
        .combine = sctp_csum_combine,

Leave a Reply

Your email address will not be published. Required fields are marked *