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 9DB95C433F5 for ; Thu, 21 Apr 2022 15:35:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390163AbiDUPiP (ORCPT ); Thu, 21 Apr 2022 11:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390118AbiDUPiM (ORCPT ); Thu, 21 Apr 2022 11:38:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04AE5240AF; Thu, 21 Apr 2022 08:35:23 -0700 (PDT) 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 9CB3D61BF4; Thu, 21 Apr 2022 15:35:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6A0AC385A1; Thu, 21 Apr 2022 15:35:18 +0000 (UTC) Date: Thu, 21 Apr 2022 16:35:15 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202204201610.093C9D5FE8@keescook> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 20, 2022 at 04:21:45PM -0700, Kees Cook wrote: > On Wed, Apr 20, 2022 at 10:34:33PM +0300, Topi Miettinen wrote: > > For systemd, feature compatibility with the BPF version is important so that > > we could automatically switch to the kernel version once available without > > regressions. So I think PR_MDWX_MMAP (or maybe PR_MDWX_COMPAT) should match > > exactly what MemoryDenyWriteExecute=yes as implemented with BPF has: only > > forbid mmap(PROT_EXEC|PROT_WRITE) and mprotect(PROT_EXEC). Like BPF, once > > installed there should be no way to escape and ELF flags should be also > > ignored. ARM BTI should be allowed though (allow PROT_EXEC|PROT_BTI if the > > old flags had PROT_EXEC). I agree. > > Then we could have improved versions (other PR_MDWX_ prctls) with lots more > > checks. This could be enabled with MemoryDenyWriteExecute=strict or so. > > > > Perhaps also more relaxed versions (like SARA) could be interesting (system > > service running Python with FFI, or perhaps JVM etc), enabled with for > > example MemoryDenyWriteExecute=trampolines. That way even those programs > > would get some protection (though there would be a gap in the defences). > > Yup, I think we're all on the same page. Catalin, can you respin with a > prctl for enabling MDWE? I propose just: > > prctl(PR_MDWX_SET, flags); > prctl(PR_MDWX_GET); > > PR_MDWX_FLAG_MMAP > disallows PROT_EXEC on any VMA that is or was PROT_WRITE, > covering at least: mmap, mprotect, pkey_mprotect, and shmat. 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. -- Catalin 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 E82A1C433F5 for ; Thu, 21 Apr 2022 15:36:29 +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=gvGj7FZxcS74aHEZm92MZWJprHIsQ36Amifp1lO/xEo=; b=kAgFHJaJ02ka48 2NkSSKu03rZAY/EtbWjFMmjuljAHspXzF6RnflVOO3H2eshmpJO6UOBMO7b9PJkMwrRi4u/bcGHb0 n58SFqSQey1wpW7jsWOJR5l34As3Fc62guuxBUcTrM+16uEVVTlRZQ0pT2blQdBaYTH5b7Q2dGioO wlm9Q6eR45oFLGmv80AAmSUNxW2r5ZGX22f8rKsvKMi0d+o1WU+6qAoDwyW5XRA8AC+swU5BPkChz 5YThJoD4egFCdHOPLYr824yOlNQ2oqzZTVeNn/29vTnG/o55gMk2zeJLaJnpxv6QsznVvpH4iYHdd TywmWwqU+U6vucsUZqvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhYqD-00E2mw-Dm; Thu, 21 Apr 2022 15:35:33 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nhYq4-00E2js-Nt for linux-arm-kernel@lists.infradead.org; Thu, 21 Apr 2022 15:35:26 +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 ams.source.kernel.org (Postfix) with ESMTPS id 58F21B826C1; Thu, 21 Apr 2022 15:35:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6A0AC385A1; Thu, 21 Apr 2022 15:35:18 +0000 (UTC) Date: Thu, 21 Apr 2022 16:35:15 +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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <202204201610.093C9D5FE8@keescook> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220421_083525_006308_19A3D2ED X-CRM114-Status: GOOD ( 23.47 ) 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 Wed, Apr 20, 2022 at 04:21:45PM -0700, Kees Cook wrote: > On Wed, Apr 20, 2022 at 10:34:33PM +0300, Topi Miettinen wrote: > > For systemd, feature compatibility with the BPF version is important so that > > we could automatically switch to the kernel version once available without > > regressions. So I think PR_MDWX_MMAP (or maybe PR_MDWX_COMPAT) should match > > exactly what MemoryDenyWriteExecute=yes as implemented with BPF has: only > > forbid mmap(PROT_EXEC|PROT_WRITE) and mprotect(PROT_EXEC). Like BPF, once > > installed there should be no way to escape and ELF flags should be also > > ignored. ARM BTI should be allowed though (allow PROT_EXEC|PROT_BTI if the > > old flags had PROT_EXEC). I agree. > > Then we could have improved versions (other PR_MDWX_ prctls) with lots more > > checks. This could be enabled with MemoryDenyWriteExecute=strict or so. > > > > Perhaps also more relaxed versions (like SARA) could be interesting (system > > service running Python with FFI, or perhaps JVM etc), enabled with for > > example MemoryDenyWriteExecute=trampolines. That way even those programs > > would get some protection (though there would be a gap in the defences). > > Yup, I think we're all on the same page. Catalin, can you respin with a > prctl for enabling MDWE? I propose just: > > prctl(PR_MDWX_SET, flags); > prctl(PR_MDWX_GET); > > PR_MDWX_FLAG_MMAP > disallows PROT_EXEC on any VMA that is or was PROT_WRITE, > covering at least: mmap, mprotect, pkey_mprotect, and shmat. 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. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel