Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3252355rwb; Mon, 3 Oct 2022 11:57:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eCOFcKwFzEJycQlWCqUnf6rzlMet9Vv39RdBc6bXBdbQH627CwcfESlQTO7a2L8ITqQ1W X-Received: by 2002:a17:907:628f:b0:72f:58fc:3815 with SMTP id nd15-20020a170907628f00b0072f58fc3815mr16388088ejc.719.1664823428510; Mon, 03 Oct 2022 11:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664823428; cv=none; d=google.com; s=arc-20160816; b=fFWKTd25IQNNSYLWSSW2toR4l4E8ATujJ47kUwlQAee7iRikv/5k+U8JViYJrs+lPz I0lokaBaG1dlysJFpiwtWXOo7/6k9xfRCtuaTdilxon07jkYuK3YOXdenh2fGKW/swbX kc7pyZOxZfOFgtVw7hCv9QgB7HMap3ZoUIcQCtpt4D0/rEAajtr1WI2q3PvjJoP3wPSf BTfXPC5/eBcmPONEoLpoE6KK8SS8eiNxEa0zNYmsPXfgR0hzdila4cR4scUivcTcaU1O sCMfbuoHihqhafMP/yLCTQxU5y2bQfBsw3QolyicMZWl+vsrhgUU7oyPCh7XiBLBtP1Q okCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DpamCQg4r6DJ9TEvfJUx5RfmiJZUBbQ1vJaFAYMtbtE=; b=ZNiPUUEzWcTcyYeppj92MdVFIqN+e3IxFdRlTB07dNzqXo8kCHxdWJeC4AkiBCqIY8 Krmb5XdLq3WqugIbXHtn7D6NkF33q4Ved4nCc/OShKzQuVQYxwSACNlp3di+KWM7FRuY ddrQPH+pgJDoEO/fuVMJLhJqh5CeG0Bv51nRNAg8Gcl+G6iR8n3JXVKoNhm43rxFXfwS J5XzZ0Hh3w20Z7jYapjWGZHpQUPLOuuUkT1sPtK/ofaXyq/HZD75bgAlSlgM3Y+eQ/nU ign0rQuGfRlcCKfmdtMIh2V/OP7iFei9SZVeg1151wnPQCK2Wp1exK7Ol6QH26tQcm2t 0sXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bKitYN0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jr3-20020a170906a98300b007825337afeesi8003032ejb.273.2022.10.03.11.56.42; Mon, 03 Oct 2022 11:57:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bKitYN0y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbiJCSXA (ORCPT + 99 others); Mon, 3 Oct 2022 14:23:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229669AbiJCSW5 (ORCPT ); Mon, 3 Oct 2022 14:22:57 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7D8A2F028 for ; Mon, 3 Oct 2022 11:22:54 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id 83so3910705pfw.10 for ; Mon, 03 Oct 2022 11:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date; bh=DpamCQg4r6DJ9TEvfJUx5RfmiJZUBbQ1vJaFAYMtbtE=; b=bKitYN0ycfUP50dLE5yBs9aVB69jVdFmdIDNWZSSiBtQ2XyHoGDEf5LYIZa1I/OwhF 1fu8VI8iw+wr2lMK3sdEZx7+Gt162AqNHmK5PBQuBSw+CUdTXUH9di6lhhM8m5g4r6ni Cf/ac/CiSEYQJtBC8L2idRWiSX6thxVOEH5Tg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=DpamCQg4r6DJ9TEvfJUx5RfmiJZUBbQ1vJaFAYMtbtE=; b=oE4X6CnEzjQeE677vOXtrE8ZSau/x1Zj4SSehdUTcjfJJfJuFAZARs/x4dWOqhxIec wBRZo7l6bqSW6VaEY2GztgIzadQjRzh5VrtDewav/cN6G4hpDrhBPQLVKlpCsMRwn2Va 8Y/k3HovgJ49D/fuUoAU/i2d+1583eZsa3tw1Dp1ylFURGLU6nJS/IQnEMmxD4MBEUC7 LYnGl4CYnSYN7DdO7hfaW9GzZO9esU05iSwWriI5WBcY0SEuwJFZaYmjo/EqSzRY3kYh Q8APc/qDJtIlQ4Qv/7VkY0hfKfrCRGjuCb0OZyJ79oPc6Ou+BJl+9WNhvI3pwckkHL53 EEbQ== X-Gm-Message-State: ACrzQf3Vko/xLUC2qzjab4cV6Vn2TWSt9uhDb8XbM+fJsYSrPu2MK4u7 I8ezNT19HRHVUZ2HrtIklCyNRQ== X-Received: by 2002:a05:6a00:2185:b0:520:7276:6570 with SMTP id h5-20020a056a00218500b0052072766570mr23927389pfi.84.1664821374239; Mon, 03 Oct 2022 11:22:54 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id h4-20020a170902f54400b0017ee7f331ffsm3242061plf.291.2022.10.03.11.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Oct 2022 11:22:53 -0700 (PDT) Date: Mon, 3 Oct 2022 11:22:52 -0700 From: Kees Cook To: Rick Edgecombe Cc: 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 , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu Subject: Re: [PATCH v2 16/39] x86/mm: Update maybe_mkwrite() for shadow stack Message-ID: <202210031122.A27CE24D39@keescook> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-17-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-17-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 29, 2022 at 03:29:13PM -0700, Rick Edgecombe wrote: > From: Yu-cheng Yu > > When serving a page fault, maybe_mkwrite() makes a PTE writable if there is > a write access to it, and its vma has VM_WRITE. Shadow stack accesses to > shadow stack vma's are also treated as write accesses by the fault handler. > This is because setting shadow stack memory makes it writable via some > instructions, so COW has to happen even for shadow stack reads. > > So maybe_mkwrite() should continue to set VM_WRITE vma's as normally > writable, but also set VM_WRITE|VM_SHADOW_STACK vma's as shadow stack. > > Do this by adding a pte_mkwrite_shstk() and a cross-arch stub. Check for > VM_SHADOW_STACK in maybe_mkwrite() and call pte_mkwrite_shstk() > accordingly. > > Apply the same changes to maybe_pmd_mkwrite(). > > Signed-off-by: Yu-cheng Yu Reviewed-by: Kees Cook -- Kees Cook