Skip to contentSkip to conversation

lightnvm: fix memory leak

PATCH Superseded Sudip Mukherjee 2 participants 4 messages Nov 23, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lightnvm: fix memory leak

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

---
 drivers/lightnvm/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/lightnvm/core.c +4 -1
index f659e60..6688b60 100644
@@ -721,8 +721,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;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 16 lines · Sudip Mukherjee

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

---
  drivers/lightnvm/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/lightnvm/core.c +0 -0
index f659e60..6688b60 100644
@@ -721,8 +721,11 @@ static long nvm_ioctl_get_devices(struct file *file, void __user *arg)
 
  	devices->nr_devices = i;

drivers/lightnvm/core.c static long nvm_ioctl_get_devices(struct file *file, void __user *arg) · line 731

Quoted 10 lines
drivers/lightnvm/core.c +4 -1
 
-	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;

Thanks Sudip, it seems like this error is in some of the others ioctl's as well. Do you want to send a patch with the fixes for them all?

#2 lore raw
Quoted 24 lines · Matias Bjørling
Quoted 23 lines · Sudip Mukherjee

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

---
 drivers/lightnvm/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/lightnvm/core.c +4 -1
index f659e60..6688b60 100644
@@ -721,8 +721,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;
+	}
 
Quoted 7 lines

drivers/lightnvm/core.c static long nvm_ioctl_get_devices(struct file *file, void __user *arg) · line 731

Quoted 3 lines
drivers/lightnvm/core.c +0 -0
 	kfree(devices);
 	return 0;

Thanks Sudip, it seems like this error is in some of the others ioctl's as well. Do you want to send a patch with the fixes for them all?

I can find a similar error in nvm_ioctl_info(). I will have a close look tomorrow and send a patch. Is this patch applied or should I send a combined patch fixing all these similar errors?

regards
sudip

#3 lore raw
Quoted 25 lines · Sudip Mukherjee
Quoted 24 lines · Matias Bjørling
Quoted 23 lines · Sudip Mukherjee

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

---
  drivers/lightnvm/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/lightnvm/core.c +4 -1
index f659e60..6688b60 100644
@@ -721,8 +721,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;
+	}
 
Quoted 7 lines
Quoted 7 lines

drivers/lightnvm/core.c static long nvm_ioctl_get_devices(struct file *file, void __user *arg) · line 731

Quoted 3 lines
drivers/lightnvm/core.c +0 -0
  	kfree(devices);
  	return 0;

Thanks Sudip, it seems like this error is in some of the others ioctl's as well. Do you want to send a patch with the fixes for them all?

Sure, That'll be great. Then I'll apply it.

Quoted 4 lines

I can find a similar error in nvm_ioctl_info(). I will have a close look tomorrow and send a patch. Is this patch applied or should I send a combined patch fixing all these similar errors?

A combined will be great. It fixes the same type of error. Thank you.