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 01FFEC433EF for ; Thu, 21 Apr 2022 18:34:28 +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:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ysayOlQEKKEYYrU6X4FsdVtZ3pv86fFr1SF5MUorQYs=; b=jgefylgMXqu8Cw QOS12D4vDzm0qyTX1P9Bj3+rcTO3uItAbh3YzWEhfW3pGzCQe08XGC+0URJonke/ZDo7KmJby/O1Y UkeMLDHmTvXjNVphaxCc8NtXbo2kubyc47yfd4C+z/3gHOIZxcUYAUDVFzlaoPl+LxQBYHn4SKsMc FRDLD94f9CHoBJDr8o/mY7CUqlpM5uXq4ElUxwhhWchFpSvkuGsrFkpgr0jUepJUsBdwfu5nWFevy phiZCKBYbdbOVuMkgyWd7Qg7wNNTGgKS3X91PdgqzMOqj5uOZk6Hv5/elDln1w0FALRSGcG0mTllW B7nJxRZfUBl/lIY7WcMg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhbcI-00Ef1O-Mb; Thu, 21 Apr 2022 18:33:22 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhbcD-00Eey4-GV for linux-arm-kernel@lists.infradead.org; Thu, 21 Apr 2022 18:33:19 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3C5DB60B38; Thu, 21 Apr 2022 18:33:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B3E6C385A9; Thu, 21 Apr 2022 18:33:09 +0000 (UTC) Date: Thu, 21 Apr 2022 19:33:05 +0100 From: Catalin Marinas To: Kees Cook Cc: Topi Miettinen , Andrew Morton , Christoph Hellwig , Lennart Poettering , Zbigniew =?utf-8?Q?J=C4=99drzejewski-Szmek?= , Will Deacon , Alexander Viro , Eric Biederman , Szabolcs Nagy , Mark Brown , Jeremy Linton , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-abi-devel@lists.sourceforge.net, linux-hardening@vger.kernel.org, Jann Horn , Salvatore Mesoraca , Igor Zhbanov Subject: Re: [PATCH RFC 0/4] mm, arm64: In-kernel support for memory-deny-write-execute (MDWE) Message-ID: References: <20220413134946.2732468-1-catalin.marinas@arm.com> <202204141028.0482B08@keescook> <202204201610.093C9D5FE8@keescook> <202204210941.4318DE6E8@keescook> <202204211030.B0093CC14@keescook> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202204211030.B0093CC14@keescook> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220421_113317_680750_1546CEEE X-CRM114-Status: GOOD ( 30.11 ) 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 Thu, Apr 21, 2022 at 10:41:43AM -0700, Kees Cook wrote: > On Thu, Apr 21, 2022 at 06:24:21PM +0100, Catalin Marinas wrote: > > On Thu, Apr 21, 2022 at 09:42:23AM -0700, Kees Cook wrote: > > > On Thu, Apr 21, 2022 at 04:35:15PM +0100, Catalin Marinas wrote: > > > > Do we want the "was PROT_WRITE" or we just reject mprotect(PROT_EXEC) if > > > > the vma is not already PROT_EXEC? The latter is closer to the current > > > > systemd approach. The former allows an mprotect(PROT_EXEC) if the > > > > mapping was PROT_READ only for example. > > > > > > > > I'd drop the "was PROT_WRITE" for now if the aim is a drop-in > > > > replacement for BPF MDWE. > > > > > > I think "was PROT_WRITE" is an important part of the defense that > > > couldn't be done with a simple seccomp filter (which is why the filter > > > ended up being a problem in the first place). > > > > I would say "was PROT_WRITE" is slightly more relaxed than "is not > > already PROT_EXEC". The seccomp filter can't do "is not already > > PROT_EXEC" either since it only checks the mprotect() arguments, not the > > current vma flags. > > > > So we have (with sub-cases): > > > > 1. Current BPF filter: > > > > a) mmap(PROT_READ|PROT_WRITE|PROT_EXEC); // fails > > > > b) mmap(PROT_READ|PROT_EXEC); > > mprotect(PROT_READ|PROT_EXEC|PROT_BTI); // fails > > > > c) mmap(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // fails > > > > d) mmap(PROT_READ|PROT_WRITE); > > mprotect(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // fails > > > > 2. "is not already PROT_EXEC": > > > > a) mmap(PROT_READ|PROT_WRITE|PROT_EXEC); // fails > > > > b) mmap(PROT_READ|PROT_EXEC); > > mprotect(PROT_READ|PROT_EXEC|PROT_BTI); // passes > > > > c) mmap(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // fails > > > > d) mmap(PROT_READ|PROT_WRITE); > > mprotect(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // fails > > > > 3. "is or was not PROT_WRITE": > > > > a) mmap(PROT_READ|PROT_WRITE|PROT_EXEC); // fails > > > > b) mmap(PROT_READ|PROT_EXEC); > > mprotect(PROT_READ|PROT_EXEC|PROT_BTI); // passes > > > > c) mmap(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // passes > > > > d) mmap(PROT_READ|PROT_WRITE); > > mprotect(PROT_READ); > > mprotect(PROT_READ|PROT_EXEC); // fails > > [edited above to show each case] Thanks, I was in a rush to get home ;). > restated what was already summarized: > Problem is 1.b. 2 and 3 solve it. 3 is more relaxed (c passes). > > > If we don't care about 3.c, we might as well go for (2). I don't mind, > > already went for (3) in this series. I think either of them would not be > > a regression on MDWE, unless there is some test that attempts 3.c and > > expects it to fail. > > I should stop arguing for a less restrictive mode. ;) It just feels weird > that the combinations are API-mediated, rather than logically defined: > I can do PROT_READ|PROT_EXEC with mmap but not mprotect under 2. As > opposed to saying "the vma cannot be executable if it is or ever was > writable". I find the latter much easier to reason about as far as the > expectations of system state. I had the same reasoning, hence option 3 in this series. I prefer to treat mmap(PROT_READ|PROT_EXEC) and mprotect(PROT_READ|PROT_EXEC) in a similar way. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel