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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D9E3C433F5 for ; Thu, 21 Apr 2022 15:35:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F0D2B6B0072; Thu, 21 Apr 2022 11:35:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBCE36B0073; Thu, 21 Apr 2022 11:35:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D84076B0074; Thu, 21 Apr 2022 11:35:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id CA13F6B0072 for ; Thu, 21 Apr 2022 11:35:25 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 91BEF252C3 for ; Thu, 21 Apr 2022 15:35:25 +0000 (UTC) X-FDA: 79381285410.28.37A73B5 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf19.hostedemail.com (Postfix) with ESMTP id 077671A0022 for ; Thu, 21 Apr 2022 15:35:22 +0000 (UTC) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202204201610.093C9D5FE8@keescook> X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 077671A0022 X-Stat-Signature: zj4ypib87mgq38rus91guqtf6p6zoe4w Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf19.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Rspam-User: X-HE-Tag: 1650555322-301821 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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