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