Return-Path: Received: from mail-by2nam01on0108.outbound.protection.outlook.com ([104.47.34.108]:47424 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932287AbeARVDz (ORCPT ); Thu, 18 Jan 2018 16:03:55 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Christophe JAILLET , Felipe Balbi , Sasha Levin Subject: [added to the 4.1 stable tree] USB: gadgetfs: Fix a potential memory leak in 'dev_config()' Date: Thu, 18 Jan 2018 21:00:56 +0000 Message-ID: <20180118205908.3220-173-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Christophe JAILLET This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit b6e7aeeaf235901c42ec35de4633c7c69501d303 ] '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 Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- 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 63d71400dcaf..ada2a4f5a774 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -1834,8 +1834,10 @@ dev_config (struct file *fd, const char __user *buf,= size_t len, loff_t *ptr) =20 spin_lock_irq (&dev->lock); value =3D -EINVAL; - if (dev->buf) + if (dev->buf) { + kfree(kbuf); goto fail; + } dev->buf =3D kbuf; =20 /* full or low speed config */ --=20 2.11.0