Skip to content

Commit 9b4bb82

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
ecryptfs: Pass the folio index to crypt_extent()
We need to pass pages, not folios, to crypt_extent() as we may be working with a plain page rather than a folio. But we need to know the index in the file, so pass it in from the caller. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Link: https://lore.kernel.org/r/20241025190822.1319162-11-willy@infradead.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent bf64913 commit 9b4bb82

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

fs/ecryptfs/crypto.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat,
340340
* encryption operation
341341
* @dst_page: The page to write the result into
342342
* @src_page: The page to read from
343+
* @page_index: The offset in the file (in units of PAGE_SIZE)
343344
* @extent_offset: Page extent offset for use in generating IV
344345
* @op: ENCRYPT or DECRYPT to indicate the desired operation
345346
*
@@ -350,9 +351,9 @@ static loff_t lower_offset_for_page(struct ecryptfs_crypt_stat *crypt_stat,
350351
static int crypt_extent(struct ecryptfs_crypt_stat *crypt_stat,
351352
struct page *dst_page,
352353
struct page *src_page,
354+
pgoff_t page_index,
353355
unsigned long extent_offset, int op)
354356
{
355-
pgoff_t page_index = op == ENCRYPT ? src_page->index : dst_page->index;
356357
loff_t extent_base;
357358
char extent_iv[ECRYPTFS_MAX_IV_BYTES];
358359
struct scatterlist src_sg, dst_sg;
@@ -432,7 +433,8 @@ int ecryptfs_encrypt_page(struct folio *folio)
432433
extent_offset < (PAGE_SIZE / crypt_stat->extent_size);
433434
extent_offset++) {
434435
rc = crypt_extent(crypt_stat, enc_extent_page,
435-
folio_page(folio, 0), extent_offset, ENCRYPT);
436+
folio_page(folio, 0), folio->index,
437+
extent_offset, ENCRYPT);
436438
if (rc) {
437439
printk(KERN_ERR "%s: Error encrypting extent; "
438440
"rc = [%d]\n", __func__, rc);
@@ -505,8 +507,8 @@ int ecryptfs_decrypt_page(struct folio *folio)
505507
extent_offset < (PAGE_SIZE / crypt_stat->extent_size);
506508
extent_offset++) {
507509
struct page *page = folio_page(folio, 0);
508-
rc = crypt_extent(crypt_stat, page, page,
509-
extent_offset, DECRYPT);
510+
rc = crypt_extent(crypt_stat, page, page, folio->index,
511+
extent_offset, DECRYPT);
510512
if (rc) {
511513
printk(KERN_ERR "%s: Error decrypting extent; "
512514
"rc = [%d]\n", __func__, rc);

0 commit comments

Comments
 (0)