Subject: kern/33023: device files behave unexpectedly under union mounts
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <dyoung@ojctech.com>
List: netbsd-bugs
Date: 03/07/2006 08:50:03
>Number:         33023
>Category:       kern
>Synopsis:       device files behave unexpectedly under union mounts
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 07 08:50:02 +0000 2006
>Originator:     David Young
>Release:        NetBSD 3.99.7
>Organization:
	OJC Technologies
>Environment:
	
	
System: NetBSD elmendorf.ojctech.com 3.99.7 NetBSD 3.99.7 (GENERIC) #9: Wed Aug 31 22:47:06 CDT 2005 dyoung@cuw.ojctech.com:/u3/dyoung/radix-nbsd/i386/O/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
If I union-mount a filesystem (e.g., /dev/vnd0a) over a directory
containing device special files (e.g., /dev/), writing to the device
special files (/dev/null) has an unexpected result.  Namely, the
device special file is "copied up" to the top filesystem as a
*regular file*.  For example, if I run 'echo test > /dev/null', a
regular file called 'null' is created in the top layer.  Its contents
are "test\n".
>How-To-Repeat:
Run these commands:

% mkdir foo
% cd foo
% cp /dev/MAKEDEV .
% su root -c "./MAKEDEV std"
% cd ..
% mkdir empty
% makefs -s 1440k -t ffs ./zoom.img ./empty/
% su root -c "vnconfig vnd0 ./zoom.img"
% su root -c "mount -o union /dev/vnd0a ./foo"
% cd foo
% ls -l
total 52
-r-xr-xr-x  1 dyoung  users    25429 Mar  7 02:27 MAKEDEV
crw-------  1 root    wheel    0,  0 Mar  7 02:28 console
crw-------  1 root    wheel    0,  1 Mar  7 02:28 constty
crw-r-----  1 root    kmem     4,  0 Mar  7 02:28 drum
crw-------  1 root    wheel    7,  0 Mar  7 02:28 klog
crw-r-----  1 root    kmem     2,  1 Mar  7 02:28 kmem
cr--r--r--  1 root    wheel  101,  0 Mar  7 02:28 ksyms
crw-r-----  1 root    kmem     2,  0 Mar  7 02:28 mem
crw-rw-rw-  1 root    wheel    2,  2 Mar  7 02:28 null
crw-rw-rw-  1 root    wheel   22,  2 Mar  7 02:28 stderr
crw-rw-rw-  1 root    wheel   22,  0 Mar  7 02:28 stdin
crw-rw-rw-  1 root    wheel   22,  1 Mar  7 02:28 stdout
crw-rw-rw-  1 root    wheel    1,  0 Mar  7 02:28 tty
crw-rw-rw-  1 root    wheel    2, 12 Mar  7 02:28 zero
% echo test > ./null
% ls -l 
total 54
-r-xr-xr-x  1 dyoung  users    25429 Mar  7 02:27 MAKEDEV
crw-------  1 root    wheel    0,  0 Mar  7 02:28 console
crw-------  1 root    wheel    0,  1 Mar  7 02:28 constty
crw-r-----  1 root    kmem     4,  0 Mar  7 02:28 drum
crw-------  1 root    wheel    7,  0 Mar  7 02:28 klog
crw-r-----  1 root    kmem     2,  1 Mar  7 02:28 kmem
cr--r--r--  1 root    wheel  101,  0 Mar  7 02:28 ksyms
crw-r-----  1 root    kmem     2,  0 Mar  7 02:28 mem
-rw-r--r--  1 dyoung  users        5 Mar  7 02:34 null
crw-rw-rw-  1 root    wheel   22,  2 Mar  7 02:28 stderr
crw-rw-rw-  1 root    wheel   22,  0 Mar  7 02:28 stdin
crw-rw-rw-  1 root    wheel   22,  1 Mar  7 02:28 stdout
crw-rw-rw-  1 root    wheel    1,  0 Mar  7 02:28 tty
crw-rw-rw-  1 root    wheel    2, 12 Mar  7 02:28 zero
% ls -l foo
total 52
-r-xr-xr-x  1 dyoung  users    25429 Mar  7 02:27 MAKEDEV
crw-------  1 root    wheel    0,  0 Mar  7 02:28 console
crw-------  1 root    wheel    0,  1 Mar  7 02:28 constty
crw-r-----  1 root    kmem     4,  0 Mar  7 02:28 drum
crw-------  1 root    wheel    7,  0 Mar  7 02:28 klog
crw-r-----  1 root    kmem     2,  1 Mar  7 02:28 kmem
cr--r--r--  1 root    wheel  101,  0 Mar  7 02:28 ksyms
crw-r-----  1 root    kmem     2,  0 Mar  7 02:28 mem
crw-rw-rw-  1 root    wheel    2,  2 Mar  7 02:28 null
crw-rw-rw-  1 root    wheel   22,  2 Mar  7 02:28 stderr
crw-rw-rw-  1 root    wheel   22,  0 Mar  7 02:28 stdin
crw-rw-rw-  1 root    wheel   22,  1 Mar  7 02:28 stdout
crw-rw-rw-  1 root    wheel    1,  0 Mar  7 02:28 tty
crw-rw-rw-  1 root    wheel    2, 12 Mar  7 02:28 zero
>Fix:
I do not know how to fix it.