Skip to content

Commit 62dba28

Browse files
q2venkuba-moo
authored andcommitted
atm: clip: Fix memory leak of struct clip_vcc.
ioctl(ATMARP_MKIP) allocates struct clip_vcc and set it to vcc->user_back. The code assumes that vcc_destroy_socket() passes NULL skb to vcc->push() when the socket is close()d, and then clip_push() frees clip_vcc. However, ioctl(ATMARPD_CTRL) sets NULL to vcc->push() in atm_init_atmarp(), resulting in memory leak. Let's serialise two ioctl() by lock_sock() and check vcc->push() in atm_init_atmarp() to prevent memleak. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 706cc36 commit 62dba28

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

net/atm/clip.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,9 @@ static struct atm_dev atmarpd_dev = {
645645

646646
static int atm_init_atmarp(struct atm_vcc *vcc)
647647
{
648+
if (vcc->push == clip_push)
649+
return -EINVAL;
650+
648651
mutex_lock(&atmarpd_lock);
649652
if (atmarpd) {
650653
mutex_unlock(&atmarpd_lock);
@@ -669,6 +672,7 @@ static int atm_init_atmarp(struct atm_vcc *vcc)
669672
static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
670673
{
671674
struct atm_vcc *vcc = ATM_SD(sock);
675+
struct sock *sk = sock->sk;
672676
int err = 0;
673677

674678
switch (cmd) {
@@ -689,14 +693,18 @@ static int clip_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
689693
err = clip_create(arg);
690694
break;
691695
case ATMARPD_CTRL:
696+
lock_sock(sk);
692697
err = atm_init_atmarp(vcc);
693698
if (!err) {
694699
sock->state = SS_CONNECTED;
695700
__module_get(THIS_MODULE);
696701
}
702+
release_sock(sk);
697703
break;
698704
case ATMARP_MKIP:
705+
lock_sock(sk);
699706
err = clip_mkip(vcc, arg);
707+
release_sock(sk);
700708
break;
701709
case ATMARP_SETENTRY:
702710
err = clip_setentry(vcc, (__force __be32)arg);

0 commit comments

Comments
 (0)