From patchwork Sun Nov 13 21:20:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 9425045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F8D36047D for ; Sun, 13 Nov 2016 21:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DB4228908 for ; Sun, 13 Nov 2016 21:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0176C2890C; Sun, 13 Nov 2016 21:29:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E1DD28908 for ; Sun, 13 Nov 2016 21:29:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935188AbcKMVVy (ORCPT ); Sun, 13 Nov 2016 16:21:54 -0500 Received: from mail.sigma-star.at ([95.130.255.111]:45998 "EHLO mail.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935056AbcKMVVx (ORCPT ); Sun, 13 Nov 2016 16:21:53 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.sigma-star.at (Postfix) with ESMTP id A314124E0002; Sun, 13 Nov 2016 22:21:49 +0100 (CET) Received: from linux.site (richard.vpn.sigmapriv.at [10.3.0.5]) by mail.sigma-star.at (Postfix) with ESMTPSA id 79AD624E0003; Sun, 13 Nov 2016 22:21:48 +0100 (CET) From: Richard Weinberger To: linux-mtd@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, dedekind1@gmail.com, adrian.hunter@intel.com, tytso@mit.edu, jaegeuk@kernel.org, david@sigma-star.at, wd@denx.de, sbabic@denx.de, dengler@linutronix.de, ebiggers@google.com, mhalcrow@google.com, hch@infradead.org, Richard Weinberger Subject: [PATCH 02/29] fscrypt: Allow fscrypt_decrypt_page() to function with non-writeback pages Date: Sun, 13 Nov 2016 22:20:45 +0100 Message-Id: <1479072072-6844-3-git-send-email-richard@nod.at> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1479072072-6844-1-git-send-email-richard@nod.at> References: <1479072072-6844-1-git-send-email-richard@nod.at> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: David Gstir Some filesystem might pass pages which do not have page->mapping->host set to the encrypted inode. We want the caller to explicitly pass the corresponding inode. Signed-off-by: David Gstir Signed-off-by: Richard Weinberger --- fs/crypto/crypto.c | 11 ++++++----- fs/ext4/inode.c | 5 +++-- include/linux/fscrypto.h | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fs/crypto/crypto.c b/fs/crypto/crypto.c index f38dc8aac2fe..222a70520565 100644 --- a/fs/crypto/crypto.c +++ b/fs/crypto/crypto.c @@ -271,7 +271,8 @@ EXPORT_SYMBOL(fscrypt_encrypt_page); /** * f2crypt_decrypt_page() - Decrypts a page in-place - * @page: The page to decrypt. Must be locked. + * @inode: The encrypted inode to decrypt. + * @page: The page to decrypt. Must be locked. * * Decrypts page in-place using the ctx encryption context. * @@ -279,12 +280,12 @@ EXPORT_SYMBOL(fscrypt_encrypt_page); * * Return: Zero on success, non-zero otherwise. */ -int fscrypt_decrypt_page(struct page *page) +int fscrypt_decrypt_page(struct inode *inode, struct page *page) { BUG_ON(!PageLocked(page)); - return do_page_crypto(page->mapping->host, - FS_DECRYPT, page->index, page, page, GFP_NOFS); + return do_page_crypto(inode, FS_DECRYPT, page->index, page, page, + GFP_NOFS); } EXPORT_SYMBOL(fscrypt_decrypt_page); @@ -419,7 +420,7 @@ static void completion_pages(struct work_struct *work) bio_for_each_segment_all(bv, bio, i) { struct page *page = bv->bv_page; - int ret = fscrypt_decrypt_page(page); + int ret = fscrypt_decrypt_page(page->mapping->host, page); if (ret) { WARN_ON_ONCE(1); diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 9c064727ed62..4b7b842ec024 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1166,7 +1166,7 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, if (unlikely(err)) page_zero_new_buffers(page, from, to); else if (decrypt) - err = fscrypt_decrypt_page(page); + err = fscrypt_decrypt_page(page->mapping->host, page); return err; } #endif @@ -3743,7 +3743,8 @@ static int __ext4_block_zero_page_range(handle_t *handle, /* We expect the key to be set. */ BUG_ON(!fscrypt_has_encryption_key(inode)); BUG_ON(blocksize != PAGE_SIZE); - WARN_ON_ONCE(fscrypt_decrypt_page(page)); + WARN_ON_ONCE(fscrypt_decrypt_page(page->mapping->host, + page)); } } if (ext4_should_journal_data(inode)) { diff --git a/include/linux/fscrypto.h b/include/linux/fscrypto.h index 5a65b0e3773f..8be8e9657c63 100644 --- a/include/linux/fscrypto.h +++ b/include/linux/fscrypto.h @@ -249,7 +249,7 @@ int fscrypt_initialize(void); extern struct fscrypt_ctx *fscrypt_get_ctx(struct inode *, gfp_t); extern void fscrypt_release_ctx(struct fscrypt_ctx *); extern struct page *fscrypt_encrypt_page(struct inode *, struct page *, gfp_t); -extern int fscrypt_decrypt_page(struct page *); +extern int fscrypt_decrypt_page(struct inode *, struct page *); extern void fscrypt_decrypt_bio_pages(struct fscrypt_ctx *, struct bio *); extern void fscrypt_pullback_bio_page(struct page **, bool); extern void fscrypt_restore_control_page(struct page *); @@ -298,7 +298,8 @@ static inline struct page *fscrypt_notsupp_encrypt_page(struct inode *i, return ERR_PTR(-EOPNOTSUPP); } -static inline int fscrypt_notsupp_decrypt_page(struct page *p) +static inline int fscrypt_notsupp_decrypt_page(struct inode *i, + struct page *p) { return -EOPNOTSUPP; }