1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# 4# Copyright (c) 2019 FUJITSU LIMITED. All rights reserved. 5# Author: Xiao Yang <yangx.jy@cn.fujitsu.com> 6# 7# Description: 8# Use various invalid inputs to register a new binary type. 9# 1) Invalid format of string fails to register a new binary type. 10# 2) Invalid type fails to register a new binary type. 11# 3) Invalid name containing slashes fails to register a new 12# binary type. 13# 4) If extension matching is chosen, invalid magic containing 14# slashes fails to register a new binary type. 15# 5) If magic matching is chosen, invalid offset(e.g. -1 and 16# 2500000000) fails to register a new binary type. 17# 6) Invalid flag fails to register a new binary type. 18# 19# Note: 20# This is also a regression test for the following kernel bug: 21# '5cc41e099504 ("fs/binfmt_misc.c: do not allow offset overflow")' 22 23 24TST_CNT=9 25TST_TESTFUNC=do_test 26TST_NEEDS_CMDS="cat" 27 28. binfmt_misc_lib.sh 29 30verify_binfmt_misc() 31{ 32 local name=$(echo "$1" | awk -F ':' '{print $2}') 33 local mntpoint=$(get_binfmt_misc_mntpoint) 34 35 (echo "$1" >"$mntpoint/register") 2>/dev/null 36 if [ $? -ne 0 -a ! -f "$mntpoint/$name" ]; then 37 tst_res TPASS "Failed to register a binary type" 38 return 39 fi 40 41 # Trigger kernel crash reliably by cat command. 42 cat "$mntpoint/$name" >/dev/null 2>&1 43 tst_res TFAIL "Register a binary type successfully" 44 45 [ -f "$mntpoint/$name" ] && \ 46 remove_binary_type "$mntpoint/$name" 47} 48 49do_test() 50{ 51 case $1 in 52 1) verify_binfmt_misc ".textension,E,,ltp,,$(which cat),";; 53 2) verify_binfmt_misc ":tnone:X::ltp::$(which cat):";; 54 3) verify_binfmt_misc ":textension/:E::ltp::$(which cat):";; 55 4) verify_binfmt_misc ":tmagic/:M::ltp::$(which cat):";; 56 5) verify_binfmt_misc ":textension:E::ltp/::$(which cat):";; 57 6) verify_binfmt_misc ":tmagic:M:-1:ltp::$(which cat):";; 58 7) verify_binfmt_misc ":tmagic:M:2500000000:ltp::$(which cat):";; 59 8) verify_binfmt_misc ":textension:E::ltp::$(which cat):A";; 60 9) verify_binfmt_misc ":tmagic:M::ltp::$(which cat):A";; 61 esac 62} 63 64tst_run 65