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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 263EDC433F5 for ; Fri, 22 Apr 2022 17:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EUAfeBXCUStet9cabGsPrK443IClXnn/iH0afwaU5do=; b=LgCyTCzLKw5rUK zzelzcnWzXedEAfchfDi7UbQBkzn/OGdsg9wzo1tpPbR5pGiAvaAn0VEMWmEHEDtIU00DJJCczH6f b8I1e0Nur15QEudrMRoZeTS+h0iQupsUD8Kdrdeev5M9KGdtsl1kG5qhVdq0GxXUtjrqlXslB10mL 2tkYWWLJZXAXypr1eJxF2MYlqPtsVvW2+U5BYFqarfaIZmglrV/QDhA12A1TQRxj2Ls/fzvei9HNg jL5bSqzyfpeV8tSSnz7oqO1DSAEoo3/6jDW41j1Qd6bPsm9yK1cdi8nS6deBI4cLwQ74NB0IEa3PN w5Z/AycYEwyjOYi5xt/Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhxHy-001pyw-J1; Fri, 22 Apr 2022 17:41:50 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhxHv-001pws-Ei for linux-arm-kernel@lists.infradead.org; Fri, 22 Apr 2022 17:41:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650649301; 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=qS1z2/5qHncMhjCwTTUMd4XpJC28UxMysCRYKxl364Y=; b=aGsZP9YlztXAj5ng1/5Cq9YEaM9z+d+VAiiimW4hh/OAYFaZ74yp4VbCw+L/Woj7jk8DPz 3oUFEypmEHsGAl9sTUv/P/q4bkkjZke+TgPG66YqbzqsINg106IyxNc5jHaOgD0Hq/EeS9 9CNAQhArX0RsrIkBhEPgNNwYUChN0EY= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-149-B_HS6TnzPay7zh1rRKEhzA-1; Fri, 22 Apr 2022 13:41:41 -0400 X-MC-Unique: B_HS6TnzPay7zh1rRKEhzA-1 Received: by mail-wm1-f71.google.com with SMTP id b12-20020a05600c4e0c00b003914432b970so3958275wmq.8 for ; Fri, 22 Apr 2022 10:41:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=qS1z2/5qHncMhjCwTTUMd4XpJC28UxMysCRYKxl364Y=; b=JuTpFWHDitf0Ji/K/9+/JiPVARABdRYEh7MpSedVUJ5uEN5Oweqjzb70NERHcGf3cW PGZ8U0KPi7+gLjBu6V8jwMdxdlRspz4AFOPV/cSOsZZuDfr+wIo1v82Xiv2RUxqYmrR2 UJEni6uIT+sVZ/y+igm1AetQ2FCBgQv8zbWsLBB4ODBpBL2YqJr9g/aQXN/jFbE1Re2Q UU2DHSMTe7Jx1VwhjHHyw0aD96qqClpIq+EIN6i06axNy0eUmlqGc5jOhLk6l6CEkSUE yq+iDtypVT00YpLGKPDVYeDcrNO1yCmYVI8KiZpgQYaqAv2x8hD94Bm/nKCpdZdSvhkY PUsA== X-Gm-Message-State: AOAM530qcY27sUC3Iju2b7zyBhM4O90ZFy+y5s9YPj9pupwV/hNGt7sN OXsogggJXJxesDsv142319wleuwxtAUO0IvnHEj5mIHRFtGOHnqA26s3PRM7+EXjxIMlC9IS7L9 g9/3EGpNelKl8whBhDvrZt96qJFiIatfSP/U= X-Received: by 2002:a7b:c205:0:b0:38e:b6b4:ed90 with SMTP id x5-20020a7bc205000000b0038eb6b4ed90mr5289993wmi.51.1650649298833; Fri, 22 Apr 2022 10:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt73hO3Dy97LGUolcZvHHAxZgmOvXPUbuwOME5mBJ6jfcifPO0j4OjUm4GxUQAhhZyN0MblA== X-Received: by 2002:a7b:c205:0:b0:38e:b6b4:ed90 with SMTP id x5-20020a7bc205000000b0038eb6b4ed90mr5289976wmi.51.1650649298584; Fri, 22 Apr 2022 10:41:38 -0700 (PDT) Received: from ?IPV6:2003:cb:c702:dd00:745e:20b7:bfa4:2e5f? (p200300cbc702dd00745e20b7bfa42e5f.dip0.t-ipconnect.de. [2003:cb:c702:dd00:745e:20b7:bfa4:2e5f]) by smtp.gmail.com with ESMTPSA id u5-20020adfed45000000b00207a480e6aasm2161989wro.116.2022.04.22.10.41.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Apr 2022 10:41:38 -0700 (PDT) Message-ID: <8aafe4ad-81a6-31a5-c95a-ce2943bf0525@redhat.com> Date: Fri, 22 Apr 2022 19:41:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.2 Subject: Re: [PATCH RFC 2/4] mm, personality: Implement memory-deny-write-execute as a personality flag To: Catalin Marinas Cc: Andrew Morton , Christoph Hellwig , Lennart Poettering , =?UTF-8?Q?Zbigniew_J=c4=99drzejewski-Szmek?= , Will Deacon , Alexander Viro , Eric Biederman , Kees Cook , Szabolcs Nagy , Mark Brown , Jeremy Linton , Topi Miettinen , "linux-mm@kvack.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-abi-devel@lists.sourceforge.net" References: <20220413134946.2732468-1-catalin.marinas@arm.com> <20220413134946.2732468-3-catalin.marinas@arm.com> <443d978a-7092-b5b1-22f3-ae3a997080ad@redhat.com> <59401856-0e45-0ee6-1e45-667c8e00cf21@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220422_104147_595749_66A0CBB4 X-CRM114-Status: GOOD ( 20.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 22.04.22 15:12, Catalin Marinas wrote: > On Fri, Apr 22, 2022 at 01:04:31PM +0200, David Hildenbrand wrote: >> On 22.04.22 12:28, Catalin Marinas wrote: >>> On Thu, Apr 21, 2022 at 06:37:49PM +0100, David Hildenbrand wrote: >>>> Note that in the (FOLL_WRITE|FOLL_FORCE) we only require VM_MAYWRITE on >>>> the vma and trigger a write fault. As the VMA is not VM_WRITE, we won't >>>> actually map the PTE writable, but set it dirty. GUP will retry, find a >>>> R/O pte that is dirty and where it knows that it broke COW and will >>>> allow the read access, although the PTE is R/O. >>>> >>>> That mechanism is required to e.g., set breakpoints in R/O MAP_PRIVATE >>>> kernel sections, but it's used elsewhere for page pinning as well. >>>> >>>> My gut feeling is that GUP(FOLL_WRITE|FOLL_FORCE) could be used right >>>> now to bypass that mechanism, I might be wrong. >>> >>> GUP can be used to bypass this. But if an attacker can trigger such GUP >>> paths via a syscall (e.g. ptrace(PTRACE_POKEDATA)), I think we need the >>> checks on those paths (and reject the syscall) rather than on >>> mmap/mprotect(). This would be covered by something like CAP_SYS_PTRACE. >> >> I was told that RDMA uses FOLL_FORCE|FOLL_WRITE and is available to >> unprivileged users. > > Ah, do they really need this? At a quick search, ib_umem_get() for > example: > > unsigned int gup_flags = FOLL_WRITE; > ... > if (!umem->writable) > gup_flags |= FOLL_FORCE; > > I guess with a new MDWE flag we can make the GUP code ignore FOLL_FORCE > if VM_EXEC. > It's, for example, required when you have a MAP_PRIVATE but PROT_READ mapping and want to take a reliable R/O (!) pin. Without FOLL_FORCE|FOLL_WRITE you'd be pinning a (shared zeropage, pagecache) page that will get replaced by an anonymous page in the COW handler, after mprotect(PROT_READ|PROT_WRITE) followed by a write access. That was an issue for RDMA in the past, that's why we have that handling in place IIRC. Yes, it's ugly. -- Thanks, David / dhildenb _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel