From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFD29C636CC for ; Tue, 31 Jan 2023 08:52:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232093AbjAaIwI (ORCPT ); Tue, 31 Jan 2023 03:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231830AbjAaIvg (ORCPT ); Tue, 31 Jan 2023 03:51:36 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC804B4B3 for ; Tue, 31 Jan 2023 00:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675154794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RT0be17qJU4YrT6BGLBw4plPJpfNOohspNBXSp02x6k=; b=Zb0txdNmkI6msqnIx8u2aYCjm6uPrPp3ULYqd5d8xkpUFdqB1odtxJEmAb27yr1pD7vOti ktF7k0FvtynPcvc55NSB80I/a01/25cuJ0IHTEWnt7Sd4MtZJU1Rrb+lDia1EI9M4bZJeE Ev6h6gNHhYkGiC38Wm37xAZCLU+VJW4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-244-5wNx-w6dP5WQeeIPhbyGfw-1; Tue, 31 Jan 2023 03:46:32 -0500 X-MC-Unique: 5wNx-w6dP5WQeeIPhbyGfw-1 Received: by mail-wm1-f72.google.com with SMTP id r15-20020a05600c35cf00b003d9a14517b2so10944851wmq.2 for ; Tue, 31 Jan 2023 00:46:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RT0be17qJU4YrT6BGLBw4plPJpfNOohspNBXSp02x6k=; b=xmY7CBR0sfM24iqXgljcWKr8/d6YY4ZmsOtWrcOdQ3Rea0JppiqyfOT+WlDy2b/X0T wd3kUgwZXcKc410AXhwNfEsH5/ha52WhEt7eJKjkseTi3OfiYgpnkNoxFdVkimECyyTx /OtCdl0f2VK5irjDTcEb4kJK3Nt+jzYRAPnZvif1W+V7rAL7g0bEkYpgM7YGdMHv7Kb1 bzol4tKsw2tKGInWU8gTp4ENcU/uLvLhRt/mieX7NeYJ1/IninXsd6HtMF+bfqYvdjRe hBFFmZcxgDnw3sFAv7sKjQ8RGZwbrVVxMQeMN4qtDAnunXpA2kHGsAd6oGR6kOAvQ6af oGlg== X-Gm-Message-State: AO0yUKVSdWWXneSR04esehjJ1KpPeIKvK5vs+cfzZqwHKS3+/s0uXQSH L6Fx3lyQ4yAVdxk3rdXZVeE9QQxZyLKFX2+BnZ8zR4r7UzvzKAVlFAsvz/14hLX1jYdGEAGcalj ll2zZNelt13FTNsk9UEEs X-Received: by 2002:a05:600c:350a:b0:3dd:1c45:a36d with SMTP id h10-20020a05600c350a00b003dd1c45a36dmr2228077wmq.27.1675154790684; Tue, 31 Jan 2023 00:46:30 -0800 (PST) X-Google-Smtp-Source: AK7set8QpCOBeSom0P3EMkkVT3iDxdmU57NVBunEGbit/G8Vzfu/HJ8buwXfm2TF7WWfzUVYQ1crOw== X-Received: by 2002:a05:600c:350a:b0:3dd:1c45:a36d with SMTP id h10-20020a05600c350a00b003dd1c45a36dmr2228038wmq.27.1675154790214; Tue, 31 Jan 2023 00:46:30 -0800 (PST) Received: from ?IPV6:2003:d8:2f0a:ca00:f74f:2017:1617:3ec3? (p200300d82f0aca00f74f201716173ec3.dip0.t-ipconnect.de. [2003:d8:2f0a:ca00:f74f:2017:1617:3ec3]) by smtp.gmail.com with ESMTPSA id o16-20020a05600c379000b003dc49e0132asm9751166wmr.1.2023.01.31.00.46.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 00:46:29 -0800 (PST) Message-ID: <0e29a2d0-08d8-bcd6-ff26-4bea0e4037b0@redhat.com> Date: Tue, 31 Jan 2023 09:46:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v5 18/39] mm: Handle faultless write upgrades for shstk Content-Language: en-US To: "Edgecombe, Rick P" , "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "keescook@chromium.org" , "Eranian, Stephane" , "kirill.shutemov@linux.intel.com" , "dave.hansen@linux.intel.com" , "linux-mm@kvack.org" , "fweimer@redhat.com" , "nadav.amit@gmail.com" , "jannh@google.com" , "dethoma@microsoft.com" , "kcc@google.com" , "linux-arch@vger.kernel.org" , "pavel@ucw.cz" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "akpm@linux-foundation.org" , "Lutomirski, Andy" , "bp@alien8.de" , "jamorris@linux.microsoft.com" , "tglx@linutronix.de" , "Schimpe, Christina" , "mike.kravetz@oracle.com" , "arnd@arndb.de" , "Yang, Weijiang" , "x86@kernel.org" , "andrew.cooper3@citrix.com" , "john.allen@amd.com" , "linux-doc@vger.kernel.org" , "rppt@kernel.org" , "mingo@redhat.com" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" Cc: "Yu, Yu-cheng" References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-19-rick.p.edgecombe@intel.com> <7f63d13d-7940-afb6-8b25-26fdf3804e00@redhat.com> <50cf64932507ba60639eca28692e7df285bcc0a7.camel@intel.com> <1327c608-1473-af4f-d962-c24f04f3952c@redhat.com> <8c3820ae1448de4baffe7c476b4b5d9ba0a309ff.camel@intel.com> <4d224020-f26f-60a4-c7ab-721a024c7a6d@redhat.com> <899d8f3baaf45b896cf335dec2143cd0969a2d8a.camel@intel.com> <27b141c06c37da78afca7214ec7efeaf730162d9.camel@intel.com> <6a38779c1539c2bcfeb6bc8251ed04aa9b06802e.camel@intel.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <6a38779c1539c2bcfeb6bc8251ed04aa9b06802e.camel@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-api@vger.kernel.org On 28.01.23 01:51, Edgecombe, Rick P wrote: > On Fri, 2023-01-27 at 17:12 +0100, David Hildenbrand wrote: >> On 26.01.23 21:19, Edgecombe, Rick P wrote: >>> On Thu, 2023-01-26 at 09:46 +0100, David Hildenbrand wrote: >>>> On 26.01.23 01:59, Edgecombe, Rick P wrote: >>>>> On Wed, 2023-01-25 at 10:43 -0800, Rick Edgecombe wrote: >>>>>> Thanks for your comments and ideas here, I'll give the: >>>>>> pte_t pte_mkwrite(struct vm_area_struct *vma, pte_t pte) >>>>>> ...solution a try. >>>>> >>>>> Well, it turns out there are some pte_mkwrite() callers in >>>>> other >>>>> arch's >>>>> that operate on kernel memory and don't have a VMA. So it >>>>> needed a >>>>> new >>>> >>>> Why not pass in NULL as VMA then and document the semantics? The >>>> less >>>> similarly named but slightly different functions, the better :) >>> >>> Hmm. The x86 and generic versions should probably have the same >>> semantics, so then if you pass a NULL, it would do a regular >>> pte_mkwrite() I guess? >>> >>> I see another benefit of requiring the vma argument, such that raw >>> pte_mkwrite()s are less likely to appear in core MM code. But I >>> think >>> the NULL is awkward because it's not obvious, to me at least, what >>> the >>> implications of that should be. >>> >>> So it will be confusing to read in the NULL cases for the other >>> archs. >>> We also have some warnings to catch miss cases in the PTE tear down >>> code, so the scenario of new code accidentally marking shadow stack >>> PTEs as writable is not totally unchecked. >>> >>> The three functions that do slightly different things are: >>> >>> pte_mkwrite(): >>> Makes a PTE conventionally writable, only takes a PTE. Very clear >>> that >>> it is a low level helper and what it does. >>> >>> maybe_mkwrite(): >>> Might make a PTE writable if the VMA allows it. >>> >>> pte_mkwrite_vma(): >>> Makes a PTE writable in a specific way depending on the VMA >>> >>> I wonder if the name pte_mkwrite_vma() is maybe just not clear >>> enough. >>> It takes a VMA, yes, but what does it do with it? >>> >>> What if it was called pte_mkwrite_type() instead? Some arch's have >>> additional types of writable memory and this function creates them. >>> Of >>> course they also have the normal type of writable memory, and >>> pte_mkwrite() creates that like usual. Doesn't it seem more >>> readable? >> >> The issue is, the more variants we provide the easier it is to make >> mistakes and introduce new buggy code. >> >> It's tempting to simply use pte_mkwrite() and call it a day, where >> people actually should use pte_mkwrite_vma(). >> >> Then, they at least have to investigate what to do about the second >> VMA >> parameter. > > Ok, I'll give it a spin. So far it looks ok. The downside is the giant > tree-wide pte_mkwrite() signature change, but once that is over with > there are other advantages. Like getting rid of maybe_mkwrite()'s > awareness of shadow stack so the logic is more centralized. Please let > me know if you don't feel comfortable with a suggested-by credit tag. Sure ... but I reconsidered :) Maybe there is a cleaner way to do it and avoid the "NULL" argument. What about having (while you're going over everything already): pte_mkwrite(pte, vma) pte_mkwrite_kernel(pte) The latter would only be used in that arch code where we're working on kernel pgtables. We already have pte_offset_kernel() and pte_alloc_kernel_track(), so it's not too weird. -- Thanks, David / dhildenb