From patchwork Wed Dec 13 03:58:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yan, Zheng" X-Patchwork-Id: 10109181 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 C177B60327 for ; Wed, 13 Dec 2017 03:59:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE4CF28CC1 for ; Wed, 13 Dec 2017 03:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1F642903F; Wed, 13 Dec 2017 03:59:02 +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 5735B28CC1 for ; Wed, 13 Dec 2017 03:59:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752077AbdLMD6q (ORCPT ); Tue, 12 Dec 2017 22:58:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57372 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751499AbdLMD6p (ORCPT ); Tue, 12 Dec 2017 22:58:45 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C253C058EC2; Wed, 13 Dec 2017 03:58:45 +0000 (UTC) Received: from ovpn-12-21.pek2.redhat.com (ovpn-12-21.pek2.redhat.com [10.72.12.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90AAB7C85D; Wed, 13 Dec 2017 03:58:41 +0000 (UTC) From: "Yan, Zheng" To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, ceph-devel@vger.kernel.org, linux-ext4@vger.kernel.org Cc: akpm@linux-foundation.org, viro@zeniv.linux.org.uk, jlayton@redhat.com, "Yan, Zheng" Subject: [PATCH] mm: save current->journal_info before calling fault/page_mkwrite Date: Wed, 13 Dec 2017 11:58:36 +0800 Message-Id: <20171213035836.916-1-zyan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 13 Dec 2017 03:58:45 +0000 (UTC) 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 We recently got an Oops report: BUG: unable to handle kernel NULL pointer dereference at (null) IP: jbd2__journal_start+0x38/0x1a2 [...] Call Trace: ext4_page_mkwrite+0x307/0x52b _ext4_get_block+0xd8/0xd8 do_page_mkwrite+0x6e/0xd8 handle_mm_fault+0x686/0xf9b mntput_no_expire+0x1f/0x21e __do_page_fault+0x21d/0x465 dput+0x4a/0x2f7 page_fault+0x22/0x30 copy_user_generic_string+0x2c/0x40 copy_page_to_iter+0x8c/0x2b8 generic_file_read_iter+0x26e/0x845 timerqueue_del+0x31/0x90 ceph_read_iter+0x697/0xa33 [ceph] hrtimer_cancel+0x23/0x41 futex_wait+0x1c8/0x24d get_futex_key+0x32c/0x39a __vfs_read+0xe0/0x130 vfs_read.part.1+0x6c/0x123 handle_mm_fault+0x831/0xf9b __fget+0x7e/0xbf SyS_read+0x4d/0xb5 The reason is that page fault can happen when one filesystem copies data from/to userspace, the filesystem may set current->journal_info. If the userspace memory is mapped to a file on another filesystem, the later filesystem may also want to use current->journal_info. Signed-off-by: "Yan, Zheng" --- mm/memory.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 5eb3d2524bdc..e51383cd49bf 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2347,12 +2347,22 @@ static int do_page_mkwrite(struct vm_fault *vmf) { int ret; struct page *page = vmf->page; + void *old_journal_info = current->journal_info; unsigned int old_flags = vmf->flags; + /* + * If the fault happens during read_iter() copies data to + * userspace, filesystem may have set current->journal_info. + * If the userspace memory is mapped to a file on another + * filesystem, page_mkwrite() of the later filesystem may + * want to access/modify current->journal_info. + */ + current->journal_info = NULL; vmf->flags = FAULT_FLAG_WRITE|FAULT_FLAG_MKWRITE; ret = vmf->vma->vm_ops->page_mkwrite(vmf); - /* Restore original flags so that caller is not surprised */ + /* Restore original journal_info and flags */ + current->journal_info = old_journal_info; vmf->flags = old_flags; if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE))) return ret; @@ -3191,9 +3201,20 @@ static int do_anonymous_page(struct vm_fault *vmf) static int __do_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + void *old_journal_info = current->journal_info; int ret; + /* + * If the fault happens during write_iter() copies data from + * userspace, filesystem may have set current->journal_info. + * If the userspace memory is mapped to a file on another + * filesystem, fault handler of the later filesystem may want + * to access/modify current->journal_info. + */ + current->journal_info = NULL; ret = vma->vm_ops->fault(vmf); + /* Restore original journal_info */ + current->journal_info = old_journal_info; if (unlikely(ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE | VM_FAULT_RETRY | VM_FAULT_DONE_COW))) return ret;