Bug 3175

Summary: 'cp' does not play well with device files with ENABLE_FEATURE_NON_POSIX_CP is selected.
Product: Busybox Reporter: Caglar Akyuz <caglarakyuz>
Component: OtherAssignee: unassigned
Status: RESOLVED WONTFIX    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: 1.18.x   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description Caglar Akyuz 2011-01-31 19:44:05 UTC
Issuing following command replaces my device file:

$cp /dev/zero /dev/fb0

Here /dev/fb0 is a device file and I want to clear framebuffer memory, however cp tries to open device file with O_WRONLY|O_CREAT|O_EXCL and fails to open device file. Then it unlinks device file and creates a new file on my file-system. I don't know if this is intentional or not but, IMHO, this behavior is not expected.
Comment 1 Denys Vlasenko 2011-02-02 00:04:50 UTC
That's not surprising, since you use "copy file(s)" command to perform something quite different from copying of files.


Help text for this option says:

config FEATURE_NON_POSIX_CP
        bool "Non-POSIX, but safer, copying to special nodes"
        default y
        help
          With this option, "cp file symlink" will delete symlink
          and create a regular file. This does not conform to POSIX,
          but prevents a symlink attack.
          Similarly, "cp file device" will not send file's data
          to the device. (To do that, use "cat file >device")


Thus, either disable FEATURE_NON_POSIX_CP and recompile your busybox, or use

cat /dev/zero >/dev/fb0

instead of cp.