linux/drivers/char/agp
Jesper Juhl 190644e180 Fix "use after free" / "double free" bug in ati_create_gatt_pages / ati_free_gatt_pages
Hi,

Coverity spotted a "use after free" bug in
drivers/char/agp/ati-agp.c::ati_create_gatt_pages().

The same one that was in
  drivers/char/agp/amd-k7-agp.c::amd_create_gatt_pages()

The problem is this:
       If "entry = kzalloc(sizeof(struct ati_page_map), GFP_KERNEL);"
fails, then there's a loop in the function to free all entries
allocated so far and break out of the allocation loop. That in itself
is pretty sane, but then the (now freed) 'tables' is assigned to
ati_generic_private.gatt_pages and 'retval' is set to -ENOMEM which
causes ati_free_gatt_pages(); to be called at the end of the function.
The problem with this is that ati_free_gatt_pages() will then loop
'ati_generic_private.num_tables' times and try to free each entry in
tables[] - this is bad since tables has already been freed and
furthermore it will call kfree(tables) at the end - a double free.

This patch removes the freeing loop in ati_create_gatt_pages() and
instead relies entirely on the call to ati_free_gatt_pages() to free
everything we allocated in case of an error. It also sets
ati_generic_private.num_tables to the actual number of entries
allocated instead of just using the value passed in from the caller -
this ensures that ati_free_gatt_pages() will only attempt to free
stuff that was actually allocated.

Note: I'm in no way intimate with this code and I have no way to
actually test this patch (besides compile test it), so while I've
tried to be careful in reading the code and make sure the patch
does the right thing an ACK from someone who actually knows the
code in-depth would be very much appreciated.

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Dave Airlie <airlied@linux.ie>
2007-07-27 10:44:32 +10:00
..
agp.h [AGPGART] intel_agp: Add support for G33, Q33 and Q35 chipsets 2007-06-06 17:10:03 -04:00
ali-agp.c [AGPGART] Add missing calls to global_flush_tlb() to ali-agp 2007-04-26 14:22:50 -04:00
alpha-agp.c PCI: Convert to alloc_pci_dev() 2007-05-02 19:02:37 -07:00
amd64-agp.c PCI: Change all drivers to use pci_device->revision 2007-07-11 16:02:10 -07:00
amd-k7-agp.c PCI: Change all drivers to use pci_device->revision 2007-07-11 16:02:10 -07:00
ati-agp.c Fix "use after free" / "double free" bug in ati_create_gatt_pages / ati_free_gatt_pages 2007-07-27 10:44:32 +10:00
backend.c [AGPGART] Hand off AGP maintainence. 2007-07-09 20:23:50 -04:00
compat_ioctl.c [AGPGART] compat ioctl 2007-02-03 17:16:24 -05:00
compat_ioctl.h [AGPGART] compat ioctl 2007-02-03 17:16:24 -05:00
efficeon-agp.c [AGPGART] Further constification. 2007-02-22 18:41:28 -05:00
frontend.c Detach sched.h from mm.h 2007-05-21 09:18:19 -07:00
generic.c Detach sched.h from mm.h 2007-05-21 09:18:19 -07:00
hp-agp.c [AGPGART] fix compile errors 2007-02-27 00:36:00 -05:00
i460-agp.c [AGPGART] fix compile errors 2007-02-27 00:36:00 -05:00
intel-agp.c [AGPGART] intel_agp: don't load if no IGD and AGP port 2007-06-21 12:49:11 -04:00
isoch.c [AGPGART] Lots of CodingStyle/whitespace cleanups. 2006-02-28 00:54:25 -05:00
Kconfig Merge ../linus 2006-12-12 18:13:32 -05:00
Makefile [AGPGART] Fix modular agpgart ia64 allmodconfig 2007-02-20 14:18:01 -05:00
nvidia-agp.c [AGPGART] Nvidia AGP: Use refcount aware PCI interfaces 2007-04-26 14:22:51 -04:00
parisc-agp.c PCI: Convert to alloc_pci_dev() 2007-05-02 19:02:37 -07:00
sgi-agp.c [AGPGART] Fix sparse warning in sgi-agp.c 2007-04-26 14:22:51 -04:00
sis-agp.c [AGPGART] prevent probe collision of sis-agp and amd64_agp 2007-04-26 14:22:50 -04:00
sworks-agp.c [AGPGART] sworks-agp: Switch to PCI ref counting APIs 2007-04-26 14:22:51 -04:00
uninorth-agp.c [POWERPC] Rename get_property to of_get_property: drivers 2007-05-02 20:04:32 +10:00
via-agp.c [AGPGART] Fix wrong ID in via-agp.c 2007-05-13 17:41:47 -04:00