Error Codes Wiki

Linux EFAULT (errno 14) — Bad Address (Memory Access Error)

Errorerrno

Overview

Linux EFAULT error occurs when a system call is given a pointer to invalid memory, indicating a programming bug or memory corruption in the application.

Key Details

  • EFAULT (errno 14) means a system call was passed a pointer outside the process's accessible address space
  • This is almost always a programming bug — passing NULL, freed, or uninitialized pointers to syscalls
  • The kernel validates user-space pointers before accessing them and returns EFAULT if invalid
  • Unlike SIGSEGV which crashes the process, EFAULT is returned as an error code allowing recovery
  • Common in C programs with incorrect memory management

Common Causes

  • Passing NULL pointer to a system call that expects valid memory
  • Using a pointer to freed memory (use-after-free)
  • Buffer allocated on the stack that has gone out of scope
  • Incorrect pointer arithmetic pointing outside allocated buffer
  • Memory corruption from buffer overflow in a different part of the program

Steps

  1. 1Run the program under Valgrind: valgrind --track-origins=yes ./program to detect memory errors
  2. 2Compile with AddressSanitizer: gcc -fsanitize=address -g program.c
  3. 3Use strace to identify which system call returns EFAULT: strace -e trace=all ./program
  4. 4Enable core dumps: ulimit -c unlimited, then analyze with gdb ./program core
  5. 5Review code for NULL pointer checks before system calls

Tags

linuxefaulterrno-14bad-addressmemory-bug

More in Errno

Frequently Asked Questions

Almost never. The kernel correctly detects the invalid pointer and returns EFAULT. The bug is in the user-space program.