Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iamroot, interpreter-script: run empty executable files
TL;DR; This runs empty executable files via shell interpreter. The package scripts devuan-baseconf.postinst is empty on Devuan jessie; this leads to the error below: Setting up devuan-baseconf (0.6.4+devuan1.3) ... dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Input/output error dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 See: gportay@archlinux ~/src/iamroot $ ls -l amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.* -rw-r--r-- 1 gportay gportay 76 May 24 2017 amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.conffiles -rw-r--r-- 1 gportay gportay 307 May 10 09:16 amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.list -rw-r--r-- 1 gportay gportay 151 May 24 2017 amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.md5sums -rwxr-xr-x 1 gportay gportay 0 May 24 2017 amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.postinst -rwxr-xr-x 1 gportay gportay 0 May 24 2017 amd64-devuan-jessie-rootfs/var/lib/dpkg/info/devuan-baseconf.postrm See also[1][2]. According to the Open Group Base Specifications Issue 7, 2018 edition, Chapter 2.9.1, Point Command Search and Execution 1.e.i.b. and 2.[3]: If the execl() function fails due to an error equivalent to the [ENOEXEC] error defined in the System Interfaces volume of POSIX.1-2017, the shell shall execute a command equivalent to having a shell invoked with the pathname resulting from the search as its first operand, with any remaining arguments passed to the new shell, except that the value of "$0" in the new shell may be set to the command name. If the executable file is not a text file, the shell may bypass this command execution. In this case, it shall write an error message, and shall return an exit status of 126. (...) If the execl() function fails due to an error equivalent to the [ENOEXEC] error, the shell shall execute a command equivalent to having a shell invoked with the command name as its first operand, with any remaining arguments passed to the new shell. If the executable file is not a text file, the shell may bypass this command execution. In this case, it shall write an error message and shall return an exit status of 126. According to 6) in execute_cmd.c of bash(1)[4][5]: 1) fork () 2) connect pipes 3) look up the command 4) do redirections 5) execve () 6) If the execve failed, see if the file has executable mode set. If so, and it isn't a directory, then execute its contents as a shell script. According to shell/ash.c of busybox(1)[6]: /* Run "cmd" as a shell script: * http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html * "If the execve() function fails with ENOEXEC, the shell * shall execute a command equivalent to having a shell invoked * with the command name as its first operand, * with any remaining arguments passed to the new shell" * * That is, do not use $SHELL, user's shell, or /bin/sh; * just call ourselves. * * Note that bash reads ~80 chars of the file, and if it sees * a zero byte before it sees newline, it doesn't try to * interpret it, but fails with "cannot execute binary file" * message and exit code 126. For one, this prevents attempts * to interpret foreign ELF binaries as shell scripts. */ The functions execve(), posix_spawn() and co. bypass the kernel by rewritting the cmdline using the dynamic loader to run the program. This hacks the function __can_exec() to return 1 if empty-file, and the function __interpreter_script_hashbang() to return _PATH_BSHELL to cause to "execve($ROOT/bin/sh, {argv[0], program, ...}, __environ)". Note: This should be implemented correctly. Fixes: gportay@archlinux ~/src/iamroot $ make amd64-devuan-jessie-rootfs ido --multiarch --preserve-env=PERL_DL_NONLAZY --preserve-env=LDCONFIG_NOTRIGGER mkdir -p amd64-devuan-jessie-rootfs ido --multiarch --preserve-env=PERL_DL_NONLAZY --preserve-env=LDCONFIG_NOTRIGGER debootstrap --keep-debootstrap-dir --arch=amd64 jessie amd64-devuan-jessie-rootfs http://archive.devuan.org/merged/ support/ceres I: Target architecture can be executed I: Retrieving InRelease I: Checking Release signature I: Valid Release signature (key id 72E3CB773315DFA2E464743D94532124541922FB) I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages... I: Resolving dependencies of base packages... I: Checking component main on http://archive.devuan.org/merged... (...) W: Failure while configuring base packages. This will be re-attempted up to five times. W: See /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log for details (possibly the package devuan-baseconf is at fault) I: Configuring devuan-baseconf... W: Failure while configuring base packages. This will be re-attempted up to five times. W: See /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log for details (possibly the package devuan-baseconf is at fault) W: Failure while configuring base packages. This will be re-attempted up to five times. W: See /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log for details (possibly the package devuan-baseconf is at fault) W: Failure while configuring base packages. This will be re-attempted up to five times. W: See /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log for details (possibly the package devuan-baseconf is at fault) W: Failure while configuring base packages. This will be re-attempted up to five times. W: See /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log for details (possibly the package devuan-baseconf is at fault) gportay@archlinux ~/src/iamroot $ cat /home/gportay/src/iamroot/amd64-devuan-jessie-rootfs/debootstrap/debootstrap.log (...) Setting up devuan-baseconf (0.6.4+devuan1.3) ... __fcan_exec: Input/output error dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 (...) Errors were encountered while processing: devuan-baseconf Setting up devuan-baseconf ... __fcan_exec: Input/output error dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: devuan-baseconf Setting up devuan-baseconf ... __fcan_exec: Input/output error dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: devuan-baseconf Setting up devuan-baseconf ... __fcan_exec: Input/output error dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: devuan-baseconf Setting up devuan-baseconf ... __fcan_exec: Input/output error dpkg (subprocess): unable to execute installed post-installation script (/var/lib/dpkg/info/devuan-baseconf.postinst): Invalid argument dpkg: error processing package devuan-baseconf (--configure): subprocess installed post-installation script returned error exit status 2 Errors were encountered while processing: devuan-baseconf [1]: https://utcc.utoronto.ca/~cks/space/blog/unix/BourneCommentHistory [2]: https://utcc.utoronto.ca/~cks/space/blog/unix/EmptyFileWhyTrue [3]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html [4]: http://git.savannah.gnu.org/cgit/bash.git/tree/execute_cmd.c?h=bash-5.2#n5569 [5]: http://git.savannah.gnu.org/cgit/bash.git/tree/execute_cmd.c?h=bash-5.2#n5992 [6]: https://git.busybox.net/busybox/tree/shell/ash.c#n8282
- Loading branch information