public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* WARN_ON out of range error in ERR_PTR?
@ 2008-11-26 15:48 Benny Halevy
  2008-11-27  0:15 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Benny Halevy @ 2008-11-26 15:48 UTC (permalink / raw)
  To: Andrew Morton; +Cc: lkml

Andrew,

After hitting a bug where an nfs error -10021 wasn't handled
correctly since IS_ERR returned false on its ERR_PTR value
I realized that adding a BUG_ON to make sure the mapped error
is in the valid range would have caught this.

Since ERR_PTR is not called on the critical path
(unlike IS_ERR) but rather on the error handling path I believe
we can tolerate the extra cost.

The reason this is just a WARN_ON and not BUG_ON is to make
fixing it easier, although I do consider calling ERR_PTR on an
out of range error a pretty dangerous bug as the error might go
unnoticed.

How about committing the following patch to -mm?

Signed-off-by: Benny Halevy <bhalevy@panasas.com>
---
 include/linux/err.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/include/linux/err.h b/include/linux/err.h
index ec87f31..81df84f 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -2,7 +2,7 @@
 #define _LINUX_ERR_H
 
 #include <linux/compiler.h>
-
+#include <asm/bug.h>
 #include <asm/errno.h>
 
 /*
@@ -21,6 +21,7 @@
 
 static inline void *ERR_PTR(long error)
 {
+	WARN_ON(error && !IS_ERR_VALUE(error));
 	return (void *) error;
 }
 
-- 
1.6.0.2


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

* Re: WARN_ON out of range error in ERR_PTR?
  2008-11-26 15:48 WARN_ON out of range error in ERR_PTR? Benny Halevy
@ 2008-11-27  0:15 ` Andrew Morton
  2008-11-27  6:27   ` Benny Halevy
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2008-11-27  0:15 UTC (permalink / raw)
  To: Benny Halevy; +Cc: linux-kernel

On Wed, 26 Nov 2008 17:48:08 +0200
Benny Halevy <bhalevy@panasas.com> wrote:

> Andrew,
> 
> After hitting a bug where an nfs error -10021 wasn't handled
> correctly since IS_ERR returned false on its ERR_PTR value

That sounds like an error in NFS.  Did it get fixed?

> I realized that adding a BUG_ON to make sure the mapped error
> is in the valid range would have caught this.
> 
> Since ERR_PTR is not called on the critical path
> (unlike IS_ERR) but rather on the error handling path I believe
> we can tolerate the extra cost.
> 
> The reason this is just a WARN_ON and not BUG_ON is to make
> fixing it easier, although I do consider calling ERR_PTR on an
> out of range error a pretty dangerous bug as the error might go
> unnoticed.
> 
> How about committing the following patch to -mm?
> 
> Signed-off-by: Benny Halevy <bhalevy@panasas.com>
> ---
>  include/linux/err.h |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/err.h b/include/linux/err.h
> index ec87f31..81df84f 100644
> --- a/include/linux/err.h
> +++ b/include/linux/err.h
> @@ -2,7 +2,7 @@
>  #define _LINUX_ERR_H
>  
>  #include <linux/compiler.h>
> -
> +#include <asm/bug.h>
>  #include <asm/errno.h>
>  
>  /*
> @@ -21,6 +21,7 @@
>  
>  static inline void *ERR_PTR(long error)
>  {
> +	WARN_ON(error && !IS_ERR_VALUE(error));
>  	return (void *) error;
>  }

We have over 2000 ERR_PTR callsites, and WARN_ON() is a big fat porky
thing, so this change would add quite a lot of kernel text&data.

If this problem does occur again, I expect that the kernel will
reliably dereference a small negative address and we'll get an oops,
which will give us the same information as that WARN_ON would have
done, no?




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

* Re: WARN_ON out of range error in ERR_PTR?
  2008-11-27  0:15 ` Andrew Morton
@ 2008-11-27  6:27   ` Benny Halevy
  0 siblings, 0 replies; 3+ messages in thread
From: Benny Halevy @ 2008-11-27  6:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel

On Nov. 27, 2008, 2:15 +0200, Andrew Morton <akpm@linux-foundation.org> wrote:
> On Wed, 26 Nov 2008 17:48:08 +0200
> Benny Halevy <bhalevy@panasas.com> wrote:
> 
>> Andrew,
>>
>> After hitting a bug where an nfs error -10021 wasn't handled
>> correctly since IS_ERR returned false on its ERR_PTR value
> 
> That sounds like an error in NFS.  Did it get fixed?

Right, it is an error I made when developing new code for nfs41
and I caught and fixed it in my branch before releasing the code.
I just thought that this WARN_ON could be beneficial for everybody...

Benny

> 
>> I realized that adding a BUG_ON to make sure the mapped error
>> is in the valid range would have caught this.
>>
>> Since ERR_PTR is not called on the critical path
>> (unlike IS_ERR) but rather on the error handling path I believe
>> we can tolerate the extra cost.
>>
>> The reason this is just a WARN_ON and not BUG_ON is to make
>> fixing it easier, although I do consider calling ERR_PTR on an
>> out of range error a pretty dangerous bug as the error might go
>> unnoticed.
>>
>> How about committing the following patch to -mm?
>>
>> Signed-off-by: Benny Halevy <bhalevy@panasas.com>
>> ---
>>  include/linux/err.h |    3 ++-
>>  1 files changed, 2 insertions(+), 1 deletions(-)
>>
>> diff --git a/include/linux/err.h b/include/linux/err.h
>> index ec87f31..81df84f 100644
>> --- a/include/linux/err.h
>> +++ b/include/linux/err.h
>> @@ -2,7 +2,7 @@
>>  #define _LINUX_ERR_H
>>  
>>  #include <linux/compiler.h>
>> -
>> +#include <asm/bug.h>
>>  #include <asm/errno.h>
>>  
>>  /*
>> @@ -21,6 +21,7 @@
>>  
>>  static inline void *ERR_PTR(long error)
>>  {
>> +	WARN_ON(error && !IS_ERR_VALUE(error));
>>  	return (void *) error;
>>  }
> 
> We have over 2000 ERR_PTR callsites, and WARN_ON() is a big fat porky
> thing, so this change would add quite a lot of kernel text&data.
> 
> If this problem does occur again, I expect that the kernel will
> reliably dereference a small negative address and we'll get an oops,
> which will give us the same information as that WARN_ON would have
> done, no?
> 
> 
> 

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

end of thread, other threads:[~2008-11-27  6:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-26 15:48 WARN_ON out of range error in ERR_PTR? Benny Halevy
2008-11-27  0:15 ` Andrew Morton
2008-11-27  6:27   ` Benny Halevy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox