diff options
Diffstat (limited to 'fs/crypto')
-rw-r--r-- | fs/crypto/crypto.c | 15 | ||||
-rw-r--r-- | fs/crypto/policy.c | 4 |
2 files changed, 12 insertions, 7 deletions
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index 61057b7dbddb..98f87fe8f186 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c | |||
@@ -151,7 +151,10 @@ static int do_page_crypto(struct inode *inode, | |||
151 | struct page *src_page, struct page *dest_page, | 151 | struct page *src_page, struct page *dest_page, |
152 | gfp_t gfp_flags) | 152 | gfp_t gfp_flags) |
153 | { | 153 | { |
154 | u8 xts_tweak[FS_XTS_TWEAK_SIZE]; | 154 | struct { |
155 | __le64 index; | ||
156 | u8 padding[FS_XTS_TWEAK_SIZE - sizeof(__le64)]; | ||
157 | } xts_tweak; | ||
155 | struct skcipher_request *req = NULL; | 158 | struct skcipher_request *req = NULL; |
156 | DECLARE_FS_COMPLETION_RESULT(ecr); | 159 | DECLARE_FS_COMPLETION_RESULT(ecr); |
157 | struct scatterlist dst, src; | 160 | struct scatterlist dst, src; |
@@ -171,17 +174,15 @@ static int do_page_crypto(struct inode *inode, | |||
171 | req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, | 174 | req, CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP, |
172 | page_crypt_complete, &ecr); | 175 | page_crypt_complete, &ecr); |
173 | 176 | ||
174 | BUILD_BUG_ON(FS_XTS_TWEAK_SIZE < sizeof(index)); | 177 | BUILD_BUG_ON(sizeof(xts_tweak) != FS_XTS_TWEAK_SIZE); |
175 | memcpy(xts_tweak, &index, sizeof(index)); | 178 | xts_tweak.index = cpu_to_le64(index); |
176 | memset(&xts_tweak[sizeof(index)], 0, | 179 | memset(xts_tweak.padding, 0, sizeof(xts_tweak.padding)); |
177 | FS_XTS_TWEAK_SIZE - sizeof(index)); | ||
178 | 180 | ||
179 | sg_init_table(&dst, 1); | 181 | sg_init_table(&dst, 1); |
180 | sg_set_page(&dst, dest_page, PAGE_SIZE, 0); | 182 | sg_set_page(&dst, dest_page, PAGE_SIZE, 0); |
181 | sg_init_table(&src, 1); | 183 | sg_init_table(&src, 1); |
182 | sg_set_page(&src, src_page, PAGE_SIZE, 0); | 184 | sg_set_page(&src, src_page, PAGE_SIZE, 0); |
183 | skcipher_request_set_crypt(req, &src, &dst, PAGE_SIZE, | 185 | skcipher_request_set_crypt(req, &src, &dst, PAGE_SIZE, &xts_tweak); |
184 | xts_tweak); | ||
185 | if (rw == FS_DECRYPT) | 186 | if (rw == FS_DECRYPT) |
186 | res = crypto_skcipher_decrypt(req); | 187 | res = crypto_skcipher_decrypt(req); |
187 | else | 188 | else |
diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c index ed115acb5dee..6865663aac69 100644 --- a/fs/crypto/policy.c +++ b/fs/crypto/policy.c | |||
@@ -109,6 +109,8 @@ int fscrypt_process_policy(struct file *filp, | |||
109 | if (ret) | 109 | if (ret) |
110 | return ret; | 110 | return ret; |
111 | 111 | ||
112 | inode_lock(inode); | ||
113 | |||
112 | if (!inode_has_encryption_context(inode)) { | 114 | if (!inode_has_encryption_context(inode)) { |
113 | if (!S_ISDIR(inode->i_mode)) | 115 | if (!S_ISDIR(inode->i_mode)) |
114 | ret = -EINVAL; | 116 | ret = -EINVAL; |
@@ -127,6 +129,8 @@ int fscrypt_process_policy(struct file *filp, | |||
127 | ret = -EINVAL; | 129 | ret = -EINVAL; |
128 | } | 130 | } |
129 | 131 | ||
132 | inode_unlock(inode); | ||
133 | |||
130 | mnt_drop_write_file(filp); | 134 | mnt_drop_write_file(filp); |
131 | return ret; | 135 | return ret; |
132 | } | 136 | } |