From patchwork Thu Nov 24 07:59:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Hicks X-Patchwork-Id: 127449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id AC32C1007D7 for ; Thu, 24 Nov 2011 19:00:03 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RTUDt-0001or-AG; Thu, 24 Nov 2011 07:59:57 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1RTUDr-0001ol-Lk for kernel-team@lists.ubuntu.com; Thu, 24 Nov 2011 07:59:55 +0000 Received: from ip98-186-177-164.ks.ks.cox.net ([98.186.177.164] helo=boyd.l.tihix.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1RTUDr-0000aa-7W; Thu, 24 Nov 2011 07:59:55 +0000 From: Tyler Hicks To: kernel-team Subject: [PATCH] eCryptfs: Flush file in vma close Date: Thu, 24 Nov 2011 01:59:44 -0600 Message-Id: <1322121584-31566-1-git-send-email-tyhicks@canonical.com> X-Mailer: git-send-email 1.7.5.4 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com Dirty pages weren't being written back when an mmap'ed eCryptfs file was closed before the mapping was unmapped. Since f_ops->flush() is not called by the munmap() path, the lower file was simply being released. This patch flushes the eCryptfs file in the vm_ops->close() path. https://launchpad.net/bugs/870326 Signed-off-by: Tyler Hicks --- Upstream: 32001d6fe9ac6b0423e674a3093aa56740849f3b Discussion: https://lkml.org/lkml/2011/11/23/495 This is the upstream commit applied to ubuntu-oneiric/master-next. Linus wasn't entirely happy with the patch, but he did take it in. I agree with his criticism of the patch but this is a minimal fix to a critical bug and implementing his suggestions will take a little more time. I've been testing the patch (and using it daily) over the last week and have had 0 issues. fs/ecryptfs/file.c | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c index 4ec9eb0..0c1a652 100644 --- a/fs/ecryptfs/file.c +++ b/fs/ecryptfs/file.c @@ -139,6 +139,27 @@ out: return rc; } +static void ecryptfs_vma_close(struct vm_area_struct *vma) +{ + filemap_write_and_wait(vma->vm_file->f_mapping); +} + +static const struct vm_operations_struct ecryptfs_file_vm_ops = { + .close = ecryptfs_vma_close, + .fault = filemap_fault, +}; + +static int ecryptfs_file_mmap(struct file *file, struct vm_area_struct *vma) +{ + int rc; + + rc = generic_file_mmap(file, vma); + if (!rc) + vma->vm_ops = &ecryptfs_file_vm_ops; + + return rc; +} + struct kmem_cache *ecryptfs_file_info_cache; /** @@ -348,7 +369,7 @@ const struct file_operations ecryptfs_main_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = ecryptfs_compat_ioctl, #endif - .mmap = generic_file_mmap, + .mmap = ecryptfs_file_mmap, .open = ecryptfs_open, .flush = ecryptfs_flush, .release = ecryptfs_release,