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 997FFC25B4E for ; Tue, 24 Jan 2023 16:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231593AbjAXQ1c (ORCPT ); Tue, 24 Jan 2023 11:27:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233165AbjAXQ1b (ORCPT ); Tue, 24 Jan 2023 11:27:31 -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 45AC02691 for ; Tue, 24 Jan 2023 08:26:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674577608; 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=i7Pw8HLyonCZeA68egrmyo7nTJgPIzxf4MWuoam80Xs=; b=Ft4y85zMq2WhjpISQQYHr3FkOgjqBXSoX+O0ExdeDbBjV1k4tg6VU1Doj7E/xYlptJvoO3 yPgHE4pXXomlPTCvVHW2RV+0rgeRMCkG+QuQuluXpnrcBammWSuxjkw66dpqoWAaD+nOtD 7cvOkjzg04LTorkn4lunz7m1dFthmqY= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-184-ai12ucPhPzCelu1YQeYq0A-1; Tue, 24 Jan 2023 11:26:47 -0500 X-MC-Unique: ai12ucPhPzCelu1YQeYq0A-1 Received: by mail-wr1-f71.google.com with SMTP id y2-20020adfee02000000b002bfb44f286dso267409wrn.11 for ; Tue, 24 Jan 2023 08:26:47 -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=i7Pw8HLyonCZeA68egrmyo7nTJgPIzxf4MWuoam80Xs=; b=ltceD6bdqiUwNKnVMzLlniRlILVDoglDpLmM8fWrUCGtMc0bB3u1Cqq1oz5fUYDKzM Zw+/mXY/ncXNwhbKpMM49+z5wKLm6DfbsZ6MoAaJ/s1ytcqgv9uk41vSKeeScabmPWx6 K44TbQJ5NuI6Gk0WCkAaOYCUeHql6HfEARZs2sIcy3wLmEgU4C5LU8imCNF1XjLLGl08 FD8yH2+GJR/sGBOg9gHc9Gv3mEXtCjRlzJ9lZ5mILx1itC7TRTGmF1fgJIGc4Rl7zb25 c+VXlqD6SceJ2/y48CA0X41/H5qLXpnWR7nNraHxQo/lLQcLto5hOMFJtGyOZButebH+ AWeA== X-Gm-Message-State: AFqh2krfoFRIGIyGarM59VYPF/ODdIbCl3L/V5qdl9OWfvuTGC1tyQ5v ZkyJ+M98XVsQTk+tQAkN9iY0rKGwNT7iSuun2+c+S9drOJven63j5acoB6q88LxJ7J9EoitDPsy 8vaoS5kPrQuDJ8CgblBrH X-Received: by 2002:a05:6000:10c6:b0:2bd:e33e:c04b with SMTP id b6-20020a05600010c600b002bde33ec04bmr23891398wrx.22.1674577606154; Tue, 24 Jan 2023 08:26:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXtQ9TD2bnXMPy82nhP127kncrzx3y56M6S5Ht8LsvTwDvmKsGRFx5R/aF94Ts9iBIA/bwn/sg== X-Received: by 2002:a05:6000:10c6:b0:2bd:e33e:c04b with SMTP id b6-20020a05600010c600b002bde33ec04bmr23891359wrx.22.1674577605843; Tue, 24 Jan 2023 08:26:45 -0800 (PST) Received: from ?IPV6:2003:cb:c707:9d00:9303:90ce:6dcb:2bc9? (p200300cbc7079d00930390ce6dcb2bc9.dip0.t-ipconnect.de. [2003:cb:c707:9d00:9303:90ce:6dcb:2bc9]) by smtp.gmail.com with ESMTPSA id t16-20020a5d49d0000000b002bfb0c5527esm1691618wrs.109.2023.01.24.08.26.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jan 2023 08:26:45 -0800 (PST) Message-ID: Date: Tue, 24 Jan 2023 17:26:43 +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 23/39] mm: Don't allow write GUPs to shadow stack memory Content-Language: en-US To: "Edgecombe, Rick P" , "fweimer@redhat.com" Cc: "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "keescook@chromium.org" , "dave.hansen@linux.intel.com" , "Eranian, Stephane" , "kirill.shutemov@linux.intel.com" , "linux-mm@kvack.org" , "nadav.amit@gmail.com" , "jannh@google.com" , "dethoma@microsoft.com" , "kcc@google.com" , "linux-arch@vger.kernel.org" , "bp@alien8.de" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "pavel@ucw.cz" , "Lutomirski, Andy" , "linux-doc@vger.kernel.org" , "arnd@arndb.de" , "tglx@linutronix.de" , "Schimpe, Christina" , "mike.kravetz@oracle.com" , "x86@kernel.org" , "Yang, Weijiang" , "jamorris@linux.microsoft.com" , "john.allen@amd.com" , "rppt@kernel.org" , "andrew.cooper3@citrix.com" , "mingo@redhat.com" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" , "akpm@linux-foundation.org" References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-24-rick.p.edgecombe@intel.com> <87fsc1il73.fsf@oldenburg.str.redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: 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 23.01.23 21:46, Edgecombe, Rick P wrote: > On Mon, 2023-01-23 at 11:45 +0100, Florian Weimer wrote: >> * David Hildenbrand: >> >>> On 19.01.23 22:23, Rick Edgecombe wrote: >>>> The x86 Control-flow Enforcement Technology (CET) feature >>>> includes a new >>>> type of memory called shadow stack. This shadow stack memory has >>>> some >>>> unusual properties, which requires some core mm changes to >>>> function >>>> properly. >>>> Shadow stack memory is writable only in very specific, controlled >>>> ways. >>>> However, since it is writable, the kernel treats it as such. As a >>>> result >>>> there remain many ways for userspace to trigger the kernel to >>>> write to >>>> shadow stack's via get_user_pages(, FOLL_WRITE) operations. To >>>> make this a >>>> little less exposed, block writable GUPs for shadow stack VMAs. >>>> Still allow FOLL_FORCE to write through shadow stack protections, >>>> as >>>> it >>>> does for read-only protections. >>> >>> So an app can simply modify the shadow stack itself by writing to >>> /proc/self/mem ? >>> >>> Is that really intended? Looks like security hole to me at first >>> sight, but maybe I am missing something important. >> >> Isn't it possible to overwrite GOT pointers using the same vector? >> So I think it's merely reflecting the status quo. > > There was some debate on this. /proc/self/mem can currently write > through read-only memory which protects executable code. So should > shadow stack get separate rules? Is ROP a worry when you can overwrite > executable code? > The question is, if there is reasonable debugging reason to keep it. I assume if a debugger would adjust the ordinary stack, it would have to adjust the shadow stack as well (oh my ...). So it sounds reasonable to have it in theory at least ... not sure when debugger would support that, but maybe they already do. > The consensus seemed to lean towards not making special rules for this > case, and there was some discussion that /proc/self/mem should maybe be > hardened generally. I agree with that. It's a debugging mechanism that a process can abuse to do nasty stuff to its memory that it maybe shouldn't be able to do ... -- Thanks, David / dhildenb