Use After Free

Detects potential use-after-free vulnerabilities where memory is accessed after being freed.

zakirkun 9358b7b 2 files · 2.9 KB Updated

File contents

Use After Free

Overview

Use-after-free (UAF) occurs when a program continues to use a pointer after the memory it points to has been freed. This can lead to:

  • Memory corruption
  • Arbitrary code execution
  • Privilege escalation
  • Information disclosure

UAF vulnerabilities are common in browsers, kernels, and network services.

Detection Strategy

  • free(ptr) followed by accessing ptr without setting it to NULL
  • delete ptr in C++ followed by further dereference
  • Returning a pointer to freed memory

Remediation

  • Set pointers to NULL immediately after free()
  • Use smart pointers in C++ (unique_ptr, shared_ptr)
  • Use memory-safe languages for new projects

Vulnerable:

char *buf = malloc(256);
free(buf);
strcpy(buf, input); // Use after free!

Safe:

char *buf = malloc(256);
free(buf);
buf = NULL; // Prevent use after free

zakirkun/ice-tea/tree/main/skills/memory/use-after-free commit 9358b7b40c

Frequently asked questions

npx skillmds@latest add zakirkun/use-after-free