linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] module: report -EFAULT on bytes remaining
@ 2012-09-12 15:06 Kees Cook
  2012-09-12 15:40 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2012-09-12 15:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Rusty Russell, Fengguang Wu, kernel-janitors, Mimi Zohar, Dan Carpenter

Caught by smatch:
kernel/module.c:2450 copy_module_from_user() warn: maybe return -EFAULT instead of the bytes remaining?  

Clean up the copy_from_user() call to not report a positive value.
With this patch, init_module() will report errors from copy_from_user
(before it would always only report -EFAULT when err != 0).

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
This change is on top of the finit_module patch series.
---
 kernel/module.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 0ad03c4..05b8dde 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2441,8 +2441,11 @@ int copy_module_from_user(const void __user *umod, unsigned long len,
 		return -ENOMEM;
 
 	err = copy_from_user(info->hdr, umod, info->len);
-	if (err)
+	if (err) {
+		if (err > 0)
+			err = -EFAULT;
 		goto free_hdr;
+	}
 
 	err = check_info(info);
 	if (err)
-- 
1.7.0.4


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: report -EFAULT on bytes remaining
  2012-09-12 15:06 [PATCH] module: report -EFAULT on bytes remaining Kees Cook
@ 2012-09-12 15:40 ` Dan Carpenter
  2012-09-13  6:31   ` Rusty Russell
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2012-09-12 15:40 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Rusty Russell, Fengguang Wu, kernel-janitors, Mimi Zohar

On Wed, Sep 12, 2012 at 08:06:16AM -0700, Kees Cook wrote:
> Caught by smatch:
> kernel/module.c:2450 copy_module_from_user() warn: maybe return -EFAULT instead of the bytes remaining?  
> 
> Clean up the copy_from_user() call to not report a positive value.
> With this patch, init_module() will report errors from copy_from_user
> (before it would always only report -EFAULT when err != 0).
> 
> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This change is on top of the finit_module patch series.
> ---
>  kernel/module.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/module.c b/kernel/module.c
> index 0ad03c4..05b8dde 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2441,8 +2441,11 @@ int copy_module_from_user(const void __user *umod, unsigned long len,
>  		return -ENOMEM;
>  
>  	err = copy_from_user(info->hdr, umod, info->len);
> -	if (err)
> +	if (err) {
> +		if (err > 0)
                ^^^^^^^^^^^
This condition is always true because copy_to/from_user() returns
the number of bytes remaining to be copied.  (It never returns a
negative error code).

> +			err = -EFAULT;
>  		goto free_hdr;
> +	}

regards,
dan carpenter



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] module: report -EFAULT on bytes remaining
  2012-09-12 15:40 ` Dan Carpenter
@ 2012-09-13  6:31   ` Rusty Russell
  0 siblings, 0 replies; 3+ messages in thread
From: Rusty Russell @ 2012-09-13  6:31 UTC (permalink / raw)
  To: Dan Carpenter, Kees Cook
  Cc: linux-kernel, Fengguang Wu, kernel-janitors, Mimi Zohar

Dan Carpenter <dan.carpenter@oracle.com> writes:

> On Wed, Sep 12, 2012 at 08:06:16AM -0700, Kees Cook wrote:
>> Caught by smatch:
>> kernel/module.c:2450 copy_module_from_user() warn: maybe return -EFAULT instead of the bytes remaining?  
>> 
>> Clean up the copy_from_user() call to not report a positive value.
>> With this patch, init_module() will report errors from copy_from_user
>> (before it would always only report -EFAULT when err != 0).
>> 
>> Reported-by: Fengguang Wu <fengguang.wu@intel.com>
>> Signed-off-by: Kees Cook <keescook@chromium.org>
>> ---
>> This change is on top of the finit_module patch series.
>> ---
>>  kernel/module.c |    5 ++++-
>>  1 files changed, 4 insertions(+), 1 deletions(-)
>> 
>> diff --git a/kernel/module.c b/kernel/module.c
>> index 0ad03c4..05b8dde 100644
>> --- a/kernel/module.c
>> +++ b/kernel/module.c
>> @@ -2441,8 +2441,11 @@ int copy_module_from_user(const void __user *umod, unsigned long len,
>>  		return -ENOMEM;
>>  
>>  	err = copy_from_user(info->hdr, umod, info->len);
>> -	if (err)
>> +	if (err) {
>> +		if (err > 0)
>                 ^^^^^^^^^^^
> This condition is always true because copy_to/from_user() returns
> the number of bytes remaining to be copied.  (It never returns a
> negative error code).

Yes, I made the obvious fix (eliminating the >0 check).

This "copy_from_user is stupid" was a debate a lost long ago, but it
still annoys me.

Applied,
Rusty.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-09-13  6:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-12 15:06 [PATCH] module: report -EFAULT on bytes remaining Kees Cook
2012-09-12 15:40 ` Dan Carpenter
2012-09-13  6:31   ` Rusty Russell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).