Linux SIGBUS — Bus Error Signal (Memory Alignment & Mapping)
Errorsignal
Overview
Linux SIGBUS (signal 7) occurs from memory alignment violations, accessing beyond mapped file boundaries, or hardware bus errors on specific architectures.
Key Details
- SIGBUS (signal 7) indicates a bus error — the CPU cannot physically address the memory
- Different from SIGSEGV: SIGBUS is an addressing error, SIGSEGV is a permissions/unmapped error
- Most common on x86: accessing an mmap'd file beyond its actual size
- On SPARC/ARM: unaligned memory access (e.g., reading int from odd address)
- Can also occur from stack overflow into guard pages on some architectures
Common Causes
- Accessing memory-mapped file (mmap) beyond the file's actual size
- File truncated while another process has it memory-mapped
- Unaligned memory access on strict-alignment architectures (ARM, SPARC)
- Hardware bus error (rare — indicates physical hardware problem)
- Stack guard page violation (alternative to SIGSEGV for stack overflow)
Steps
- 1Check if the program uses mmap: strace -e mmap,munmap ./program
- 2Verify mapped file size has not changed: ls -la and compare to mmap size
- 3For alignment issues: compile with -fsanitize=undefined to detect alignment violations
- 4Use GDB to find the exact instruction: gdb ./program core > bt
- 5Check dmesg for hardware bus errors if the issue is not software
Tags
linuxsigbusbus-errorsignal-7mmap
More in Signal
Frequently Asked Questions
SIGSEGV: accessing unmapped or unauthorized memory. SIGBUS: accessing memory that is mapped but physically inaccessible (alignment, truncated file, hardware).