From patchwork Wed Sep 26 03:18:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Aneesh Kumar K.V" X-Patchwork-Id: 10615181 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 69C9815A6 for ; Wed, 26 Sep 2018 03:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 592932ABAE for ; Wed, 26 Sep 2018 03:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4AB1B2ABBF; Wed, 26 Sep 2018 03:19:48 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D55AB2ABAE for ; Wed, 26 Sep 2018 03:19:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EC228E0002; Tue, 25 Sep 2018 23:19:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C26E8E0001; Tue, 25 Sep 2018 23:19:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 48B9D8E0002; Tue, 25 Sep 2018 23:19:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 1AB518E0001 for ; Tue, 25 Sep 2018 23:19:46 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id s69-v6so30088352ota.13 for ; Tue, 25 Sep 2018 20:19:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=WBR/pk5FOYNVScrUiKhKoCNuxNFpAXJF3clAW6uvwY4=; b=KL5yMEPermYXIl4hBHJ/mDqeZHetUVd6BcTGjmUp3aXko0ZH971N1H/6q9KVTE974U mwJYWGVlHsSYisJ3sBGT/Uo3tSi2SIpcsJPUeG8GHY3/Z+f8s71folvYayuyfSnCYIw2 az5odZEAXdmyeOS/eowsu0IOfgamSAV+DT44OHB5M97kuRozeghOrk1u4xNAkjrSk+gk Y77xcwiBITcMXF8KrPstEBrCAFJU1+xUfev9E8wmFzJnE9icIdZ2Hz+oPxrgrT98un8c EofXps6R66M/WXoNGGLdp47ja9l1L/wkp/C0OSsdrcmQpLYKNfS5NwEgkWUawIRTrCqk Slpw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: ABuFfogLZcO1rQEkXBULnXeJcQxjE7kzpIoPyY10+oP5yl/VA85Jgp+2 a7l7hBY53COzXdUw1nTCARdvLyHuAtMY9t7mmuupyVnvxGaYYGqJpyLhmQ7nP+Fm8zH67ew939s N5zspO/VJ/9azDykMJUmWBDT/GlAWxKQlDgnVht57vQDGG34IlT2KNb7ZG4v4/5qvWQ== X-Received: by 2002:aca:5d86:: with SMTP id r128-v6mr517362oib.243.1537931985782; Tue, 25 Sep 2018 20:19:45 -0700 (PDT) X-Google-Smtp-Source: ACcGV63RlLqvbX521wssQjM1EPXtNpsPT7dVrn+WwMR2/SUI5Tr59O6M5p4aESopUf4Uv/bc/UKv X-Received: by 2002:aca:5d86:: with SMTP id r128-v6mr517341oib.243.1537931984719; Tue, 25 Sep 2018 20:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537931984; cv=none; d=google.com; s=arc-20160816; b=sULaP+pYF6dfgseqMLxu93i9TtuO4IR1VUOY5OUATCCnvS4xicKltWQg12LVnmrGhL iiMGs8cmgFzg2cOHvXi4Zb6pq+ZtDnXSjujsgdmN/0gSBWcnN4xIFY7GfDsb182iYuA+ OPPTU1GEqCWpKitmQbu9sCbNm26Thv693rrx3aas4a8xbgrcBMUz3spndYFvhrzFTHld qWG+LGN24H5c7VAH2xEjpfB/mpfr8bfpU9mFvggXLsg2lNKmh2S/jlNJ1StY6ASBTOG0 uHiA4j8atqSCkqdVPrZh/dOuNSoBAWMpoGwrrqj6botqC8u5YrZ7wo44wzMowE/w92q8 XQQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from; bh=WBR/pk5FOYNVScrUiKhKoCNuxNFpAXJF3clAW6uvwY4=; b=YirIgp4U/mG+9KuRgBHjubz4kkTXgZ0enysFPuAoTrAuePR14jlsdxfgK3k/TRT4er Wd/TSgAQrdGiAirbg2Updm+B9My0JWqBwLpVTrM80g0NoeyWUC2hhj4UrbyVVgXyQcFW LISsymPVaCA9KqTg/pxrngPttbsLycwfNGvC6uo5REVbzXqZOosp4UZm9TMexDVLlFG9 Ga/3OAdNXA4B4BtUTd5C7OL8ok3jboUMI9oDv5TVQI0mxZBa0tI44Ytq75kmE0Q2btgZ v1fT049xAi26KIcN/9he8Cb+DB5q4KvMWn9+CV5Mt6R5lgj4RMhmYBYh6WwvbrlFqhBK rgCg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id n63-v6si1667221oif.143.2018.09.25.20.19.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Sep 2018 20:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.158.5 as permitted sender) smtp.mailfrom=aneesh.kumar@linux.ibm.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8Q3Jgce144629 for ; Tue, 25 Sep 2018 23:19:44 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 2mqye6nabx-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 25 Sep 2018 23:19:42 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Sep 2018 21:19:07 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 25 Sep 2018 21:19:05 -0600 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8Q3J4gw49807568 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 25 Sep 2018 20:19:04 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 874B0C605B; Tue, 25 Sep 2018 21:19:04 -0600 (MDT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91086C605A; Tue, 25 Sep 2018 21:19:02 -0600 (MDT) Received: from skywalker.ibmuc.com (unknown [9.199.41.211]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Tue, 25 Sep 2018 21:19:02 -0600 (MDT) From: "Aneesh Kumar K.V" To: akpm@linux-foundation.org, "Kirill A . Shutemov" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Aneesh Kumar K.V" Subject: [PATCH V2] mm: Recheck page table entry with page table lock held Date: Wed, 26 Sep 2018 08:48:58 +0530 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 18092603-0012-0000-0000-000016BBD39D X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009772; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000267; SDB=6.01093723; UDB=6.00565314; IPR=6.00873760; MB=3.00023505; MTD=3.00000008; XFM=3.00000015; UTC=2018-09-26 03:19:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18092603-0013-0000-0000-00005489113B Message-Id: <20180926031858.9692-1-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-26_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=831 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809260033 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We clear the pte temporarily during read/modify/write update of the pte. If we take a page fault while the pte is cleared, the application can get SIGBUS. One such case is with remap_pfn_range without a backing vm_ops->fault callback. do_fault will return SIGBUS in that case. cpu 0 cpu1 mprotect() ptep_modify_prot_start()/pte cleared. . . page fault. . . prep_modify_prot_commit() Fix this by taking page table lock and rechecking for pte_none. Signed-off-by: Aneesh Kumar K.V Acked-by: Kirill A. Shutemov --- V1: * update commit message. mm/memory.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index c467102a5cbc..c2f933184303 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3745,10 +3745,33 @@ static vm_fault_t do_fault(struct vm_fault *vmf) struct vm_area_struct *vma = vmf->vma; vm_fault_t ret; - /* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */ - if (!vma->vm_ops->fault) - ret = VM_FAULT_SIGBUS; - else if (!(vmf->flags & FAULT_FLAG_WRITE)) + /* + * The VMA was not fully populated on mmap() or missing VM_DONTEXPAND + */ + if (!vma->vm_ops->fault) { + + /* + * pmd entries won't be marked none during a R/M/W cycle. + */ + if (unlikely(pmd_none(*vmf->pmd))) + ret = VM_FAULT_SIGBUS; + else { + vmf->ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); + /* + * Make sure this is not a temporary clearing of pte + * by holding ptl and checking again. A R/M/W update + * of pte involves: take ptl, clearing the pte so that + * we don't have concurrent modification by hardware + * followed by an update. + */ + spin_lock(vmf->ptl); + if (unlikely(pte_none(*vmf->pte))) + ret = VM_FAULT_SIGBUS; + else + ret = VM_FAULT_NOPAGE; + spin_unlock(vmf->ptl); + } + } else if (!(vmf->flags & FAULT_FLAG_WRITE)) ret = do_read_fault(vmf); else if (!(vma->vm_flags & VM_SHARED)) ret = do_cow_fault(vmf);