summaryrefslogtreecommitdiff
path: root/tests/ext4/024
blob: 11b335f0ba62611d50ae985208dc60fea1c79225 (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
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Google, Inc.  All Rights Reserved.
#
# FS QA Test ext4/024
#
# Regression test for 0d06863f903a ("ext4: don't BUG when truncating encrypted
# inodes on the orphan list").
#
. ./common/preamble
_begin_fstest auto quick encrypt dangerous

# get standard environment and checks
. ./common/encrypt

# real QA test starts here
_supported_fs ext4
_require_scratch_encryption
_require_command "$KEYCTL_PROG" keyctl

_init_session_keyring

#
# Create an encrypted file whose size is not a multiple of the filesystem block
# size, then add it to the orphan list.
#
# We create the encrypted file normally, rather than use debugfs to force the
# inode flags to ENCRYPT|EXTENTS as done in the example listed in the commit
# message of the kernel fix, because forcing the inode flags is incompatible
# with some MKFS_OPTIONS such as inline_data or ^extents.
#
# This choice does, however, have the disadvantage that this test won't detect
# the bug in as many situations, such as in kernels configured without
# encryption support.
#
_scratch_mkfs_encrypted &>>$seqres.full
_scratch_mount
mkdir $SCRATCH_MNT/edir
keydesc=$(_generate_session_encryption_key)
_set_encpolicy $SCRATCH_MNT/edir $keydesc
echo foo > $SCRATCH_MNT/edir/file
inum=$(stat -c '%i' $SCRATCH_MNT/edir/file)
_scratch_unmount
debugfs -w -R "set_super_value s_last_orphan $inum" $SCRATCH_DEV &>>$seqres.full

# Try to mount the filesystem.  This would hit a BUG() in fs/ext4/inode.c.
_try_scratch_mount

# success, all done
echo "Didn't crash!"
status=0
exit