Bugzilla – Bug 115556
/init crashes in initramfs
Last modified: 2005-12-18 18:54:53 UTC
Whilst trying to get NFS root to work my machine always crashes in /init with mysterious error codes; mostly parsing errors from sh. When running under strace (in the same environment) the machine stopped with: ... write(2, ": proc udev_", 12: proc udev_) = 12 read(10, 0x528680, 4088) = -1 EBADF (Bad file descriptor) write(2, "+ ", 2+ ) = 2 write(2, ":", 1:) = 1 write(2, " proc", 5 proc) = 5 write(2, " udev_", 6 udev_) = 6 write(2, "\n", 1 ) = 1 _exit(0) Kernel panic - not syncing: Attempted to kill init Uh-oh ...
Created attachment 49014 [details] screenlog.1 Logfile captured from serial console. Doesn't show everything, I'm afraid, as the kernel panic occured before everything was flushed.
Created attachment 49015 [details] init /init script used within the initramfs
Created attachment 49016 [details] screenlog.2 Full screenlog; most clutter removed.
This seems to be the relevant part: this shell closes its sourcefile when it sources dhcpcd-eth0.info. open("/init.real", O_RDONLY) = 3 dup2(3, 10) = 10 read(10, "#! /bin/sh\n\nexport PATH=/sbin:/u"..., 4088) = 4088 open("/var/lib/dhcpcd/dhcpcd-eth0.info", O_RDONLY) = 3 dup2(3, 10) = 10 [...original fd 10 now and not saved anywhere...] close(3) = 0 read(10, "IPADDR=10.10.101.227\nNETMASK=255"..., 4088) = 657 read(10, "", 4088) = 0 close(10) = 0 [...some more temporary use of fd 10, eventually closing it again...] read(10, 0x528680, 4088) = -1 EBADF (Bad file descriptor)
Yep. there is a bug in /lib/klibc/bin/sh; dup2() will close the destination fd if already open. One should use fcntl() to always get a new free fd.
Raising priority as this potentially affects all installations.
Fixed klibc submitted to stable.
Just use dup() instead of dup2()
closed.