linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liu Jian <liujian56@huawei.com>
To: <gregkh@linuxfoundation.org>
Cc: <hamish.martin@alliedtelesis.co.nz>, <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 1/2] driver: uio: fix possible memory leak in __uio_register_device
Date: Wed, 23 Jan 2019 06:45:37 +0800	[thread overview]
Message-ID: <1548197138-352285-2-git-send-email-liujian56@huawei.com> (raw)
In-Reply-To: <1548197138-352285-1-git-send-email-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 b4ae2d9..4d20220 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -941,8 +941,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-22 12:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-22 22:45 [PATCH v2 0/2] fix possible memory leak and use-after-free in __uio_register_device Liu Jian
2019-01-22 22:45 ` Liu Jian [this message]
2019-01-22 22:45 ` [PATCH v2 2/2] driver: uio: fix possible " Liu Jian

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=1548197138-352285-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;
as well as URLs for NNTP newsgroup(s).