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: <1604914097-14999-1-git-send-email-yangtiezhu@loongson.cn>
Date:   Mon,  9 Nov 2020 17:28:17 +0800
From:   Tiezhu Yang <yangtiezhu@...ngson.cn>
To:     Coly Li <colyli@...e.de>,
        Kent Overstreet <kent.overstreet@...il.com>
Cc:     linux-bcache@...r.kernel.org, linux-kernel@...r.kernel.org,
        Xuefeng Li <lixuefeng@...ngson.cn>
Subject: [PATCH] bcache: Fix potential memory leak in register_bcache()

Call kfree() in the error path to free the memory allocated by kzalloc().

Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
---
 drivers/md/bcache/super.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 46a0013..af51574 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -2593,8 +2593,10 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 		ret = register_bdev(sb, sb_disk, bdev, dc);
 		mutex_unlock(&bch_register_lock);
 		/* blkdev_put() will be called in cached_dev_free() */
-		if (ret < 0)
+		if (ret < 0) {
+			kfree(dc);
 			goto out_free_sb;
+		}
 	} else {
 		struct cache *ca = kzalloc(sizeof(*ca), GFP_KERNEL);
 
@@ -2602,8 +2604,10 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
 			goto out_put_sb_page;
 
 		/* blkdev_put() will be called in bch_cache_release() */
-		if (register_cache(sb, sb_disk, bdev, ca) != 0)
+		if (register_cache(sb, sb_disk, bdev, ca) != 0) {
+			kfree(ca);
 			goto out_free_sb;
+		}
 	}
 
 done:
-- 
2.1.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ