Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp884771pxb; Fri, 22 Apr 2022 13:24:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF45a++BxFPM8RTZqyk8EyukSxTr9LCgjDKfGyhPv4bi08gn4mBVOOqTCe52N9Kzs7YS9s X-Received: by 2002:a17:90b:3b46:b0:1c7:9ca8:a19e with SMTP id ot6-20020a17090b3b4600b001c79ca8a19emr17876418pjb.245.1650659089639; Fri, 22 Apr 2022 13:24:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650659089; cv=none; d=google.com; s=arc-20160816; b=zuE7g4gBQTJtqbI5B7oxd2IgIeBaKYdrTiLSzrxx9njhDRacsYgdSrfyhpHeShs2qq rol9Ma3M+UeWXxTUee7gtFCTHdZXBdDAWr4a3mmN9UB5Hg4hr62LQlgWLzSzPChlc97z OxIoRfcoXcQOzNcn0YLFpeUxWW8d9Uv9QUoPvJJAR8hs264H4X4G+aWbn49ILAuxVoTn GosZTD+iPwYCgMsRXuN4S0kDRtrDvxSFuieAkPNWM0eMYQ0FIbBdUBcROiOVsgTV+xLL 3oJvcwqGp25hwRugjPjNUxEu7/IFzOjn1KFE+34StgDdWPLBfeCsHj0Gqip8oj33fKWT iScQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=trqb3RGz4By7Q/4vNGu07jSQIZ6J+sXuU83PxHssfAo=; b=GYK4vgPnNfwTbTm4/fcYVpemLnBBqo3laZxTtaxnOgR/bhWiDnjhJXesnPFb5RmJYG pq63R/WRfMfiJGed57Q419IpTCeKODfYfRnIVKH/9F3atU0fN9HxNou/KuFL9P4gGPj+ C1wNJxn2iA8iLD4mgAfsdqLFc/2pxcax/ZdeOBVjvo1JNJpyAGBrAVT11Pj9dT0+lc27 h9p+qRqYlcFsfW1XjocSTJV0esu2kZHWsbLhZkPBE2+bePHZ4SD1XdW1SIU9IS156KtG uHB3al7rPlTEnfoHZRCFAfqoT6prwepz7xTEmXJsjjV2JePF2EUEU46Ijpd+OIcEpike 6SnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mn20-20020a17090b189400b001caa43d9645si7914889pjb.95.2022.04.22.13.24.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:24:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5FBEE1AAB7B; Fri, 22 Apr 2022 12:12:15 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1390730AbiDUR10 (ORCPT + 99 others); Thu, 21 Apr 2022 13:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1390577AbiDUR1U (ORCPT ); Thu, 21 Apr 2022 13:27:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 411C32B251; Thu, 21 Apr 2022 10:24:29 -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 C90BA61DFA; Thu, 21 Apr 2022 17:24:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE85AC385A5; Thu, 21 Apr 2022 17:24:24 +0000 (UTC) Date: Thu, 21 Apr 2022 18:24:21 +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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202204210941.4318DE6E8@keescook> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 2. "is not already PROT_EXEC": a) mmap(PROT_READ|PROT_WRITE|PROT_EXEC); // fails b) mmap(PROT_READ|PROT_EXEC); mmap(PROT_READ|PROT_EXEC|PROT_BTI); // passes c) mmap(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); mmap(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 (was write) The current seccomp filter is the strictest. If we go for (2), it allows PROT_BTI as in 2.b but prevents 2.c (as would the current seccomp filter). (3) relaxes 2.c as in 3.c while still preventing 3.d. Both (1) and (2) prevent 3.d by simply rejecting mprotect(PROT_EXEC). 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. -- Catalin