Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1276447

[PATCH 4/5] lightnvm: fix ioctl memory leaks

From Matias Bjørling <m@bjorling.me>
Newsgroups linux.kernel
Subject [PATCH 4/5] lightnvm: fix ioctl memory leaks
Date 2015-11-24 14:30 +0100
Message-ID <qylPt-cQ-35@gated-at.bofh.it> (permalink)
References <qylPs-cQ-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Sudip Mukherjee <sudipm.mukherjee@gmail.com>

If copy_to_user() fails we returned error but we missed releasing
devices.

Signed-off-by: Sudip Mukherjee <sudip@vectorindia.org>
Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/lightnvm/core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 5178645..ea50fa5 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -680,8 +680,10 @@ static long nvm_ioctl_info(struct file *file, void __user *arg)
 	info->tgtsize = tgt_iter;
 	up_write(&nvm_lock);
 
-	if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info)))
+	if (copy_to_user(arg, info, sizeof(struct nvm_ioctl_info))) {
+		kfree(info);
 		return -EFAULT;
+	}
 
 	kfree(info);
 	return 0;
@@ -724,8 +726,11 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
 
 	devices->nr_devices = i;
 
-	if (copy_to_user(arg, devices, sizeof(struct nvm_ioctl_get_devices)))
+	if (copy_to_user(arg, devices,
+			 sizeof(struct nvm_ioctl_get_devices))) {
+		kfree(devices);
 		return -EFAULT;
+	}
 
 	kfree(devices);
 	return 0;
-- 
2.1.4

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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/5] LightNVM fixes Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100
  [PATCH 1/5] lightnvm: change vendor and dev id for qemu Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100
    RE: [PATCH 1/5] lightnvm: change vendor and dev id for qemu "Elliott, Robert (Persistent Memory)" <elliott@hpe.com> - 2015-11-24 17:00 +0100
      Re: [PATCH 1/5] lightnvm: change vendor and dev id for qemu Matias Bjørling <m@bjorling.me> - 2015-11-24 19:30 +0100
        Re: [PATCH 1/5] lightnvm: change vendor and dev id for qemu Jens Axboe <axboe@fb.com> - 2015-11-24 23:30 +0100
  [PATCH 2/5] lightnvm: Simplify config when disabled Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100
  [PATCH 5/5] lightnvm: do device max sectors boundary check first Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100
  [PATCH 4/5] lightnvm: fix ioctl memory leaks Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100
  [PATCH 3/5] lightnvm: free memory when gennvm register fails Matias Bjørling <m@bjorling.me> - 2015-11-24 14:30 +0100

csiph-web