]> git.baikalelectronics.ru Git - kernel.git/commitdiff
USB: gadgetfs: Fix a potential memory leak in 'dev_config()'
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Tue, 21 Feb 2017 21:33:11 +0000 (22:33 +0100)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 6 Mar 2017 14:54:45 +0000 (16:54 +0200)
'kbuf' is allocated just a few lines above using 'memdup_user()'.
If the 'if (dev->buf)' test fails, this memory is never released.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/gadget/legacy/inode.c

index a2615d64d07c1967d7cd2c25ab2e046747f6bd7d..0513dfa008e63746045330b4ea40fda1cfb54b8d 100644 (file)
@@ -1782,8 +1782,10 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
 
        spin_lock_irq (&dev->lock);
        value = -EINVAL;
-       if (dev->buf)
+       if (dev->buf) {
+               kfree(kbuf);
                goto fail;
+       }
        dev->buf = kbuf;
 
        /* full or low speed config */