add patch avoid-infinite-loop-when-destroying-aborted-journal
[ext4-patch-queue.git] / detect-short-encrypted-directories
blobfe33fdfbcb2f6b987159dd50d09e6ac68b25d195
1 ext4 crypto: check for too-short encrypted file names
3 An encrypted file name should never be shorter than an 16 bytes, the
4 AES block size.  The 3.10 crypto layer will oops and crash the kernel
5 if ciphertext shorter than the block size is passed to it.
7 Fortunately, in modern kernels the crypto layer will not crash the
8 kernel in this scenario, but nevertheless, it represents a corrupted
9 directory, and we should detect it and mark the file system as
10 corrupted so that e2fsck can fix this.
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 ---
14  fs/ext4/crypto_fname.c | 4 ++++
15  1 file changed, 4 insertions(+)
17 diff --git a/fs/ext4/crypto_fname.c b/fs/ext4/crypto_fname.c
18 index 7dc4eb5..86ee996 100644
19 --- a/fs/ext4/crypto_fname.c
20 +++ b/fs/ext4/crypto_fname.c
21 @@ -329,6 +329,10 @@ int _ext4_fname_disk_to_usr(struct inode *inode,
22                         return oname->len;
23                 }
24         }
25 +       if (iname->len < EXT4_CRYPTO_BLOCK_SIZE) {
26 +               EXT4_ERROR_INODE(inode, "encrypted inode too small");
27 +               return -EUCLEAN;
28 +       }
29         if (EXT4_I(inode)->i_crypt_info)
30                 return ext4_fname_decrypt(inode, iname, oname);