Skip to content

Commit e25696f

Browse files
q2venpopcornmix
authored andcommitted
atm: Revert atm_account_tx() if copy_from_iter_full() fails.
commit 7851263 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 c55fa3c~ Fixes: 1da177e ("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>
1 parent 69a5f46 commit e25696f

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

include/linux/atmdev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,12 @@ static inline void atm_account_tx(struct atm_vcc *vcc, struct sk_buff *skb)
249249
ATM_SKB(skb)->atm_options = vcc->atm_options;
250250
}
251251

252+
static inline void atm_return_tx(struct atm_vcc *vcc, struct sk_buff *skb)
253+
{
254+
WARN_ON_ONCE(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize,
255+
&sk_atm(vcc)->sk_wmem_alloc));
256+
}
257+
252258
static inline void atm_force_charge(struct atm_vcc *vcc,int truesize)
253259
{
254260
atomic_add(truesize, &sk_atm(vcc)->sk_rmem_alloc);

net/atm/common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ int vcc_sendmsg(struct socket *sock, struct msghdr *m, size_t size)
635635

636636
skb->dev = NULL; /* for paths shared with net_device interfaces */
637637
if (!copy_from_iter_full(skb_put(skb, size), size, &m->msg_iter)) {
638+
atm_return_tx(vcc, skb);
638639
kfree_skb(skb);
639640
error = -EFAULT;
640641
goto out;

net/atm/raw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static void atm_pop_raw(struct atm_vcc *vcc, struct sk_buff *skb)
3636

3737
pr_debug("(%d) %d -= %d\n",
3838
vcc->vci, sk_wmem_alloc_get(sk), ATM_SKB(skb)->acct_truesize);
39-
WARN_ON(refcount_sub_and_test(ATM_SKB(skb)->acct_truesize, &sk->sk_wmem_alloc));
39+
atm_return_tx(vcc, skb);
4040
dev_kfree_skb_any(skb);
4141
sk->sk_write_space(sk);
4242
}

0 commit comments

Comments
 (0)