From owner-svn-src-all@freebsd.org Mon Dec 30 21:32:57 2019 Return-Path: Delivered-To: svn-src-all@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 2B1321EABB0; Mon, 30 Dec 2019 21:32:57 +0000 (UTC) (envelope-from jilles@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47mrJ90Jgmz4W5y; Mon, 30 Dec 2019 21:32:57 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 05DC380FC; Mon, 30 Dec 2019 21:32:57 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBULWuGT085843; Mon, 30 Dec 2019 21:32:56 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBULWumr085838; Mon, 30 Dec 2019 21:32:56 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201912302132.xBULWumr085838@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Mon, 30 Dec 2019 21:32:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356208 - head/bin/sh/tests/execution X-SVN-Group: head X-SVN-Commit-Author: jilles X-SVN-Commit-Paths: head/bin/sh/tests/execution X-SVN-Commit-Revision: 356208 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Dec 2019 21:32:57 -0000 Author: jilles Date: Mon Dec 30 21:32:55 2019 New Revision: 356208 URL: https://svnweb.freebsd.org/changeset/base/356208 Log: 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 Added: head/bin/sh/tests/execution/shellproc2.0 (contents, props changed) head/bin/sh/tests/execution/shellproc3.0 (contents, props changed) head/bin/sh/tests/execution/shellproc4.0 (contents, props changed) head/bin/sh/tests/execution/shellproc5.0 (contents, props changed) Modified: head/bin/sh/tests/execution/Makefile Modified: head/bin/sh/tests/execution/Makefile ============================================================================== --- head/bin/sh/tests/execution/Makefile Mon Dec 30 20:30:31 2019 (r356207) +++ head/bin/sh/tests/execution/Makefile Mon Dec 30 21:32:55 2019 (r356208) @@ -55,6 +55,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 Added: head/bin/sh/tests/execution/shellproc2.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/execution/shellproc2.0 Mon Dec 30 21:32:55 2019 (r356208) @@ -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" ] Added: head/bin/sh/tests/execution/shellproc3.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/execution/shellproc3.0 Mon Dec 30 21:32:55 2019 (r356208) @@ -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" ] Added: head/bin/sh/tests/execution/shellproc4.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/execution/shellproc4.0 Mon Dec 30 21:32:55 2019 (r356208) @@ -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" ] Added: head/bin/sh/tests/execution/shellproc5.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/bin/sh/tests/execution/shellproc5.0 Mon Dec 30 21:32:55 2019 (r356208) @@ -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" ]