Skip to content

Commit 8a32d46

Browse files
James Bottomleyardbiesheuvel
authored andcommitted
selftests/efivarfs: add check for disallowing file truncation
Now that the ability of arbitrary writes to set the inode size is fixed, verify that a variable file accepts a truncation operation but does not change the stat size because of it. Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
1 parent 8b4bc20 commit 8a32d46

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/testing/selftests/efivarfs/efivarfs.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,28 @@ test_invalid_filenames()
202202
exit $ret
203203
}
204204

205+
test_no_set_size()
206+
{
207+
local attrs='\x07\x00\x00\x00'
208+
local file=$efivarfs_mount/$FUNCNAME-$test_guid
209+
local ret=0
210+
211+
printf "$attrs\x00" > $file
212+
[ -e $file -a -s $file ] || exit 1
213+
chattr -i $file
214+
: > $file
215+
if [ $? != 0 ]; then
216+
echo "variable file failed to accept truncation"
217+
ret=1
218+
elif [ -e $file -a ! -s $file ]; then
219+
echo "file can be truncated to zero size"
220+
ret=1
221+
fi
222+
rm $file || exit 1
223+
224+
exit $ret
225+
}
226+
205227
check_prereqs
206228

207229
rc=0
@@ -214,5 +236,6 @@ run_test test_zero_size_delete
214236
run_test test_open_unlink
215237
run_test test_valid_filenames
216238
run_test test_invalid_filenames
239+
run_test test_no_set_size
217240

218241
exit $rc

0 commit comments

Comments
 (0)