Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1585761 > unrolled thread

[PATCH] USB: gadgetfs: Fix a potential memory leak in 'dev_config()'

Started byChristophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2017-02-21 22:50 +0100
Last post2017-02-21 22:50 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] USB: gadgetfs: Fix a potential memory leak in 'dev_config()' Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-02-21 22:50 +0100

#1585761 — [PATCH] USB: gadgetfs: Fix a potential memory leak in 'dev_config()'

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2017-02-21 22:50 +0100
Subject[PATCH] USB: gadgetfs: Fix a potential memory leak in 'dev_config()'
Message-ID<tdqtP-8mV-7@gated-at.bofh.it>
'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>
---
 drivers/usb/gadget/legacy/inode.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c
index 79a2d8fba6b6..a2c916869293 100644
--- a/drivers/usb/gadget/legacy/inode.c
+++ b/drivers/usb/gadget/legacy/inode.c
@@ -1781,8 +1781,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 */
-- 
2.9.3

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web