UPSTREAM: ipv6: raw: Deduct extension header length in rawv6_push_pending_frames
authorHerbert Xu <herbert@gondor.apana.org.au>
Tue, 10 Jan 2023 00:59:06 +0000 (08:59 +0800)
committerGreg Kroah-Hartman <gregkh@google.com>
Wed, 18 Jan 2023 11:48:41 +0000 (11:48 +0000)
commit cb3e9864cdbe35ff6378966660edbcbac955fe17 upstream.

The total cork length created by ip6_append_data includes extension
headers, so we must exclude them when comparing them against the
IPV6_CHECKSUM offset which does not include extension headers.

Reported-by: Kyle Zeng <zengyhkyle@gmail.com>
Fixes: 357b40a18b04 ("[IPV6]: IPV6_CHECKSUM socket option can corrupt kernel memory")
Change-Id: I73cf556998cab122229e1a361d186925775aad61
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 35ed8ba485544a31a4ab9b92a1c68e406ab66a47)
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
net/ipv6/raw.c

index f3caf952d172d816b8b4cb135db7dd8cb82aa6a0..a91e643162bf9fcc447df49710d11028b5ce2a4c 100644 (file)
@@ -539,6 +539,7 @@ csum_copy_err:
 static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
                                     struct raw6_sock *rp)
 {
+       struct ipv6_txoptions *opt;
        struct sk_buff *skb;
        int err = 0;
        int offset;
@@ -556,6 +557,9 @@ static int rawv6_push_pending_frames(struct sock *sk, struct flowi6 *fl6,
 
        offset = rp->offset;
        total_len = inet_sk(sk)->cork.base.length;
+       opt = inet6_sk(sk)->cork.opt;
+       total_len -= opt ? opt->opt_flen : 0;
+
        if (offset >= total_len - 1) {
                err = -EINVAL;
                ip6_flush_pending_frames(sk);