Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp927127pxb; Fri, 22 Apr 2022 14:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9k/mNPiQpt0PWfSKgAFEDhj3dMyh4iWMx6lJ4OZ/D3+wkLPcQPAELU+Syr7qMxRewFoJj X-Received: by 2002:a63:854a:0:b0:3aa:ed49:b5c1 with SMTP id u71-20020a63854a000000b003aaed49b5c1mr988143pgd.277.1650663111112; Fri, 22 Apr 2022 14:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663110; cv=none; d=google.com; s=arc-20160816; b=IaJcq7spxg85wvGssqZUziQA+8WDYJec8dQIas9F3pc7hHlMzHdPben9D58Ymj0Cop u1U6n3DPpylUW+PzRuqp2ObGrftD8hzxkulH5AhYPgApdTZdy+CzAZKECpSYq0rGw2QF ldLK7d5kSUpeWSI7WWvUVkS8kkAzRn34lmHvO9nZNk+9NRgqYlIH0DIDzd8rgp6Vl+ow lnpCBGVO4Lz81z4i7soiIU3yhige4a9h8x6j+Caqjl9EYgbrtouHkJ0kGcAKWf0g22lW z16svg1ZqX2LSh3jYpQdd/L0/OTa+K+ZArKFbPyEJtXbey5/ej4QgXLCH71qMX7/7aJC 2guQ== 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=pkv69SAvmKsXPgLcsZ02xC7YxGf7jung9wr7SPZncXs=; b=aav/4EOdzb+d90tqAIojkjNa2ptaneA7eSpGp4lLaR1Z0ykvd+UvykMuEkoCeclR0a RCYOKg3d6/xGzqsPWcZqGb91ZNzccQe7aTUPdnSThozI+kC8S2NXkbxs1svTSCnK8KHZ AkEiux20Pge37gqbohp/0mjz0CV1eMa7qAOWmmChW8k/Db/kS9UEPh1Vr5/ZjA4YcB61 UdOYFjI7miyKOSsr3i8Tpd9cKaTZIqcekBaEWHBTVc9w77LqKHbf3PqCNkdjonOF2F0l uLWnEN2J91wzqHEdNaJN4vNdjo4iyjRAzEBV+5rcmQjF3dQMIOrtXKZjWUq0HjAJS4OO WUyg== 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 c8-20020a634e08000000b003aaba22d1d9si3616298pgb.756.2022.04.22.14.31.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:31:50 -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 out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8F65E1B12CD; Fri, 22 Apr 2022 12:39:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391368AbiDUSgF (ORCPT + 99 others); Thu, 21 Apr 2022 14:36:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1389065AbiDUSgE (ORCPT ); Thu, 21 Apr 2022 14:36:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE3E4BB80; Thu, 21 Apr 2022 11:33:13 -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 429FB60CA5; 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202204211030.B0093CC14@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 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