diff mbox

[2/2] efi_runtime: handle memory errors when setting variables

Message ID 1423687393-7810-3-git-send-email-ricardo.neri-calderon@linux.intel.com
State Accepted
Headers show

Commit Message

Ricardo Neri Feb. 11, 2015, 8:43 p.m. UTC
If the allocation of data fails, we must not proceed copying data
from the user space. Instead we return with -ENOMEM.

Also, while there, free the memory of the variable name in case
the copy from user space fails.

Reported-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
 efi_runtime/efi_runtime.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Colin Ian King Feb. 11, 2015, 8:47 p.m. UTC | #1
On 11/02/15 20:43, Ricardo Neri wrote:
> If the allocation of data fails, we must not proceed copying data
> from the user space. Instead we return with -ENOMEM.
> 
> Also, while there, free the memory of the variable name in case
> the copy from user space fails.
> 
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> ---
>  efi_runtime/efi_runtime.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index 1125556..9693721 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -300,8 +300,13 @@ static long efi_runtime_set_variable(unsigned long arg)
>  		return rv;
>  
>  	data = kmalloc(psetvariable_local.DataSize, GFP_KERNEL);
> +	if (!data) {
> +		kfree(name);
> +		return -ENOMEM;
> +	}
>  	if (copy_from_user(data, psetvariable_local.Data,
>  			   psetvariable_local.DataSize)) {
> +		kfree(data);
>  		kfree(name);
>  		return -EFAULT;
>  	}
> 
Thanks!

Acked-by: Colin Ian King <colin.king@canonical.com>
Alex Hung March 2, 2015, 2:54 a.m. UTC | #2
On 02/12/2015 04:43 AM, Ricardo Neri wrote:
> If the allocation of data fails, we must not proceed copying data
> from the user space. Instead we return with -ENOMEM.
> 
> Also, while there, free the memory of the variable name in case
> the copy from user space fails.
> 
> Reported-by: Colin Ian King <colin.king@canonical.com>
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> ---
>  efi_runtime/efi_runtime.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
> index 1125556..9693721 100644
> --- a/efi_runtime/efi_runtime.c
> +++ b/efi_runtime/efi_runtime.c
> @@ -300,8 +300,13 @@ static long efi_runtime_set_variable(unsigned long arg)
>  		return rv;
>  
>  	data = kmalloc(psetvariable_local.DataSize, GFP_KERNEL);
> +	if (!data) {
> +		kfree(name);
> +		return -ENOMEM;
> +	}
>  	if (copy_from_user(data, psetvariable_local.Data,
>  			   psetvariable_local.DataSize)) {
> +		kfree(data);
>  		kfree(name);
>  		return -EFAULT;
>  	}
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/efi_runtime/efi_runtime.c b/efi_runtime/efi_runtime.c
index 1125556..9693721 100644
--- a/efi_runtime/efi_runtime.c
+++ b/efi_runtime/efi_runtime.c
@@ -300,8 +300,13 @@  static long efi_runtime_set_variable(unsigned long arg)
 		return rv;
 
 	data = kmalloc(psetvariable_local.DataSize, GFP_KERNEL);
+	if (!data) {
+		kfree(name);
+		return -ENOMEM;
+	}
 	if (copy_from_user(data, psetvariable_local.Data,
 			   psetvariable_local.DataSize)) {
+		kfree(data);
 		kfree(name);
 		return -EFAULT;
 	}