mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Jian <liujian56@huawei.com>
To: <gregkh@linuxfoundation.org>, <hamish.martin@alliedtelesis.co.nz>
Cc: <liujian56@huawei.com>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/2] driver: uio: fix possible memory leak in __uio_register_device
Date: Tue, 8 Jan 2019 21:01:47 +0800	[thread overview]
Message-ID: <1546952508-186003-2-git-send-email-liujian56@huawei.com> (raw)
In-Reply-To: <1546952508-186003-1-git-send-email-liujian56@huawei.com>

From: liujian <liujian56@huawei.com>

'idev' is malloced in __uio_register_device() and leak free it before
leaving from the uio_get_minor() error handing case, it will cause
memory leak.

Fixes: a93e7b331568 ("uio: Prevent device destruction while fds are open")
Signed-off-by: Liu Jian <liujian56@huawei.com>
Reviewed-by: Hamish Martin <hamish.martin@alliedtelesis.co.nz>
---
 drivers/uio/uio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 1313422..7280552 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -940,8 +940,10 @@ int __uio_register_device(struct module *owner,
 	atomic_set(&idev->event, 0);
 
 	ret = uio_get_minor(idev);
-	if (ret)
+	if (ret) {
+		kfree(idev);
 		return ret;
+	}
 
 	idev->dev.devt = MKDEV(uio_major, idev->minor);
 	idev->dev.class = &uio_class;
-- 
2.7.4


  reply	other threads:[~2019-01-08  3:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-08 13:01 [PATCH 0/2] fix possible memory leak and use-after-free " Liu Jian
2019-01-08 13:01 ` Liu Jian [this message]
2019-01-22 11:00   ` [PATCH 1/2] driver: uio: fix possible memory leak " Greg KH
2019-01-08 13:01 ` [PATCH 2/2] driver: uio: fix possible use-after-free " Liu Jian
2019-01-22 11:00   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1546952508-186003-2-git-send-email-liujian56@huawei.com \
    --to=liujian56@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hamish.martin@alliedtelesis.co.nz \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®