From patchwork Fri Sep 21 15:03:49 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: 10610281 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 4FC4415A6 for ; Fri, 21 Sep 2018 15:10:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3FBCF2E460 for ; Fri, 21 Sep 2018 15:10:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D39C2E4BE; Fri, 21 Sep 2018 15:10:35 +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 2945C2E460 for ; Fri, 21 Sep 2018 15:10:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A8C08E001C; Fri, 21 Sep 2018 11:10:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2591D8E0019; Fri, 21 Sep 2018 11:10:27 -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 0FD408E001E; Fri, 21 Sep 2018 11:10:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id B8F888E001C for ; Fri, 21 Sep 2018 11:10:26 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id z18-v6so6712210pfe.19 for ; Fri, 21 Sep 2018 08:10: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:in-reply-to:references; bh=AOHK0mK6OMLhyVWfypXS6nFx+0YXj0Cflh1jDhzHtRg=; b=oHF7zc/M3UEj4rcWCOC2rB3eY5jaIVbGeMdlyz0wExrULv2E+lDcRxbpUJlvRSxquW g+/RiX4uI6ZslJVfsLvMNowwub5LXSB5XCe9QUy+alkz03QZqyLRtuPTdpbtXaD8Sw4q +KN7W8y+AEW3wbGaRg8wrWCATPwCrwg98DVQhJWM3bNz3JRdzsg76CdN9YPZ9esas/lQ gGxqdTTGFXJJjU1BhYntcwfczJfogJdKlnE2jC4mxQLcQaJtCZiX2HYifRviASboCWOx +FBWxsftyTiXCldihyEh6wrlHRwRp6TvPFwX57qmBULTx43ex4/isS15IhxEWMQVShGm SQMQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 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: APzg51B0JR6Z2pt6di1tvXD98R0KNL6ZBKEtLsXYuoJQlyhWPrrUrJf4 FCQarhhC0eJSYVE98LJNVOGOkPrL5//Hsbcr5k1VQ+gXCzads/kD/zE4tDMvs7H+cZ2z5kP7nPJ zIvvykRe4ZmYiuI5FG2Bsa+nZngXWgtXFgIMnJ4fiTO4YXpmN47gqITCCgaiBZ5gszw== X-Received: by 2002:a62:4494:: with SMTP id m20-v6mr47393411pfi.205.1537542626459; Fri, 21 Sep 2018 08:10:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYJFWSaBVOGFQl5nT2NsUCzLxjfUoWTygaHBba5ybPAR/rdlTMCYnFHTZI7cR7tlFghOdjF X-Received: by 2002:a62:4494:: with SMTP id m20-v6mr47393342pfi.205.1537542625704; Fri, 21 Sep 2018 08:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537542625; cv=none; d=google.com; s=arc-20160816; b=bsIkYiqlaqxkoO/94lm2mJ6sqrsYjWT7uQvBdRWalUzBtv+e3YbTidK2+Joqbpemhb QL+Ei/q7/FPl8+FnL0MRjkqTDQgb6R587nsAutLjqK6dlvnIpEwFBwldJlae8NZNMA0a 9sTAHVRWbi5IkE4YCZn2EToqlIzh9B5FyVca1bRmUODoT8khaluCAiavJEzn2mIErqP3 +bDJsXnqekNa/5vyM2Ial7oy3mncOmPhqYfKlHScKqOAASJSypQlBhcjIw4ugr7co5E1 I8qESHwj6t1dF9A/wTpeWwwY1PZmuEDHcjA+30ZdD9wnDZAgN8PAH7WlUSTB2m9j/4k3 kiRA== 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; bh=AOHK0mK6OMLhyVWfypXS6nFx+0YXj0Cflh1jDhzHtRg=; b=0A+uNqUfaysmQcaS7rNrUGnRBqZAdXDluBmzV0Z85X/jukoFiF55uMPP7WA2r5K1F1 u3EquRpVcnMxTvEaiax677su+DkK09k7Rjc2s34drIytTN26IJ0JRHwcaPzI+I7cMA/F kPc5gxHsIKqN6608nvuLHEfVfl7KQ8lS9PGhXlMbJscZieSvGeA/PIAd9JBm7dgKYFkd i50KWP+7AeQtb89qL+ql9kt6S2pQnJOwyRgUgrG6d90jNdWRQ0MwV4ljeeCq8BEtJE+J 350F4mDZEh/yFd7fMSJ8BebcWVyN4IethOcBxawybrkDOdlnTsJbWhbFvGNq5fNrS8+q d1VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=yu-cheng.yu@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id z3-v6si26822954pgh.557.2018.09.21.08.10.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Sep 2018 08:10:25 -0700 (PDT) Received-SPF: pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yu-cheng.yu@intel.com designates 134.134.136.126 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 fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 08:10:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="71856872" Received: from 2b52.sc.intel.com ([143.183.136.51]) by fmsmga007.fm.intel.com with ESMTP; 21 Sep 2018 08:09:54 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Cyrill Gorcunov , Dave Hansen , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue Cc: Yu-cheng Yu Subject: [RFC PATCH v4 25/27] mm/mmap: Prevent Shadow Stack VMA merges Date: Fri, 21 Sep 2018 08:03:49 -0700 Message-Id: <20180921150351.20898-26-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921150351.20898-1-yu-cheng.yu@intel.com> References: <20180921150351.20898-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 Function returns could unwind stacks beyond its allocated area. We do not merge shadow stack areas. This and VMA guards prevent shadow stack underflow. Signed-off-by: Yu-cheng Yu --- mm/mmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index de2d0faa1c61..fa581ced3f56 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1123,6 +1123,12 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm, if (vm_flags & VM_SPECIAL) return NULL; + /* + * Do not merge shadow stack areas. + */ + if (vm_flags & VM_SHSTK) + return NULL; + if (prev) next = prev->vm_next; else