Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libclaymore

Description

libclaymore is a shared library designed to be preloaded by the dynamic linker. It provides operational safety for the dd(1) utility by enforcing clear output semantics.

Due to historical design flaws, standard dd usage presents a severe hazard to operators. The legacy syntax (if= and of=) lacks sufficient semantic differentiation, frequently resulting in catastrophic data loss when an operator inadvertently transposes the input and output targets.

libclaymore mitigates this risk by interposing __libc_start_main and mutating the argument vector at runtime. It deprecates the of= argument and introduces modern, consequence-aware targeting directives.

Installation

Build and install the library to your system:

$ sudo make install

To enable protection, export the following environment variables in your shell configuration profile (e.g., ~/.bashrc, ~/.zshrc):

# if installed as root
export LD_PRELOAD=libclaymore.so
export LIBCLAYMORE_ARM=1

or

# if installed as a user
export LD_PRELOAD=~/.local/lib/libclaymore.so
export LIBCLAYMORE_ARM=1

Configuration

The library supports the following environment variables for configuration:

  • LIBCLAYMORE_ARM: Set to 1 to arm the library. If unset or set to 0, execution proceeds normally.
  • LIBCLAYMORE_WARNING: Overrides the text emitted to standard error when a blocked argument is intercepted. If unset, a sensible default message is provided.

Usage

When armed, libclaymore intercepts the execution of dd and enforces the following rules:

  1. Legacy Output Blocking: If the of= argument is detected, the operation is immediately aborted, the configured safety warning is printed to standard error, and the process exits with a non-zero status.
  2. Target Designation: Output targets must be explicitly designated using either enemy= or target=. These are translated to of= internally prior to detonation.
  3. Block Size and Flags: Output block size and output flags may use matching directional prefixes:
    • ebs= and tbs= map to obs=
    • eflag= and tflag= map to oflag=
    • eseek= and tseek= map to oseek=

Examples

Writing an ISO to a flash drive:

$ dd if=debian-12.0.0-amd64-netinst.iso enemy=/dev/sdX ebs=4M eflag=direct

Zeroing a block device:

$ dd if=/dev/zero target=/dev/nvme0n1 tbs=1M

Attempting legacy usage (Blocked):

$ dd if=/dev/zero of=/dev/sda
<configured safety warning>

Technical Details

Argument serialization is performed dynamically onto a single contiguous heap allocation to prevent argv pointer scattering. This ensures compatibility with internal string operations while avoiding potential segmentation faults in operating environments that rely on contiguous argument memory spaces. The memory allocated for the new argument block is yielded to the operating system upon normal process termination.

Child processes will not inherit the execution block, as LIBCLAYMORE_ARM is temporarily set to "0" during wrapper execution. This ensures that scripted uses of dd are not blocked, however argument remapping will remain active.

License

FAFOPL v1.0α

About

Make `dd` safer.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages