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 <[email protected]> 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 29verify_binfmt_misc() 30{ 31 local name=$(echo "$1" | awk -F ':' '{print $2}') 32 local mntpoint=$(get_binfmt_misc_mntpoint) 33 34 (echo "$1" >"$mntpoint/register") 2>/dev/null 35 if [ $? -ne 0 -a ! -f "$mntpoint/$name" ]; then 36 tst_res TPASS "Failed to register a binary type" 37 return 38 fi 39 40 # Trigger kernel crash reliably by cat command. 41 cat "$mntpoint/$name" >/dev/null 2>&1 42 tst_res TFAIL "Register a binary type successfully" 43 44 [ -f "$mntpoint/$name" ] && \ 45 remove_binary_type "$mntpoint/$name" 46} 47 48do_test() 49{ 50 case $1 in 51 1) verify_binfmt_misc ".textension,E,,ltp,,$(which cat),";; 52 2) verify_binfmt_misc ":tnone:X::ltp::$(which cat):";; 53 3) verify_binfmt_misc ":textension/:E::ltp::$(which cat):";; 54 4) verify_binfmt_misc ":tmagic/:M::ltp::$(which cat):";; 55 5) verify_binfmt_misc ":textension:E::ltp/::$(which cat):";; 56 6) verify_binfmt_misc ":tmagic:M:-1:ltp::$(which cat):";; 57 7) verify_binfmt_misc ":tmagic:M:2500000000:ltp::$(which cat):";; 58 8) verify_binfmt_misc ":textension:E::ltp::$(which cat):A";; 59 9) verify_binfmt_misc ":tmagic:M::ltp::$(which cat):A";; 60 esac 61} 62 63. binfmt_misc_lib.sh 64tst_run 65