From patchwork Thu Jun 7 14:38:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu-cheng Yu X-Patchwork-Id: 10452319 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 3B41F6053F for ; Thu, 7 Jun 2018 14:42:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 29621294DB for ; Thu, 7 Jun 2018 14:42:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DFD3294DF; Thu, 7 Jun 2018 14:42:11 +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 BF60D29508 for ; Thu, 7 Jun 2018 14:42:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E1486B028F; Thu, 7 Jun 2018 10:41:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 797C76B0291; Thu, 7 Jun 2018 10:41:37 -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 529E46B0292; Thu, 7 Jun 2018 10:41:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id E73136B028F for ; Thu, 7 Jun 2018 10:41:36 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id j25-v6so3547146pfi.9 for ; Thu, 07 Jun 2018 07:41:36 -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:in-reply-to:references; bh=jJ8DOWc436V4Cp1Pi8rm2EPAeVuEbsxoDja0yAypIH4=; b=k9ZdJrnkf4Lj6wFidFR+OX5rouUjxP8MnTEpiH7LBBSz8UnQobUMmRmnbmcT+UuqI6 R6WHPoLx0TXm876GXN6/cH/gFB0IHo4xeVMbgharHHGJSA8658410eIa4ovLVP+oc1FU pJllGlrddCXvIfnhNkXPaW2/wRXGhji+H5K4E7DsQsJi/6AJOOX82yrmCPE/HT8XqppE YOyZz/rmzeDD+RqdHuxoMwFOLxKEHrAMD0BQDSOWwZ97RVp0rsivlHt78QubXO2M3PBZ LRVUoKrxkXIys3c4YB6nVECrIUOc8ks0ASK0Ask/c4pmR9JndQJ7BoR7thvpmVfWIJDU srBw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E2jWa42yTVrvhgD3TrR6bYMnunlnZLZB473DwI7tdH6xyJ/CP2B clewTOQfAd6Rvk7dV6HXBcTtQ2oLOMBLDwa2Qgs/geQdQ16XgbChVUrDsTLE5U2bNeQNm3Z0/gO tJrv59m/2fmaE1GgxNn4jTiVB2s9HpIVyMItV80WLj4rOlTEZqk9yLw09FlMn2Mvo9A== X-Received: by 2002:a62:be0a:: with SMTP id l10-v6mr2033629pff.180.1528382496633; Thu, 07 Jun 2018 07:41:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK51S1Z5OvqavpKnhhtMvc6INtoiDZpweGHdznEfLaZ4IG2p48KBd9kHvtzb6uuoMuZJiVY X-Received: by 2002:a62:be0a:: with SMTP id l10-v6mr2033590pff.180.1528382495898; Thu, 07 Jun 2018 07:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382495; cv=none; d=google.com; s=arc-20160816; b=bMJDLBeort3HLe1vbHAcnRx8AgXSLpqmgtLCqpQcjoiHvHwySURt/zmFKACYhJQwYY HghZhfwSHE1qSlWlWknVFhdcJBb6+yEHPKWZkNTIlbm2DDYXQQsCU1WzaSfLaxD0QgJE MqIlfzMie/wjKiKiZeqcl5BZ6b6xK9gGpO9ArKEXLfCPHvDKU3zzbKhPT45wYpplD0QE P3ZcHwgctkHp2DNOCjVyoCnXNt1j8T0A7Qo+2zBaPMYq/4EQC9nhCEVUYLOWAImpQBRQ sa/IdS9AScfqDZ8srYJhn4UOWn5QlvfgnZSildbsuykYo0VL/Qvlsu2XTScc2KeylpNh CXEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jJ8DOWc436V4Cp1Pi8rm2EPAeVuEbsxoDja0yAypIH4=; b=jdndygdB6VMuyAR6MrNg5083FW3T5DcnyTjHP+WpZmuEEEbp+aZscZWWOfA+5DydXb sKZFChZ0f5JF2V6qFvoi8i998N22h0NZ90m9xupwpUAprgudIXG1JZlxmy+8kHXnt6dL fjDF0/hW6OEn71/syx6+fW60OVuzukI/b2DPCwGXYj6E/qF8NhnjkauqLGQqZFPNaBX6 yct4/6S2rDqAj7WsUd1gUrJCKKx4r84w8tt93MwkX4mhr5ezXJzzfqPh4Q03HAeP5ciV lCtCmOrLNpslgJceQ6uJ0jqWUYaO5BxhPa1IkesAgE1FC5i7MFOXXuHpRDYpfLbrDGvz TVxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga05.intel.com (mga05.intel.com. [192.55.52.43]) by mx.google.com with ESMTPS id i74-v6si8716254pgc.188.2018.06.07.07.41.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 07:41:35 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.43 as permitted sender) client-ip=192.55.52.43; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 192.55.52.43 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jun 2018 07:41:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="62632664" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga001.jf.intel.com with ESMTP; 07 Jun 2018 07:41:34 -0700 From: Yu-cheng Yu To: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H.J. Lu" , Vedvyas Shanbhogue , "Ravi V. Shankar" , Dave Hansen , Andy Lutomirski , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , Mike Kravetz Cc: Yu-cheng Yu Subject: [PATCH 10/10] mm: Prevent munmap and remap_file_pages of shadow stack Date: Thu, 7 Jun 2018 07:38:07 -0700 Message-Id: <20180607143807.3611-11-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180607143807.3611-1-yu-cheng.yu@intel.com> References: <20180607143807.3611-1-yu-cheng.yu@intel.com> 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 Signed-off-by: Yu-cheng Yu --- mm/mmap.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index fc41c0543d7f..e7d1fcb7ec58 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2810,6 +2810,16 @@ EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { + struct vm_area_struct *vma; + + /* Do not munmap shadow stack */ + down_read(¤t->mm->mmap_sem); + vma = find_vma(current->mm, addr); + if (vma && (vma->vm_flags & VM_SHSTK)) { + up_read(¤t->mm->mmap_sem); + return -EINVAL; + } + up_read(¤t->mm->mmap_sem); profile_munmap(addr); return vm_munmap(addr, len); } @@ -2851,6 +2861,9 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, if (!vma || !(vma->vm_flags & VM_SHARED)) goto out; + if (vma->vm_flags & VM_SHSTK) + goto out; + if (start < vma->vm_start) goto out;