]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/efivarfs: add check for disallowing file truncation
authorJames Bottomley <James.Bottomley@HansenPartnership.com>
Sun, 19 Jan 2025 14:59:41 +0000 (09:59 -0500)
committerArd Biesheuvel <ardb@kernel.org>
Sun, 19 Jan 2025 16:49:10 +0000 (17:49 +0100)
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>
tools/testing/selftests/efivarfs/efivarfs.sh

index d374878cc0ba9ba99a194c819f63e801172a484b..96677282789b1bbac0a7a4457024657e49b53fe2 100755 (executable)
@@ -202,6 +202,28 @@ test_invalid_filenames()
        exit $ret
 }
 
+test_no_set_size()
+{
+       local attrs='\x07\x00\x00\x00'
+       local file=$efivarfs_mount/$FUNCNAME-$test_guid
+       local ret=0
+
+       printf "$attrs\x00" > $file
+       [ -e $file -a -s $file ] || exit 1
+       chattr -i $file
+       : > $file
+       if [ $? != 0 ]; then
+               echo "variable file failed to accept truncation"
+               ret=1
+       elif [ -e $file -a ! -s $file ]; then
+               echo "file can be truncated to zero size"
+               ret=1
+       fi
+       rm $file || exit 1
+
+       exit $ret
+}
+
 check_prereqs
 
 rc=0
@@ -214,5 +236,6 @@ run_test test_zero_size_delete
 run_test test_open_unlink
 run_test test_valid_filenames
 run_test test_invalid_filenames
+run_test test_no_set_size
 
 exit $rc