summaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorKuniyuki Iwashima <kuniyu@amazon.com>2023-02-09 16:22:01 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-02-22 12:47:21 +0100
commit28a1742fcc1d8692e9090864373aa77fb3a0c8fd (patch)
tree37a235964438b1ac50a17744c9cc380af1d5c836 /include/net
parent977bafe3a4e1c734a5d36007b4ba27529d4a682a (diff)
downloadlinux-stable-28a1742fcc1d8692e9090864373aa77fb3a0c8fd.tar.gz
linux-stable-28a1742fcc1d8692e9090864373aa77fb3a0c8fd.tar.bz2
linux-stable-28a1742fcc1d8692e9090864373aa77fb3a0c8fd.zip
dccp/tcp: Avoid negative sk_forward_alloc by ipv6_pinfo.pktoptions.
commit ca43ccf41224b023fc290073d5603a755fd12eed upstream. Eric Dumazet pointed out [0] that when we call skb_set_owner_r() for ipv6_pinfo.pktoptions, sk_rmem_schedule() has not been called, resulting in a negative sk_forward_alloc. We add a new helper which clones a skb and sets its owner only when sk_rmem_schedule() succeeds. Note that we move skb_set_owner_r() forward in (dccp|tcp)_v6_do_rcv() because tcp_send_synack() can make sk_forward_alloc negative before ipv6_opt_accepted() in the crossed SYN-ACK or self-connect() cases. [0]: https://lore.kernel.org/netdev/CANn89iK9oc20Jdi_41jb9URdF210r7d1Y-+uypbMSbOfY6jqrg@mail.gmail.com/ Fixes: 323fbd0edf3f ("net: dccp: Add handling of IPV6_PKTOPTIONS to dccp_v6_do_rcv()") Fixes: 3df80d9320bc ("[DCCP]: Introduce DCCPv6") Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/net')
-rw-r--r--include/net/sock.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/net/sock.h b/include/net/sock.h
index 30315a03b4ab..9eb656683281 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2134,6 +2134,19 @@ static inline void skb_set_owner_r(struct sk_buff *skb, struct sock *sk)
sk_mem_charge(sk, skb->truesize);
}
+static inline struct sk_buff *skb_clone_and_charge_r(struct sk_buff *skb, struct sock *sk)
+{
+ skb = skb_clone(skb, sk_gfp_mask(sk, GFP_ATOMIC));
+ if (skb) {
+ if (sk_rmem_schedule(sk, skb, skb->truesize)) {
+ skb_set_owner_r(skb, sk);
+ return skb;
+ }
+ __kfree_skb(skb);
+ }
+ return NULL;
+}
+
void sk_reset_timer(struct sock *sk, struct timer_list *timer,
unsigned long expires);