]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
atm: Revert atm_account_tx() if copy_from_iter_full() fails.
authorKuniyuki Iwashima <kuniyu@google.com>
Mon, 16 Jun 2025 18:21:15 +0000 (11:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:04:20 +0000 (11:04 +0100)
commit 7851263998d4269125fd6cb3fdbfc7c6db853859 upstream.

In vcc_sendmsg(), we account skb->truesize to sk->sk_wmem_alloc by
atm_account_tx().

It is expected to be reverted by atm_pop_raw() later called by
vcc->dev->ops->send(vcc, skb).

However, vcc_sendmsg() misses the same revert when copy_from_iter_full()
fails, and then we will leak a socket.

Let's factorise the revert part as atm_return_tx() and call it in
the failure path.

Note that the corresponding sk_wmem_alloc operation can be found in
alloc_tx() as of the blamed commit.

  $ git blame -L:alloc_tx net/atm/common.c c55fa3cccbc2c~

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Simon Horman <horms@kernel.org>
Closes: https://lore.kernel.org/netdev/20250614161959.GR414686@horms.kernel.org/
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250616182147.963333-3-kuni1840@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/atmdev.h
net/atm/common.c
net/atm/raw.c

index 5d5ff2203fa2209ebc1672f333dd67186ef6a6d1..bc24d19ec2b374584c458544fc8a1682e1942cbe 100644 (file)
@@ -248,6 +248,12 @@ static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
        ATM_SKB(skb)->atm_options = vcc->atm_options;
 }
 
+static inline void atm_return_tx(struct atm_vcc *vcc, struct sk_buff *skb)
+{
+       WARN_ON_ONCE(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize,
+                                          &sk_atm(vcc)->sk_wmem_alloc));
+}
+
 static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
 {
        atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);
index 1cfa9bf1d18713afc7191ddecb256bfb3844154e..930eb302cd10f1f3b346b253af017b68414f8e80 100644 (file)
@@ -635,6 +635,7 @@ int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
 
        skb->dev = NULL; /* for paths shared with net_device interfaces */
        if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
+               atm_return_tx(vcc, skb);
                kfree_skb(skb);
                error = -EFAULT;
                goto out;
index b3ba44aab0ee6c9425fd278ebf8e2df1590a6d7a..b11ef6dccc31440c61c8923d44bcb9efa2c935f4 100644 (file)
@@ -36,7 +36,7 @@ static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
 
        pr_debug("(%d) %d -= %d\n",
                 vcc->vci, sk_wmem_alloc_get(sk), ATM_SKB(skb)->acct_truesize);
-       WARN_ON(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize, &sk->sk_wmem_alloc));
+       atm_return_tx(vcc, skb);
        dev_kfree_skb_any(skb);
        sk->sk_write_space(sk);
 }