• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
4# Based on reproducer and further discussion with Ignaz Forster <iforster@suse.de>
5# Reproducer for not upstreamed patchset [1] and previous report [2].
6# [1] https://www.spinics.net/lists/linux-integrity/msg05926.html
7# [2] https://www.spinics.net/lists/linux-integrity/msg03593.html
8
9TST_SETUP="setup"
10TST_CLEANUP="cleanup"
11TST_CNT=4
12
13setup()
14{
15	EVM_FILE="/sys/kernel/security/evm"
16
17	[ -f "$EVM_FILE" ] || tst_brk TCONF "EVM not enabled in kernel"
18	[ $(cat $EVM_FILE) -eq 1 ] || tst_brk TCONF "EVM not enabled for this boot"
19
20	require_ima_policy_cmdline "appraise_tcb"
21
22	lower="$TST_MNTPOINT/lower"
23	upper="$TST_MNTPOINT/upper"
24	work="$TST_MNTPOINT/work"
25	merged="$TST_MNTPOINT/merged"
26	mkdir -p $lower $upper $work $merged
27
28	device_backup="$TST_DEVICE"
29	TST_DEVICE="overlay"
30
31	fs_type_backup="$TST_FS_TYPE"
32	TST_FS_TYPE="overlay"
33
34	mntpoint_backup="$TST_MNTPOINT"
35	TST_MNTPOINT="$PWD/$merged"
36
37	params_backup="$TST_MNT_PARAMS"
38	TST_MNT_PARAMS="-o lowerdir=$lower,upperdir=$upper,workdir=$work"
39
40	tst_mount
41	mounted=1
42}
43
44test1()
45{
46	local file="foo1.txt"
47
48	tst_res TINFO "overwrite file in overlay"
49	EXPECT_PASS echo lower \> $lower/$file
50	EXPECT_PASS echo overlay \> $merged/$file
51}
52
53test2()
54{
55	local file="foo2.txt"
56
57	tst_res TINFO "append file in overlay"
58	EXPECT_PASS echo lower \> $lower/$file
59	EXPECT_PASS echo overlay \>\> $merged/$file
60}
61
62test3()
63{
64	local file="foo3.txt"
65
66	tst_res TINFO "create a new file in overlay"
67	EXPECT_PASS echo overlay \> $merged/$file
68}
69
70test4()
71{
72	local f
73
74	tst_res TINFO "read all created files"
75	for f in $(find $TST_MNTPOINT -type f); do
76		EXPECT_PASS cat $f \> /dev/null 2\> /dev/null
77	done
78}
79
80cleanup()
81{
82	[ -n "$mounted" ] || return 0
83
84	tst_umount $TST_MNTPOINT
85
86	TST_DEVICE="$device_backup"
87	TST_FS_TYPE="$fs_type_backup"
88	TST_MNTPOINT="$mntpoint_backup"
89	TST_MNT_PARAMS="$params_backup"
90}
91
92. ima_setup.sh
93tst_run
94