From patchwork Thu Sep 20 09:24:08 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: 10607225 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 AD2EC14BD for ; Thu, 20 Sep 2018 09:25:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C3A92CC06 for ; Thu, 20 Sep 2018 09:25:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F6762CDC1; Thu, 20 Sep 2018 09:25:28 +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 07B532CC06 for ; Thu, 20 Sep 2018 09:25:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 942A78E0002; Thu, 20 Sep 2018 05:25:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8CBFB8E0001; Thu, 20 Sep 2018 05:25:26 -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 746238E0002; Thu, 20 Sep 2018 05:25:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 48AA78E0001 for ; Thu, 20 Sep 2018 05:25:26 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id c46-v6so7734541otd.12 for ; Thu, 20 Sep 2018 02:25:26 -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=rWYAL1PjbiggQjsl4AtCgwgPHoq0cQUQL1h3UBbv5gE=; b=IMLi06LbxZpsWuVMePnhqbUCmnXRFLjUw3AzobRpq4ahyalSMlrY61CdiFJeq9wZyN 9qvTiheKDHHpbZ96PnY0ODqs8pONcEraoB8jRcp3UPSO2wY9REPRzyvibLl7X/nAB8ur Y+l89OoZAD0sQqwDORyz8UGiBFnVWgMESBQ1GItzg83xGdM8f+XfrVbQbkO20lf+Jzv7 QTA6b6FFEpLxTWgnRKKu3kyBKH+oHWDmqbfnAmTGWpOARzjtx/eT3Pb1XQEWdgw3Ar61 u2wiURH8IclmavJVonkw27cXZ6f8/UEEvJntjD0Su1YRrgmmQzafPQ2KDAnWPa25AydC 833w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 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: APzg51DwOiCfznDz7meeUzUZryWC8ZbBI0dAMEw+MezgK2k3s8lSXHCi A3I4aLC9/DosS96z36Yvn/mBZWRHvrMaG8th/JMOwVDTfQkbqpXK7FlQbOSKLMULiTmpHgiYtHC uaz7OKmeYzYBeawTtrxC0/7rdIbr9mrndTIO+Th+/GmP8CphWx0GE0xZPUG9bx83kYQ== X-Received: by 2002:aca:5c85:: with SMTP id q127-v6mr945405oib.127.1537435525970; Thu, 20 Sep 2018 02:25:25 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYT2BxKjWyVCpfmo0hzofLMoTavsexaWVVtwfrb6WlYstQr59tithKJOiBvd0FUWUA40aXL X-Received: by 2002:aca:5c85:: with SMTP id q127-v6mr945395oib.127.1537435525070; Thu, 20 Sep 2018 02:25:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537435525; cv=none; d=google.com; s=arc-20160816; b=oT5AUi4KsTLtlVW3dlfaTVWp1/SEZ5G8Ayk7cn3F9xMUG0e1fjT3XXFrSxqWw8l+uC YK/2u0mi1Klc0Wuskyg+Gwal1sOC6vhz4II/CD9c8PW+ugjKHXhMnNS8scOb4l1zeMKC Er8orgWxRvJcaQKW4TCI9TregXlwVBnhBfSKFtcLfL8RJjxRePp/pTRYo77dgiuO/xPF 7k1c6ErPndH59wbeUQ66B6AaaaMMbWk8ddukLB4QkK09v3CCz74u2Np3ekeGpCBSBhnY tZZc1gZMxEJkG37z3JG0JDQ9QUiqY/muKmw9wopueaS/gGEig35sXa1nccT2tvm/wU5c RWFQ== 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=rWYAL1PjbiggQjsl4AtCgwgPHoq0cQUQL1h3UBbv5gE=; b=rGng/JOlbtF8c32xu5zwbuHKlBd4eKPY7IiXqEPmqzOIpGCVXPRotswgja1AAujb8v Y6VkPSwJc7JpZ3BxuDHdHdfx04PsiKJQcSde5ywpkjj8yXWYVxAGyEyq8bioCGSTaDt0 XgiYVuAIWZuNt5gbvpi4MhIdydWked3e1HgnZRfRhaubb3Z6XFTNCvq/MoMc/FevkoxD k8tzfJnr/pW+i5teTT2JyHu2GF3lAYgvRpghJtRTBBeEPcBP2Lb8yKzDfj/k202SEgFp 7H6Nnj8q0jKoSsL+IpGaOTOvaIA/4zzJxY/bbSWBKQq3byHJWr+ToGWvSYZDHNVEcmqY NYMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 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 (mx0a-001b2d01.pphosted.com. [148.163.156.1]) by mx.google.com with ESMTPS id u207-v6si10717113oia.91.2018.09.20.02.25.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 02:25:25 -0700 (PDT) Received-SPF: pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 as permitted sender) client-ip=148.163.156.1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of aneesh.kumar@linux.ibm.com designates 148.163.156.1 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 (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8K9J7KL098541 for ; Thu, 20 Sep 2018 05:25:23 -0400 Received: from e12.ny.us.ibm.com (e12.ny.us.ibm.com [129.33.205.202]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mm5m1rnqa-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 20 Sep 2018 05:25:23 -0400 Received: from localhost by e12.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 20 Sep 2018 05:25:22 -0400 Received: from b01cxnp23032.gho.pok.ibm.com (9.57.198.27) by e12.ny.us.ibm.com (146.89.104.199) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 20 Sep 2018 05:25:21 -0400 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23032.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8K9PK5M27525130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 20 Sep 2018 09:25:20 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4EA3CAC05F; Thu, 20 Sep 2018 05:24:54 -0400 (EDT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 520F3AC059; Thu, 20 Sep 2018 05:24:52 -0400 (EDT) Received: from skywalker.ibmuc.com (unknown [9.85.86.4]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 20 Sep 2018 05:24:51 -0400 (EDT) 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] mm: Recheck page table entry with page table lock held Date: Thu, 20 Sep 2018 14:54:08 +0530 X-Mailer: git-send-email 2.17.1 X-TM-AS-GCONF: 00 x-cbid: 18092009-0060-0000-0000-000002B3009F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009739; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000266; SDB=6.01090986; UDB=6.00563664; IPR=6.00871009; MB=3.00023408; MTD=3.00000008; XFM=3.00000015; UTC=2018-09-20 09:25:22 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18092009-0061-0000-0000-0000469302D3 Message-Id: <20180920092408.9128-1-aneesh.kumar@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-20_06:,, 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=876 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1809200096 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. Fix this by taking page table lock and rechecking for pte_none. Signed-off-by: Aneesh Kumar K.V --- 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);