From owner-dev-commits-src-branches@freebsd.org Sat Jan 30 15:11:44 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8D5154EFD32; Sat, 30 Jan 2021 15:11:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DSd343fXxz4fFx; Sat, 30 Jan 2021 15:11:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7034317BDD; Sat, 30 Jan 2021 15:11:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10UFBi65032997; Sat, 30 Jan 2021 15:11:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10UFBiXl032996; Sat, 30 Jan 2021 15:11:44 GMT (envelope-from git) Date: Sat, 30 Jan 2021 15:11:44 GMT Message-Id: <202101301511.10UFBiXl032996@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jilles Tjoelker Subject: git: 9b38ede3a347 - stable/12 - sh: Test that executing various binary files is rejected MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jilles X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 9b38ede3a347f9ae48d4b80878134f07ccc6845c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 30 Jan 2021 15:11:44 -0000 The branch stable/12 has been updated by jilles: URL: https://cgit.FreeBSD.org/src/commit/?id=9b38ede3a347f9ae48d4b80878134f07ccc6845c commit 9b38ede3a347f9ae48d4b80878134f07ccc6845c Author: Jilles Tjoelker AuthorDate: 2019-12-30 21:32:55 +0000 Commit: Jilles Tjoelker CommitDate: 2021-01-30 15:10:26 +0000 sh: Test that executing various binary files is rejected If executing a file fails with an [ENOEXEC] error, the shell executes the file as a shell script, except that this execution may instead result in an error message if the file is binary. Per a recent Austin Group interpretation, we will need to change this to allow a concatenation of a shell script and a binary payload. See Austin Group bugs #1226 and #1250. MFC after: 1 week (cherry picked from commit 2a55bade0ed3e08a8c4f922df0ecf67d1ee32f53) --- bin/sh/tests/execution/Makefile | 4 ++++ bin/sh/tests/execution/shellproc2.0 | 18 ++++++++++++++++++ bin/sh/tests/execution/shellproc3.0 | 14 ++++++++++++++ bin/sh/tests/execution/shellproc4.0 | 14 ++++++++++++++ bin/sh/tests/execution/shellproc5.0 | 14 ++++++++++++++ 5 files changed, 64 insertions(+) diff --git a/bin/sh/tests/execution/Makefile b/bin/sh/tests/execution/Makefile index 064afdbf736c..bd6b2e06d55e 100644 --- a/bin/sh/tests/execution/Makefile +++ b/bin/sh/tests/execution/Makefile @@ -56,6 +56,10 @@ ${PACKAGE}FILES+= set-x2.0 ${PACKAGE}FILES+= set-x3.0 ${PACKAGE}FILES+= set-x4.0 ${PACKAGE}FILES+= shellproc1.0 +${PACKAGE}FILES+= shellproc2.0 +${PACKAGE}FILES+= shellproc3.0 +${PACKAGE}FILES+= shellproc4.0 +${PACKAGE}FILES+= shellproc5.0 ${PACKAGE}FILES+= subshell1.0 subshell1.0.stdout ${PACKAGE}FILES+= subshell2.0 ${PACKAGE}FILES+= subshell3.0 diff --git a/bin/sh/tests/execution/shellproc2.0 b/bin/sh/tests/execution/shellproc2.0 new file mode 100644 index 000000000000..85e768070022 --- /dev/null +++ b/bin/sh/tests/execution/shellproc2.0 @@ -0,0 +1,18 @@ +# $FreeBSD$ +# This tests a quality of implementation issue. +# Shells are not required to reject executing binary files as shell scripts +# but executing, for example, ELF files for a different architecture as +# shell scripts may have annoying side effects. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\0' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +if [ ! -s "$T/testshellproc" ]; then + printf "printf did not write a NUL character\n" >&2 + exit 2 +fi +PATH=$T:$PATH +errout=`testshellproc 3>&2 2>&1 >&3 3>&-` +r=$? +[ "$r" = 126 ] && [ -n "$errout" ] diff --git a/bin/sh/tests/execution/shellproc3.0 b/bin/sh/tests/execution/shellproc3.0 new file mode 100644 index 000000000000..6ad455f2cd77 --- /dev/null +++ b/bin/sh/tests/execution/shellproc3.0 @@ -0,0 +1,14 @@ +# $FreeBSD$ +# This tests a quality of implementation issue. +# Shells are not required to reject executing binary files as shell scripts +# but executing, for example, ELF files for a different architecture as +# shell scripts may have annoying side effects. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\177ELF\001!!\011\0\0\0\0\0\0\0\0' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +errout=`testshellproc 3>&2 2>&1 >&3 3>&-` +r=$? +[ "$r" = 126 ] && [ -n "$errout" ] diff --git a/bin/sh/tests/execution/shellproc4.0 b/bin/sh/tests/execution/shellproc4.0 new file mode 100644 index 000000000000..fcc72eef073c --- /dev/null +++ b/bin/sh/tests/execution/shellproc4.0 @@ -0,0 +1,14 @@ +# $FreeBSD$ +# This tests a quality of implementation issue. +# Shells are not required to reject executing binary files as shell scripts +# but executing, for example, ELF files for a different architecture as +# shell scripts may have annoying side effects. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\211PNG\015\012\032\012\0\0\0\015IHDR' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +errout=`testshellproc 3>&2 2>&1 >&3 3>&-` +r=$? +[ "$r" = 126 ] && [ -n "$errout" ] diff --git a/bin/sh/tests/execution/shellproc5.0 b/bin/sh/tests/execution/shellproc5.0 new file mode 100644 index 000000000000..c25ffe3e4693 --- /dev/null +++ b/bin/sh/tests/execution/shellproc5.0 @@ -0,0 +1,14 @@ +# $FreeBSD$ +# This tests a quality of implementation issue. +# Shells are not required to reject executing binary files as shell scripts +# but executing, for example, ELF files for a different architecture as +# shell scripts may have annoying side effects. + +T=`mktemp -d "${TMPDIR:-/tmp}/sh-test.XXXXXXXX"` || exit +trap 'rm -rf "${T}"' 0 +printf '\177ELF\001!!\012\0\0\0\0\0\0\0\0' >"$T/testshellproc" +chmod 755 "$T/testshellproc" +PATH=$T:$PATH +errout=`testshellproc 3>&2 2>&1 >&3 3>&-` +r=$? +[ "$r" = 126 ] && [ -n "$errout" ]