1#!/bin/sh 2# 3# Copyright (c) 2017 Fujitsu Ltd. 4# Ported: Guangwen Feng <fenggw-fnst@cn.fujitsu.com> 5# 6# This program is free software; you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation; either version 2 of the License, or 9# (at your option) any later version. 10# 11# This program is distributed in the hope that it would be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15# 16# You should have received a copy of the GNU General Public License 17# along with this program, if not, see <http://www.gnu.org/licenses/>. 18# 19# This is a regression test about potential uninitialized variable, 20# the test can crash the buggy kernel, and the bug has been fixed in: 21# 22# commit 38327424b40bcebe2de92d07312c89360ac9229a 23# Author: Dan Carpenter <dan.carpenter@oracle.com> 24# Date: Thu Jun 16 15:48:57 2016 +0100 25# 26# KEYS: potential uninitialized variable 27# 28 29TST_ID="keyctl01" 30TST_SETUP=setup 31TST_CLEANUP=cleanup 32TST_TESTFUNC=do_test 33TST_NEEDS_ROOT=1 34TST_NEEDS_TMPDIR=1 35TST_NEEDS_CMDS="keyctl" 36. tst_test.sh 37 38setup() 39{ 40 if tst_kvcmp -le 2.6.33; then 41 tst_brk TCONF "Kernel newer than 2.6.33 is needed" 42 fi 43 44 PATH_KEYSTAT="/proc/key-users" 45 PATH_KEYQUOTA="/proc/sys/kernel/keys/root_maxbytes" 46 47 if [ ! -f "$PATH_KEYSTAT" ] || [ ! -f "$PATH_KEYQUOTA" ]; then 48 tst_brk TCONF "'${PATH_KEYSTAT}' or '${PATH_KEYQUOTA}' \ 49 does not exist" 50 fi 51 52 ORIG_KEYSZ=`awk -F' +|/' '/ 0:/ {print $8}' $PATH_KEYSTAT` 53 ORIG_MAXKEYSZ=`cat $PATH_KEYQUOTA` 54} 55 56cleanup() 57{ 58 if [ -n "$ORIG_MAXKEYSZ" ]; then 59 echo $ORIG_MAXKEYSZ >$PATH_KEYQUOTA 60 fi 61} 62 63do_test() 64{ 65 local maxkeysz=$((ORIG_KEYSZ + 100)) 66 67 while true 68 do 69 echo $maxkeysz >$PATH_KEYQUOTA 70 71 keyctl request2 user debug:fred negate @t >temp 2>&1 72 grep -q -E "quota exceeded" temp 73 if [ $? -eq 0 ]; then 74 break 75 fi 76 77 local key=`keyctl show | awk '/debug:fred/ {print $1}'` 78 if [ -n "$key" ]; then 79 keyctl unlink $key @s >/dev/null 80 tst_sleep 50ms 81 fi 82 83 ((maxkeysz -= 4)) 84 done 85 86 tst_res TPASS "Bug not reproduced" 87} 88 89tst_run 90