Error Codes Wiki

Linux SIGBUS — Bus Error Signal (Memory Alignment & Mapping)

Errorsignal

About Linux SIGBUS

Linux SIGBUS (signal 7) occurs from memory alignment violations, accessing beyond mapped file boundaries, or hardware bus errors on specific architectures. 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: 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. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.

The most common reasons this occurs include: 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). Identifying the root cause is the first step toward finding the right solution.

To resolve this, follow these recommended steps: Check if the program uses mmap: strace -e mmap,munmap ./program. Verify mapped file size has not changed: ls -la and compare to mmap size. For alignment issues: compile with -fsanitize=undefined to detect alignment violations. Use GDB to find the exact instruction: gdb ./program core > bt. Check dmesg for hardware bus errors if the issue is not software. 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

What is the difference between SIGBUS and SIGSEGV?

SIGSEGV: accessing unmapped or unauthorized memory. SIGBUS: accessing memory that is mapped but physically inaccessible (alignment, truncated file, hardware).

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

  1. 1Check if the program uses mmap: strace -e mmap,munmap ./program
  2. 2Verify mapped file size has not changed: ls -la and compare to mmap size
  3. 3For alignment issues: compile with -fsanitize=undefined to detect alignment violations
  4. 4Use GDB to find the exact instruction: gdb ./program core > bt
  5. 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).