aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Gstir <david@sigma-star.at>2016-12-06 17:53:54 -0500
committerTheodore Ts'o <tytso@mit.edu>2016-12-11 16:26:11 -0500
commit9e532772b4e36888584efc7a9531143bd43355b3 (patch)
treee4e9e4f064c79751cfcd8cb820e985474ff81109
parente550c16c8aab95c7996b0c864d5fcedc2c430a43 (diff)
fscrypt: Never allocate fscrypt_ctx on in-place encryption
In case of in-place encryption fscrypt_ctx was allocated but never released. Since we don't need it for in-place encryption, we skip allocating it. Fixes: 1c7dcf69eea3 ("fscrypt: Add in-place encryption mode") Signed-off-by: David Gstir <david@sigma-star.at> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--fs/crypto/crypto.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c
index d19a42f3a983..f287f76cc906 100644
--- a/fs/crypto/crypto.c
+++ b/fs/crypto/crypto.c
@@ -246,16 +246,26 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
246 246
247 BUG_ON(plaintext_len % FS_CRYPTO_BLOCK_SIZE != 0); 247 BUG_ON(plaintext_len % FS_CRYPTO_BLOCK_SIZE != 0);
248 248
249 if (inode->i_sb->s_cop->flags & FS_CFLG_INPLACE_ENCRYPTION) {
250 /* with inplace-encryption we just encrypt the page */
251 err = do_page_crypto(inode, FS_ENCRYPT, index,
252 plaintext_page, ciphertext_page,
253 plaintext_len, plaintext_offset,
254 gfp_flags);
255 if (err)
256 return ERR_PTR(err);
257
258 return ciphertext_page;
259 }
260
249 ctx = fscrypt_get_ctx(inode, gfp_flags); 261 ctx = fscrypt_get_ctx(inode, gfp_flags);
250 if (IS_ERR(ctx)) 262 if (IS_ERR(ctx))
251 return (struct page *)ctx; 263 return (struct page *)ctx;
252 264
253 if (!(inode->i_sb->s_cop->flags & FS_CFLG_INPLACE_ENCRYPTION)) { 265 /* The encryption operation will require a bounce page. */
254 /* The encryption operation will require a bounce page. */ 266 ciphertext_page = alloc_bounce_page(ctx, gfp_flags);
255 ciphertext_page = alloc_bounce_page(ctx, gfp_flags); 267 if (IS_ERR(ciphertext_page))
256 if (IS_ERR(ciphertext_page)) 268 goto errout;
257 goto errout;
258 }
259 269
260 ctx->w.control_page = plaintext_page; 270 ctx->w.control_page = plaintext_page;
261 err = do_page_crypto(inode, FS_ENCRYPT, index, 271 err = do_page_crypto(inode, FS_ENCRYPT, index,
@@ -266,11 +276,9 @@ struct page *fscrypt_encrypt_page(const struct inode *inode,
266 ciphertext_page = ERR_PTR(err); 276 ciphertext_page = ERR_PTR(err);
267 goto errout; 277 goto errout;
268 } 278 }
269 if (!(inode->i_sb->s_cop->flags & FS_CFLG_INPLACE_ENCRYPTION)) { 279 SetPagePrivate(ciphertext_page);
270 SetPagePrivate(ciphertext_page); 280 set_page_private(ciphertext_page, (unsigned long)ctx);
271 set_page_private(ciphertext_page, (unsigned long)ctx); 281 lock_page(ciphertext_page);
272 lock_page(ciphertext_page);
273 }
274 return ciphertext_page; 282 return ciphertext_page;
275 283
276errout: 284errout: