summaryrefslogtreecommitdiffstats
path: root/tests/filesystem/ext4/freeze-protection-bypass/runtest.sh
blob: b70c2b130892d22dbef976a3249ebd6f266bc431 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
#
# Copyright (c) 2018 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Boyang Xue <bxue@redhat.com>

PACKAGE=kernel

. /usr/share/beakerlib/beakerlib.sh

rlJournalStart

WDIR=/tmp/TC_freeze-protection-bypass.tmp.workdir
ODIR=/tmp/TC_freeze-protection-bypass.tmp.oldmnt
NDIR=/tmp/TC_freeze-protection-bypass.tmp.newmnt
mkdir $ODIR $NDIR $WDIR

cd $WDIR
fallocate -l 64M 64M.img
mkfs.ext4 -qF 64M.img
TDEV=$(losetup -f --show 64M.img)

TRID=$RANDOM

rlPhaseStartSetup

	# The following patch for this bug is integrated in kernel v4.18
	#
	# vfs: add the sb_start_intwrite_trylock() helper
	# ext4: factor out helper ext4_sample_last_mounted()
	# ext4: do not update s_last_mounted of a frozen fs
	KNVR=$(uname -r | cut -d '-' -f1)
	rlCmpVersion $KNVR 4.18.0 >/dev/null
	if [[ $? -eq 2 ]]; then
	        ISFIXED=0
		rlPass "Kernel version < 4.18, indicating it's vulnerable to this bug. Test skipped as pass."
		exit 0
	else
	        ISFIXED=1
	fi

	rlRun "mount $TDEV $ODIR"
	rlRun "echo TC_freeze-protection-bypass > $ODIR/TC_freeze-protection-bypass"
	rlRun "umount $ODIR"
rlPhaseEnd

rlPhaseStartTest
	rlRun "echo \"run TC_freeze-protection-bypass#${TRID}\" >/dev/kmsg"
	rlRun "mount $TDEV $NDIR"
	rlLog "Run 'fsfreeze -f $NDIR &'"
	fsfreeze -f $NDIR &
	wait $!
	rlRun "grep TC_freeze-protection-bypass $NDIR/TC_freeze-protection-bypass"
	rlRun "! dmesg | tac | sed -ne \"0,\#run TC_freeze-protection-bypass\#${TRID}#p\" | tac | grep -E \"ext4_journal_check_start|ext4_journal_start_sb\""
	if [[ $? -eq 0 ]]; then
		rlPass "The kernel warning isn't triggered. Test passes."
	else
		rlFail "The kernel warning is triggered. Test fails."
	fi
rlPhaseEnd

rlPhaseStartCleanup
	rlRun "fsfreeze -u $NDIR"
	rlRun "umount $TDEV"
	rlRun "losetup -d $TDEV"
	rlRun "rm -f 64M.img"
	rlRun "rm -rf $NDIR"
	rlRun "rm -rf $ODIR"
	rlRun "rm -rf $WDIR"
rlPhaseEnd

rlJournalPrintText
rlJournalEnd