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