public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH]highmem_32.c: add argument pointer checking
@ 2009-06-29  3:08 Figo.zhang
  2009-06-29  4:09 ` Ingo Molnar
  0 siblings, 1 reply; 3+ messages in thread
From: Figo.zhang @ 2009-06-29  3:08 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: lkml, Andrew Morton

It had better add argument pointer checking.

If any guys write driver want to alloc hightmem and pass a no-initial pointer,
it would be crashed.

Signed-off-by: Figo.zhang <figo1802@gmail.com>
---  
arch/x86/mm/highmem_32.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
index 58f621e..e52e1a9 100644
--- a/arch/x86/mm/highmem_32.c
+++ b/arch/x86/mm/highmem_32.c
@@ -31,6 +31,7 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
 {
 	enum fixed_addresses idx;
 	unsigned long vaddr;
+	BUG_ON(!page);
 
 	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
 	pagefault_disable();
@@ -58,6 +59,9 @@ void kunmap_atomic(void *kvaddr, enum km_type type)
 	unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
 	enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
 
+	if(!kvaddr)
+		return;
+
 	/*
 	 * Force other mappings to Oops if they'll try to access this pte
 	 * without first remap it.  Keeping stale mappings around is a bad idea



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

* Re: [PATCH]highmem_32.c: add argument pointer checking
  2009-06-29  3:08 [PATCH]highmem_32.c: add argument pointer checking Figo.zhang
@ 2009-06-29  4:09 ` Ingo Molnar
  2009-06-29 16:11   ` Figo.zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Ingo Molnar @ 2009-06-29  4:09 UTC (permalink / raw)
  To: Figo.zhang; +Cc: lkml, Andrew Morton


* Figo.zhang <figo1802@gmail.com> wrote:

> It had better add argument pointer checking.
> 
> If any guys write driver want to alloc hightmem and pass a no-initial pointer,
> it would be crashed.
> 
> Signed-off-by: Figo.zhang <figo1802@gmail.com>
> ---  
> arch/x86/mm/highmem_32.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
> index 58f621e..e52e1a9 100644
> --- a/arch/x86/mm/highmem_32.c
> +++ b/arch/x86/mm/highmem_32.c
> @@ -31,6 +31,7 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
>  {
>  	enum fixed_addresses idx;
>  	unsigned long vaddr;
> +	BUG_ON(!page);
>  
>  	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
>  	pagefault_disable();
> @@ -58,6 +59,9 @@ void kunmap_atomic(void *kvaddr, enum km_type type)
>  	unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
>  	enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
>  
> +	if(!kvaddr)
> +		return;
> +

(Please run patches through scripts/checkpatch.pl before 
submission.)

Also, what's the improvement here? Before the patch we'd crash on a 
NULL dereference ... after the patch we'd crash on a BUG_ON().

Furthermore, he kunmap_atomic() change is outright wrong - it will 
now allow NULL kunmaps, which can hide bugs in drivers.

	Ingo

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

* Re: [PATCH]highmem_32.c: add argument pointer checking
  2009-06-29  4:09 ` Ingo Molnar
@ 2009-06-29 16:11   ` Figo.zhang
  0 siblings, 0 replies; 3+ messages in thread
From: Figo.zhang @ 2009-06-29 16:11 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: lkml, Andrew Morton

On Mon, 2009-06-29 at 06:09 +0200, Ingo Molnar wrote:
> * Figo.zhang <figo1802@gmail.com> wrote:
> 
> > It had better add argument pointer checking.
> > 
> > If any guys write driver want to alloc hightmem and pass a no-initial pointer,
> > it would be crashed.
> > 
> > Signed-off-by: Figo.zhang <figo1802@gmail.com>
> > ---  
> > arch/x86/mm/highmem_32.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> > 
> > diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
> > index 58f621e..e52e1a9 100644
> > --- a/arch/x86/mm/highmem_32.c
> > +++ b/arch/x86/mm/highmem_32.c
> > @@ -31,6 +31,7 @@ void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot)
> >  {
> >  	enum fixed_addresses idx;
> >  	unsigned long vaddr;
> > +	BUG_ON(!page);
> >  
> >  	/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
> >  	pagefault_disable();
> > @@ -58,6 +59,9 @@ void kunmap_atomic(void *kvaddr, enum km_type type)
> >  	unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
> >  	enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
> >  
> > +	if(!kvaddr)
> > +		return;
> > +
> 
> (Please run patches through scripts/checkpatch.pl before 
> submission.)
> 
> Also, what's the improvement here? Before the patch we'd crash on a 
> NULL dereference ... after the patch we'd crash on a BUG_ON().

why it would be crash on BUG_ON()?
I motify it and test on my computer, it would not crash.

Best Regards,
Figo.zhang

> 
> Furthermore, he kunmap_atomic() change is outright wrong - it will 
> now allow NULL kunmaps, which can hide bugs in drivers.
> 
> 	Ingo


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

end of thread, other threads:[~2009-06-29 16:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-29  3:08 [PATCH]highmem_32.c: add argument pointer checking Figo.zhang
2009-06-29  4:09 ` Ingo Molnar
2009-06-29 16:11   ` Figo.zhang

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