lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1421169557-18549-1-git-send-email-sudipm.mukherjee@gmail.com>
Date:	Tue, 13 Jan 2015 22:49:17 +0530
From:	Sudip Mukherjee <sudipm.mukherjee@...il.com>
To:	Paul Clements <Paul.Clements@...eleye.com>
Cc:	Sudip Mukherjee <sudipm.mukherjee@...il.com>,
	nbd-general@...ts.sourceforge.net, linux-kernel@...r.kernel.org
Subject: [PATCH] nbd: fix possible memory leak

we have already allocated memory for nbd_dev, but we were not
releasing that memory and just returning the error value.

Signed-off-by: Sudip Mukherjee <sudip@...torindia.org>
---

Hi Paul,
after seeing your mail about maintainers, just started to see the code.
this patch is one way, another way can be to bring the kcalloc part below these checks. 

 drivers/block/nbd.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4bc2a5c..13ea239 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -822,11 +822,15 @@ static int __init nbd_init(void)
 		max_part = (1UL << part_shift) - 1;
 	}
 
-	if ((1UL << part_shift) > DISK_MAX_PARTS)
-		return -EINVAL;
+	if ((1UL << part_shift) > DISK_MAX_PARTS) {
+		err = -EINVAL;
+		goto out_free;
+	}
 
-	if (nbds_max > 1UL << (MINORBITS - part_shift))
-		return -EINVAL;
+	if (nbds_max > 1UL << (MINORBITS - part_shift)) {
+		err = -EINVAL;
+		goto out_free;
+	}
 
 	for (i = 0; i < nbds_max; i++) {
 		struct gendisk *disk = alloc_disk(1 << part_shift);
@@ -889,6 +893,7 @@ out:
 		blk_cleanup_queue(nbd_dev[i].disk->queue);
 		put_disk(nbd_dev[i].disk);
 	}
+out_free:
 	kfree(nbd_dev);
 	return err;
 }
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ