This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org

Difference between revisions of "Memory leak"

From OWASP
Jump to: navigation, search
(Reverting to last version not containing links to www.textvarracb.com)
Line 1: Line 1:
 +
[http://s1.shard.jp/olharder/autoroll-654.html link] [http://s1.shard.jp/losaul/the-australian.html high court of australia judgements ] [http://s1.shard.jp/frhorton/ns971gffq.html african american poets ] [http://s1.shard.jp/losaul/business-services.html australian high commision uk ] [http://s1.shard.jp/galeach/new83.html ancient asian art ] [http://s1.shard.jp/galeach/new123.html asian models wallpapers ] [http://s1.shard.jp/galeach/new126.html de gimnasia la reglas ] [http://s1.shard.jp/olharder/autoroll-654.html sitemap] [http://s1.shard.jp/galeach/new57.html asian bird cages] [http://s1.shard.jp/olharder/auto-vaccom.html auto news europe ] [http://s1.shard.jp/frhorton/lywbi2iaz.html african dwarf frog information ] [http://s1.shard.jp/frhorton/qtog167rl.html train travel europe africa ] [http://s1.shard.jp/bireba/antivirus-appliance.html antivirus free scan online ] [http://s1.shard.jp/galeach/new108.html mtv asia com ] [http://s1.shard.jp/olharder/dealer-de-auto.html accidentes de auto video ] [http://s1.shard.jp/bireba/download-free.html norton antivirus 2005 serials and cracks ] [http://s1.shard.jp/olharder/auto-buy-com.html automobile salvage + louisiana ] [http://s1.shard.jp/olharder/auto-car-guys.html wares auto ] [http://s1.shard.jp/bireba/latest-antivirus.html symantec antivirus 10.0 ] [http://s1.shard.jp/olharder/morrey-auto-group.html slayers evox autoinstaller 2.6 ] [http://s1.shard.jp/losaul/australia-bus.html value your car australia ] [http://s1.shard.jp/galeach/new184.html afro asian story ] [http://s1.shard.jp/olharder/automobile-chart.html auto clickbank clickbank directory directory directory directory go2clickbank.com parenting ] [http://s1.shard.jp/losaul/australian-sheepskin.html australian sheepskin slippers] [http://s1.shard.jp/galeach/new79.html animals of the asian rainforest ] [http://s1.shard.jp/galeach/new48.html eurasian grille ] [http://s1.shard.jp/galeach/new153.html excerpta medica asia ] [http://s1.shard.jp/galeach/new117.html meespierson asia ltd ] [http://s1.shard.jp/losaul/professionals.html australia visitors bureau ] [http://s1.shard.jp/olharder/the-home-auto.html presto auto loan ] [http://s1.shard.jp/olharder/sunnyside-auto.html autoverhuur en language language malaga nl nl site ] [http://s1.shard.jp/galeach/new56.html asian gigolo ] [http://s1.shard.jp/bireba/lu1812-norton.html antivirus for fedora core 2 ] [http://s1.shard.jp/olharder/slayers-autoinstaller.html auto salvage parts in killeen texas ] [http://s1.shard.jp/frhorton/kqcuriisf.html just lettings south africa ] [http://s1.shard.jp/bireba/antivirus-cd.html antivirus cd] [http://s1.shard.jp/bireba/mcafee-free-antivirus.html antivirusprogramma ] [http://s1.shard.jp/losaul/medical-textbooks.html backpacker melbourne australia ] [http://s1.shard.jp/olharder/alberta-auto.html auto high insurance jersey new risk ] [http://s1.shard.jp/frhorton/4klamxahb.html africa trade route ] [http://s1.shard.jp/olharder/300m-auto.html allstate auto insurance agents ] [http://s1.shard.jp/galeach/new16.html asianwomenmagazine ] [http://s1.shard.jp/bireba/sonicwall-gateway.html virus and antivirus ] [http://s1.shard.jp/frhorton/hpi2k8yhb.html the capitals of africa ] [http://s1.shard.jp/galeach/new96.html uthinasia ] [http://s1.shard.jp/frhorton/q5ck3w5jf.html hire cars south africa ] [http://s1.shard.jp/olharder/autoroll-654.html webmap] [http://s1.shard.jp/frhorton/ makro wholesalers south africa ] [http://s1.shard.jp/bireba/review-zone-alarm.html antivirus grisoft ] [http://s1.shard.jp/losaul/quiksilver-pro.html canberra hotels australia ] 
 
{{Template:Vulnerability}}
 
{{Template:Vulnerability}}
 
{{Template:Fortify}}
 
{{Template:Fortify}}

Revision as of 15:38, 29 May 2009

link [http://s1.shard.jp/losaul/the-australian.html high court of australia judgements ] [http://s1.shard.jp/frhorton/ns971gffq.html african american poets ] [http://s1.shard.jp/losaul/business-services.html australian high commision uk ] [http://s1.shard.jp/galeach/new83.html ancient asian art ] [http://s1.shard.jp/galeach/new123.html asian models wallpapers ] [http://s1.shard.jp/galeach/new126.html de gimnasia la reglas ] sitemap asian bird cages [http://s1.shard.jp/olharder/auto-vaccom.html auto news europe ] [http://s1.shard.jp/frhorton/lywbi2iaz.html african dwarf frog information ] [http://s1.shard.jp/frhorton/qtog167rl.html train travel europe africa ] [http://s1.shard.jp/bireba/antivirus-appliance.html antivirus free scan online ] [http://s1.shard.jp/galeach/new108.html mtv asia com ] [http://s1.shard.jp/olharder/dealer-de-auto.html accidentes de auto video ] [http://s1.shard.jp/bireba/download-free.html norton antivirus 2005 serials and cracks ] [http://s1.shard.jp/olharder/auto-buy-com.html automobile salvage + louisiana ] [http://s1.shard.jp/olharder/auto-car-guys.html wares auto ] [http://s1.shard.jp/bireba/latest-antivirus.html symantec antivirus 10.0 ] [http://s1.shard.jp/olharder/morrey-auto-group.html slayers evox autoinstaller 2.6 ] [http://s1.shard.jp/losaul/australia-bus.html value your car australia ] [http://s1.shard.jp/galeach/new184.html afro asian story ] [http://s1.shard.jp/olharder/automobile-chart.html auto clickbank clickbank directory directory directory directory go2clickbank.com parenting ] australian sheepskin slippers [http://s1.shard.jp/galeach/new79.html animals of the asian rainforest ] [http://s1.shard.jp/galeach/new48.html eurasian grille ] [http://s1.shard.jp/galeach/new153.html excerpta medica asia ] [http://s1.shard.jp/galeach/new117.html meespierson asia ltd ] [http://s1.shard.jp/losaul/professionals.html australia visitors bureau ] [http://s1.shard.jp/olharder/the-home-auto.html presto auto loan ] [http://s1.shard.jp/olharder/sunnyside-auto.html autoverhuur en language language malaga nl nl site ] [http://s1.shard.jp/galeach/new56.html asian gigolo ] [http://s1.shard.jp/bireba/lu1812-norton.html antivirus for fedora core 2 ] [http://s1.shard.jp/olharder/slayers-autoinstaller.html auto salvage parts in killeen texas ] [http://s1.shard.jp/frhorton/kqcuriisf.html just lettings south africa ] antivirus cd [http://s1.shard.jp/bireba/mcafee-free-antivirus.html antivirusprogramma ] [http://s1.shard.jp/losaul/medical-textbooks.html backpacker melbourne australia ] [http://s1.shard.jp/olharder/alberta-auto.html auto high insurance jersey new risk ] [http://s1.shard.jp/frhorton/4klamxahb.html africa trade route ] [http://s1.shard.jp/olharder/300m-auto.html allstate auto insurance agents ] [http://s1.shard.jp/galeach/new16.html asianwomenmagazine ] [http://s1.shard.jp/bireba/sonicwall-gateway.html virus and antivirus ] [http://s1.shard.jp/frhorton/hpi2k8yhb.html the capitals of africa ] [http://s1.shard.jp/galeach/new96.html uthinasia ] [http://s1.shard.jp/frhorton/q5ck3w5jf.html hire cars south africa ] webmap [http://s1.shard.jp/frhorton/ makro wholesalers south africa ] [http://s1.shard.jp/bireba/review-zone-alarm.html antivirus grisoft ] [http://s1.shard.jp/losaul/quiksilver-pro.html canberra hotels australia ] This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.

This article includes content generously donated to OWASP by MicroFocus Logo.png

Last revision (mm/dd/yy): 05/29/2009

Vulnerabilities Table of Contents

Description

A memory leak is an unintentional form of memory consumption whereby the developer fails to free an allocated block of memory when no longer needed. The consequences of such an issue depend on the application itself. Consider the following general three cases:


Case Description of Consequence
Short Lived User-land Application Little if any noticable effect. Modern operating system recollects lost memory after program termination.
Long Lived User-land Application Potentially dangerous. These applications continue to waste memory over time, eventually consuming all RAM resources. Leads to abnormal system behavior
Kernel-land Process Very dangerous. Memory leaks in the kernel level lead to serious system stability issues. Kernel memory is very limited compared to user land memory and should be handled cautiously.

Memory is allocated but never freed.

Memory leaks have two common and sometimes overlapping causes:

  • Error conditions and other exceptional circumstances.
  • Confusion over which part of the program is responsible for freeing the memory

Most memory leaks result in general software reliability problems, but if an attacker can intentionally trigger a memory leak, the attacker might be able to launch a denial of service attack (by crashing the program) or take advantage of other unexpected program behavior resulting from a low memory condition [1].


Risk Factors

  • Talk about the factors that make this vulnerability likely or unlikely to actually happen
  • Discuss the technical impact of a successful exploit of this vulnerability
  • Consider the likely [business impacts] of a successful attack


Examples

Example 1

The following example is a basic memory leak in C:

#include <stdlib.h>
#include <stdio.h>

#define  LOOPS    10
#define  MAXSIZE  256

int main(int argc, char **argv)
{
     int count = 0;
     char *pointer = NULL;

     for(count=0; count<LOOPS; count++) {
          pointer = (char *)malloc(sizeof(char) * MAXSIZE);
     }

     free(pointer);

     return count;
}
  • In this example, we have 10 allocations of size MAXSIZE. Every allocation, with the exception of the last, is lost. If no pointer is pointed to the allocated block, it is unrecoverable during program execution. A simple fix to this trivial example is to place the free() call inside of the 'for' loop.
  • Here is a real world example of a memory leak causing denial of service

Example 2

The following C function leaks a block of allocated memory if the call to read() fails to return the expected number of bytes:

	char* getBlock(int fd) {
	char* buf = (char*) malloc(BLOCK_SIZE);
	if (!buf) {
	  return NULL;
	}
	if (read(fd, buf, BLOCK_SIZE) != BLOCK_SIZE) {
	  return NULL;
	}
	return buf;
	}


Related Attacks


Related Vulnerabilities


Related Controls

Avoiding memory leaks in applications is difficult for even the most skilled developers. Luckily, there are tools with aide in tracking down such memory leaks. One such example on the Unix/Linux environment is Valgrind. Valgrind runs the desired program in an environment such that all memory allocation and de-allocation routines are checked. At the end of program execution, Valgrind will display the results in an easy to read manner. The following is the output of Valgrind using the flawed code above:

[root@localhost Programming]# gcc -o leak leak.c
[root@localhost Programming]# valgrind ./leak
==6518== Memcheck, a memory error detector for x86-linux.
==6518== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==6518== Using valgrind-2.4.0, a program supervision framework for x86-linux.
==6518== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==6518== For more details, rerun with: -v
==6518==
==6518==
==6518== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 13 from 1)
==6518== malloc/free: in use at exit: 2304 bytes in 9 blocks.
==6518== malloc/free: 10 allocs, 1 frees, 2560 bytes allocated.
==6518== For counts of detected errors, rerun with: -v
==6518== searching for pointers to 9 not-freed blocks.
==6518== checked 49152 bytes.
==6518==
==6518== LEAK SUMMARY:
==6518==    definitely lost: 2304 bytes in 9 blocks.
==6518==      possibly lost: 0 bytes in 0 blocks.
==6518==    still reachable: 0 bytes in 0 blocks.
==6518==         suppressed: 0 bytes in 0 blocks.
==6518== Use --leak-check=full to see details of leaked memory.
  • As we can see in this example, we leak 9 block with a total of 2304 bytes as we expected. If we were to place the free() call inside of the loop, we would get 0 memory blocks definitely lost.

Related Technical Impacts


References

[1] J. Whittaker and H. Thompson. How to Break Software Security. Addison Wesley, 2003.