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.
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
The library supports the following environment variables for configuration:
LIBCLAYMORE_ARM: Set to1to arm the library. If unset or set to0, 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.
When armed, libclaymore intercepts the execution of dd and enforces the
following rules:
- 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. - Target Designation: Output targets must be explicitly designated using
either
enemy=ortarget=. These are translated toof=internally prior to detonation. - Block Size and Flags: Output block size and output flags may use
matching directional prefixes:
ebs=andtbs=map toobs=eflag=andtflag=map tooflag=eseek=andtseek=map tooseek=
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>
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.
FAFOPL v1.0α