Skip to content

cp -R reads device nodes as streams instead of recreating them #9746

@sylvestre

Description

@sylvestre

Component

cp

Description

When copying directories recursively, uutils treats character and block device nodes as stream sources and reads bytes from them into regular files at the destination. This breaks device semantics: /dev/null becomes an empty regular file.

GNU cp preserves device nodes as device nodes during recursive copy by default. The --copy-contents flag explicitly enables stream-reading behavior. uutils currently lacks device node recreation (via mknod) and always treats devices as streams because is_stream() returns true for char/block devices.

This breaks recursive copies of system trees like chroot environments, initramfs staging, or container filesystems where device nodes must retain their type and major/minor numbers.

Test / Reproduction Steps

src="$(mktemp -d)"
dst="$(mktemp -d)"

sudo mknod "${src}/null" c 1 3

cp -R "${src}" "${dst}"

ls -l "${src}/null" "${dst}/null"

Impact

Recursive copies of filesystem trees containing device nodes produce incorrect results, breaking consumers that expect device semantics. Unbounded devices cause disk consumption and runtime denial-of-service.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions