All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Null pointer dereference at free_vm_area()
@ 2005-12-26 15:58 Glauber de Oliveira Costa
  2005-12-27 15:54 ` Vincent Hanquez
  0 siblings, 1 reply; 3+ messages in thread
From: Glauber de Oliveira Costa @ 2005-12-26 15:58 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 452 bytes --]

Hi folks,

The free_vm_area() function may crash if it gets a NULL pointer as a
parameter. I do think that the right behaviour should be returning in
this case. This is, for example, the same behaviour of kfree(), and as
alloc_vm_area() may also return NULL, it may lead to a more elegant 
alloc/free sequence in case of a fail.

In case you agree with that, a patch follows.

Signed-off-by: Glauber de Oliveira Costa <glommer@br.ibm.com>

-- 
glommer

[-- Attachment #2: free_return_null --]
[-- Type: text/plain, Size: 390 bytes --]

diff -r 829517be689f linux-2.6-xen-sparse/drivers/xen/util.c
--- a/linux-2.6-xen-sparse/drivers/xen/util.c	Fri Dec 23 15:42:46 2005
+++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Mon Dec 26 15:47:50 2005
@@ -35,6 +35,8 @@
 void free_vm_area(struct vm_struct *area)
 {
 	struct vm_struct *ret;
+	if (!area)
+		return;
 	ret = remove_vm_area(area->addr);
 	BUG_ON(ret != area);
 	kfree(area);

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

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

* Re: [PATCH] Null pointer dereference at free_vm_area()
  2005-12-26 15:58 [PATCH] Null pointer dereference at free_vm_area() Glauber de Oliveira Costa
@ 2005-12-27 15:54 ` Vincent Hanquez
  2005-12-27 16:17   ` Glauber de Oliveira Costa
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Hanquez @ 2005-12-27 15:54 UTC (permalink / raw)
  To: Glauber de Oliveira Costa; +Cc: xen-devel

On Mon, Dec 26, 2005 at 01:58:57PM -0200, Glauber de Oliveira Costa wrote:
> The free_vm_area() function may crash if it gets a NULL pointer as a
> parameter. I do think that the right behaviour should be returning in
> this case. This is, for example, the same behaviour of kfree(), and as
> alloc_vm_area() may also return NULL, it may lead to a more elegant 
> alloc/free sequence in case of a fail.
>
> In case you agree with that, a patch follows.

Hi,

I quickly look around where free_vm_area is called, and I cannot see any
codepath that could benefit such a code cleanup nor find any that
could lead to a NULL pointer pass to it.

I think you should provide a use for this patch if you want it to be
applied.

Thanks,
-- 
Vincent Hanquez

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

* Re: [PATCH] Null pointer dereference at free_vm_area()
  2005-12-27 15:54 ` Vincent Hanquez
@ 2005-12-27 16:17   ` Glauber de Oliveira Costa
  0 siblings, 0 replies; 3+ messages in thread
From: Glauber de Oliveira Costa @ 2005-12-27 16:17 UTC (permalink / raw)
  To: Vincent Hanquez; +Cc: xen-devel

> 
> Hi,
> 
> I quickly look around where free_vm_area is called, and I cannot see any
> codepath that could benefit such a code cleanup nor find any that
> could lead to a NULL pointer pass to it.
> 
> I think you should provide a use for this patch if you want it to be
> applied.
> 
> Thanks,
> -- 
> Vincent Hanquez
> 
I think it's more stylish than functional nowadays. In a situations in which we 
call alloc_vm_area() more than once, and test for the return value of them all 
in one shot. It can maybe lead to a cleaner code, as shown in the
pseudocode bellow. 

a1 = alloc_vm_area()
a2 = alloc_vm_area()

if (!a1 || !a2){
	free_vm_area(a1);
	free_vm_area(a2);
	return;
}

Instead of:

a1 = alloc_vm_area();
if (!a1)
	return;
a2 = alloc_vm_area()
if (!a2){
	free_vm_area(a1);
	return;
}

But of course, it's mainly a matter of opinion.

-- 
glommer

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

end of thread, other threads:[~2005-12-27 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-26 15:58 [PATCH] Null pointer dereference at free_vm_area() Glauber de Oliveira Costa
2005-12-27 15:54 ` Vincent Hanquez
2005-12-27 16:17   ` Glauber de Oliveira Costa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.