Linux EFAULT (errno 14) — Bad Address (Memory Access Error)
About Linux EFAULT (errno 14)
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. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: 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. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Run the program under Valgrind: valgrind --track-origins=yes ./program to detect memory errors. Compile with AddressSanitizer: gcc -fsanitize=address -g program.c. Use strace to identify which system call returns EFAULT: strace -e trace=all ./program. Enable core dumps: ulimit -c unlimited, then analyze with gdb ./program core. Review code for NULL pointer checks before system calls. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Is EFAULT a kernel bug?
Almost never. The kernel correctly detects the invalid pointer and returns EFAULT. The bug is in the user-space program.
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
- 1Run the program under Valgrind: valgrind --track-origins=yes ./program to detect memory errors
- 2Compile with AddressSanitizer: gcc -fsanitize=address -g program.c
- 3Use strace to identify which system call returns EFAULT: strace -e trace=all ./program
- 4Enable core dumps: ulimit -c unlimited, then analyze with gdb ./program core
- 5Review code for NULL pointer checks before system calls