1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2017 Fujitsu Ltd. 4# Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com> 5# 6# This is a regression test about potential uninitialized variable, 7# the test can crash the buggy kernel, and the bug has been fixed in: 8# 9# commit 38327424b40bcebe2de92d07312c89360ac9229a 10# Author: Dan Carpenter <dan.carpenter@oracle.com> 11# Date: Thu Jun 16 15:48:57 2016 +0100 12# 13# KEYS: potential uninitialized variable 14 15TST_SETUP=setup 16TST_CLEANUP=cleanup 17TST_TESTFUNC=do_test 18TST_NEEDS_ROOT=1 19TST_NEEDS_TMPDIR=1 20TST_NEEDS_CMDS="keyctl" 21 22check_keyctl() 23{ 24 local nosup 25 for op in $@; do 26 nosup=0 27 28 if ! keyctl 2>&1 | grep -q "keyctl $op"; then 29 nosup=1 30 fi 31 32 if [ "$op" = "request2" ]; then 33 local key=`keyctl request2 user debug:foo bar` 34 if [ $? -ne 0 ]; then 35 nosup=1 36 fi 37 fi 38 39 if [ "$op" = "unlink" ]; then 40 if ! keyctl unlink $key @s; then 41 nosup=1 42 fi 43 fi 44 45 if [ $nosup -ne 0 ]; then 46 tst_brk TCONF "keyctl operation $op not supported" 47 fi 48 done 49} 50 51setup() 52{ 53 check_keyctl negate request2 show unlink 54 55 PATH_KEYSTAT="/proc/key-users" 56 PATH_KEYQUOTA="/proc/sys/kernel/keys/root_maxbytes" 57 58 if [ ! -f "$PATH_KEYSTAT" ] || [ ! -f "$PATH_KEYQUOTA" ]; then 59 tst_brk TCONF "'${PATH_KEYSTAT}' or '${PATH_KEYQUOTA}' \ 60 does not exist" 61 fi 62 63 ORIG_KEYSZ=`awk -F' +|/' '/ 0:/ {print $8}' $PATH_KEYSTAT` 64 ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA` 65} 66 67cleanup() 68{ 69 if [ -n "$ORIG_MAXKEYSZ" ]; then 70 echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA 71 fi 72} 73 74do_test() 75{ 76 local quota_excd=0 77 local maxkeysz=$((ORIG_KEYSZ + 100)) 78 79 while [ $maxkeysz -ge 0 ] 80 do 81 echo $maxkeysz >$PATH_KEYQUOTA 82 83 keyctl request2 user debug:fred negate @t >temp 2>&1 84 grep -q -E "quota exceeded" temp 85 if [ $? -eq 0 ]; then 86 quota_excd=1 87 break 88 fi 89 90 local key=`keyctl show | awk '/debug:fred/ {print $1}'` 91 if [ -z "$key" ]; then 92 key=`keyctl show | \ 93 awk -F ':' '/inaccessible/ {print $1}'` 94 fi 95 96 if [ -n "$key" ]; then 97 keyctl unlink $key @s >/dev/null 98 tst_sleep 50ms 99 fi 100 101 maxkeysz=$((maxkeysz - 4)) 102 done 103 104 if [ $quota_excd -eq 0 ]; then 105 tst_res TWARN "Failed to trigger the quota excess" 106 fi 107 108 tst_res TPASS "Bug not reproduced" 109} 110 111. tst_test.sh 112tst_run 113