Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034111AbdD0PyD (ORCPT ); Thu, 27 Apr 2017 11:54:03 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48789 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1033842AbdD0Pxc (ORCPT ); Thu, 27 Apr 2017 11:53:32 -0400 From: Laurent Dufour To: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com Subject: [RFC v3 17/17] mm/spf: protect mremap() against speculative pf Date: Thu, 27 Apr 2017 17:52:56 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493308376-23851-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1493308376-23851-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17042715-0012-0000-0000-0000051A0623 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042715-0013-0000-0000-0000183D9BCE Message-Id: <1493308376-23851-18-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-04-27_14:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704270259 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1441 Lines: 46 mremap() is modifying the VMA layout and thus must be protected against the speculative page fault handler. XXX: Is the change to vma->vm_flags to set VM_ACCOUNT require the protection ? Signed-off-by: Laurent Dufour --- mm/mremap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mm/mremap.c b/mm/mremap.c index 30d7d2482eea..40c3c869dffc 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -288,6 +288,10 @@ static unsigned long move_vma(struct vm_area_struct *vma, if (!new_vma) return -ENOMEM; + write_seqcount_begin(&vma->vm_sequence); + write_seqcount_begin_nested(&new_vma->vm_sequence, + SINGLE_DEPTH_NESTING); + moved_len = move_page_tables(vma, old_addr, new_vma, new_addr, old_len, need_rmap_locks); if (moved_len < old_len) { @@ -304,6 +308,7 @@ static unsigned long move_vma(struct vm_area_struct *vma, */ move_page_tables(new_vma, new_addr, vma, old_addr, moved_len, true); + write_seqcount_end(&vma->vm_sequence); vma = new_vma; old_len = new_len; old_addr = new_addr; @@ -311,7 +316,9 @@ static unsigned long move_vma(struct vm_area_struct *vma, } else { arch_remap(mm, old_addr, old_addr + old_len, new_addr, new_addr + new_len); + write_seqcount_end(&vma->vm_sequence); } + write_seqcount_end(&new_vma->vm_sequence); /* Conceal VM_ACCOUNT so old reservation is not undone */ if (vm_flags & VM_ACCOUNT) { -- 2.7.4