Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp889184pxb; Fri, 22 Apr 2022 13:31:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLYR3rhpwB/xCW3/pBqgM5CDs4AkB3nHfYv/zLcKSESMYcwSGZWgVcNXbBoyalgBV+oVlo X-Received: by 2002:a05:6a00:2310:b0:505:a8ac:40e7 with SMTP id h16-20020a056a00231000b00505a8ac40e7mr6638029pfh.11.1650659486741; Fri, 22 Apr 2022 13:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650659486; cv=none; d=google.com; s=arc-20160816; b=wi4gTMijcsck/tktiLaGn95cKQNvED+8Gj5eG/XmRMyqPf0ZXMUhwGGJmqKL5FAOW4 xpLlZ+kpna4avd4M+Bc0vgqyGU9RdRIXKVqUuqj6xaH5E3Gg9RkDuXPEim9FBC+PS3nt d71byfo+XWCCnbO0KmQbZ5Qwy/nA7Vl5AU7MeWwz3k7OSSdInmMqn9/ywg58qM3WMGna HO0jjuSoABPQXoIRVF3XrC8f4zUYbiVEty1fxMWRr0Nyj4sCFFSRrYrodG7f171LYghD kGk5Nd/jzvDZs+Id0Z8qhMUn7XZMrm+6/9zJRbUwWnDY/wpatFGdz6av+qxIaIAqzMEU Ojyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=H01S+Z7PoKhXtthwBx3mI1VVb20IHa0ThHfpXV2OsWk=; b=qNLAwWMhqXRqOmJ/Uu+JF6TA+JhRkqVwkzkNm/4w1LMGy4+zwjOwWTvR7bU/QIYDD4 59qtlfRduvD+AP8o5ZaVoK9aDstqjb5XydFts/BOiP3v/bx1MhxzL+ZVtUDl01NdidAn xCxBDa0iu7gSyrD5+Lbjo9GjXOL0Z8AUIxPaDeA5vbRsQWq2VEIChTvL9XGXrFlfNEg7 3F2f0TagzfNA8jf96Y+BD2rKPZYnE5pW9IE+pIn2oLHlI9r7brPvhs4dS77oBolY+WHB IEWua2+VCR/w06//UMfOcmLHFF6WUh0yUo6KG3A5d5x99VxLfRByEsO0OGKMN3dIcL4n S6hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Te5bNS7b; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b14-20020a170902b60e00b001548692dbf1si3246525pls.597.2022.04.22.13.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:31:26 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Te5bNS7b; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7823F1BB685; Fri, 22 Apr 2022 12:18:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232387AbiDUQvX (ORCPT + 99 others); Thu, 21 Apr 2022 12:51:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbiDUQvW (ORCPT ); Thu, 21 Apr 2022 12:51:22 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73BDE49276; Thu, 21 Apr 2022 09:48:32 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id w1so9741767lfa.4; Thu, 21 Apr 2022 09:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=H01S+Z7PoKhXtthwBx3mI1VVb20IHa0ThHfpXV2OsWk=; b=Te5bNS7bK0yTicPlwPilL/FHzAHcCqm56DhGAmSHJVeyNBi761kWJGIb9kl8TOYuck BiTT/cBsA/F5VgqiWxOJFnnaOZHoAT4gI5awBPaMEgiyrEJmcMFoF8VPBkGOxFB/SDy4 qqeDtPW45B92jzLhCXjMqi+0O7pfeh81IUjPs6/oytjFCbtCGr735rxBqlAvms8VYNT0 Jvb9G02yo002YknsCfyrj5wNC6z46s/QYuddL1MP5fcS9CizCQNamFZpPEZ8NcHpIzT4 CTDjLKjMhaRGxDTW8Gn5MvVYUXGQN4Ptv7zh47AOnsIAKcNf/WhNZKku9l22WYc3adFD kr+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=H01S+Z7PoKhXtthwBx3mI1VVb20IHa0ThHfpXV2OsWk=; b=DykgAvzxpj6H3pt75Q4xkwWo0tzperKN4BGAAKJp89R4uG1Oz18zJRZY4WXFU7hpq2 e9n3ZkGR8CIBe9Nh6uYN0VdKFJhbeoTFgSYGJx2ebN3xjmLZt1+aPzyBSErwh41b9q/t ezT/3OCDSuNvpetqJjn6NpL8CkQBvtQT+hEl3jmj04YCIQQGqKqDM2r4CV+3uSVy6lQK S74a4Qi1MWsJRiEkq+30n6P801mHgBphjnFbkash8z61bA873qPn9fmaju7YA8ogOE+r jHABpQQg9K1jKMOFpDKTZUmQvCZSIm9w1INlNov0X/ttjmhBjd491y7XQi4wwHde4ZGZ SZ/g== X-Gm-Message-State: AOAM531lGlGb01gKwa6WSRSgWxPx+q3fFBZTVYm8tyK/nTv9Wq1qvup3 1WUOD9cIRlAYwD8D7F5T4cg= X-Received: by 2002:a05:6512:151f:b0:44a:2508:1d01 with SMTP id bq31-20020a056512151f00b0044a25081d01mr228077lfb.675.1650559710555; Thu, 21 Apr 2022 09:48:30 -0700 (PDT) Received: from [192.168.1.38] (91-159-150-194.elisa-laajakaista.fi. [91.159.150.194]) by smtp.gmail.com with ESMTPSA id q64-20020a2e2a43000000b0024ee56ec2bbsm310284ljq.3.2022.04.21.09.48.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 21 Apr 2022 09:48:29 -0700 (PDT) Message-ID: <400be309-ef3f-4175-594d-7dc45a43dc36@gmail.com> Date: Thu, 21 Apr 2022 19:48:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: [PATCH RFC 0/4] mm, arm64: In-kernel support for memory-deny-write-execute (MDWE) Content-Language: en-US To: Catalin Marinas , Kees Cook Cc: Andrew Morton , Christoph Hellwig , Lennart Poettering , =?UTF-8?Q?Zbigniew_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 References: <20220413134946.2732468-1-catalin.marinas@arm.com> <202204141028.0482B08@keescook> <202204201610.093C9D5FE8@keescook> From: Topi Miettinen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 21.4.2022 18.35, Catalin Marinas wrote: > 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. > I think we'd want existing installations with MemoryDenyWriteExecute=yes not start failing when the implementation is changed to in-kernel version. The implementation could be very simple and not even check existing PROT_ flags (except for BTI case) to be maximally compatible to BPF version. So I'd leave "was PROT_WRITE" and other checks to more advanced versions, enabled with a different PR_MDWX_FLAG_. -Topi