From patchwork Thu Jun 7 14:38:04 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: 10452309 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 A28146053F for ; Thu, 7 Jun 2018 14:41:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92DCF294DB for ; Thu, 7 Jun 2018 14:41:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 877EA29508; Thu, 7 Jun 2018 14:41:59 +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 3587F294DB for ; Thu, 7 Jun 2018 14:41:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63C7B6B0288; Thu, 7 Jun 2018 10:41:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3287A6B0289; Thu, 7 Jun 2018 10:41:35 -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 16F9E6B0287; Thu, 7 Jun 2018 10:41:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id 9F02C6B0289 for ; Thu, 7 Jun 2018 10:41:34 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id e2-v6so3592695pgq.4 for ; Thu, 07 Jun 2018 07:41:34 -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=/J9JelfmH0Sfr6tVD+fjKrNCYu6NXvV/QQemuV4elYQ=; b=JxOIIzkhYsCQJP2eNkeAWN8iMsZPg4GYsBfyXXdsVYJKS9kaaJKvm1TT34F3nkcszc f9ONoY2FbIm8Mx8K9J7namj2UV+JbF7CSPkH647KqLXUxOD5vxBFN74pJVJiazrecema 6DmGDpg+CmtAyLzfklOYUsmIcPcVBsyKXNAkRUwmq328kGykmhCwZVGHHyf83/sVX5Rr SAgiiAEue7rzIFpoZ89IK6SuSGmcocUxNYOohcXaTpvNQGiFaPL9NDkyHkX4e+6/Maw6 t8HR7v94aWAg1mQj+TWicovg+T2gNR3bzpOAYznZ0+1yHURFbVm0I38UsrADCY0/Rs2S 7EUg== 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: APt69E3Iiv6shNBpbv8poIfpfdBKVOF7QuFURxb/PaVWjNp5LED6H7rD qfmi4+yUPZaMLUUpYGYLrQBs3voZvtiFaMBvqySQoNDPiTw5sAvEigC+O6FRLpc+q1PMsTbario WowT/Ph/XMtZNMXHt27bG5AwcuwdCNjDlLXwy6Qi4QujbANuoC3Zvfg8uFwVay3eXcQ== X-Received: by 2002:a17:902:8a94:: with SMTP id p20-v6mr2345232plo.258.1528382494362; Thu, 07 Jun 2018 07:41:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGoDqyP78ADFeF1oP1+zns8ApjxWwc8U+AB1fScvDp+6i9b+1gfFds5nZST2Rk6UpjnORs X-Received: by 2002:a17:902:8a94:: with SMTP id p20-v6mr2345197plo.258.1528382493818; Thu, 07 Jun 2018 07:41:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528382493; cv=none; d=google.com; s=arc-20160816; b=TZ6Bc4G3lsrTTbc58b7lbQUxnrGqAXzA6S6oDxE8420J+GwPT64ayjU1G6v2IA02h8 Mh3c4LLBDzVS0TL8XoXYclg6fuVZpj4OlExz4TnEtE63uVpUmmN1VrpuI+ID65GoQkTl J6YNxQbxQ2sh06AT8frAHZbR8muZ4xi816uSvlvH11PC8JkztgMK/V6AInpG9L3o1ahK UU5VJ8moeFR+gxG7Bgca4yF0URsyqkxu2CbbQwQOzYRQvEeaYS8ENhfw7hkSfjOrI6AO o+o0TeYW9qW8tCiZ7bpIaTvGV5jSgag1TwzQ7iXsPy5eV5916Ef/9GcFRC5v2PLeE+8f eeWQ== 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=/J9JelfmH0Sfr6tVD+fjKrNCYu6NXvV/QQemuV4elYQ=; b=fkeonlfc3QzBnPKR3gztK8yx2akSImAjxjNpziQIY8T2qlrHovt9oB5s4cy74SwR0T 0ubU0BVyoigYIa1rC+OmrN2jmUM14mpt8zA0ov59IctfnjmLL5hP0xNbRQkWjip9q+Yu ugVRGtuX1/3+ZmXBwG8XhCzUeYv4E0GlMOymth2N/TRNkwY6G4lCwaasNE+ghtRP9CQr iJ9lxhZVdJYOpcVq4fdTXVbfzEqKfyfIuZUpR8BYkmZiwT1PlI/NOGawZ3X+u2CsThCo yaBX+JABJZHv6fPKkDSWRRYTJr5b4dxGKUr44qNnXNwWn2/podZD2hUubQVZUEfNWnjt J63w== 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.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 07:41:33 -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:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,486,1520924400"; d="scan'208";a="62632644" Received: from 2b52.sc.intel.com ([143.183.136.51]) by orsmga001.jf.intel.com with ESMTP; 07 Jun 2018 07:41:32 -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 07/10] mm: Prevent mprotect from changing shadow stack Date: Thu, 7 Jun 2018 07:38:04 -0700 Message-Id: <20180607143807.3611-8-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/mprotect.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/mprotect.c b/mm/mprotect.c index 625608bc8962..128dcb880c12 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -446,6 +446,15 @@ static int do_mprotect_pkey(unsigned long start, size_t len, error = -ENOMEM; if (!vma) goto out; + + /* + * Do not allow changing shadow stack memory. + */ + if (vma->vm_flags & VM_SHSTK) { + error = -EINVAL; + goto out; + } + prev = vma->vm_prev; if (unlikely(grows & PROT_GROWSDOWN)) { if (vma->vm_start >= end)