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 CFDF6C433FE for ; Sun, 6 Nov 2022 19:42:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EEB8580008; Sun, 6 Nov 2022 14:42:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E9B9680007; Sun, 6 Nov 2022 14:42:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D631780008; Sun, 6 Nov 2022 14:42:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C67D080007 for ; Sun, 6 Nov 2022 14:42:34 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 829AEC01FC for ; Sun, 6 Nov 2022 19:42:34 +0000 (UTC) X-FDA: 80104039428.22.7322816 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by imf17.hostedemail.com (Postfix) with ESMTP id 1AB2F40002 for ; Sun, 6 Nov 2022 19:42:33 +0000 (UTC) Received: by mail-lf1-f49.google.com with SMTP id be13so14154784lfb.4 for ; Sun, 06 Nov 2022 11:42:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=soEmAuBjEszn8pf98ldLFRL5ujODoTGOCIahcsWuApw=; b=R2TvARUJtyz37zIy2kVi75Orec2ZOcXliptOV1B3feipOsEyycJ2SuXt1NmWRl8Qbw aiMMt4kIaF7uacIYnsjAyICuC0CJABfp4FySKRyqZsHPj6vd5oqakwtyU+Z9CB9jXQHS KRSV1S1YK0SIAI0hqqJ49ZYa55lxmKYsxPQxXzLQUd80eTm5NthjMv8DtykvWy5Whpb2 7ZWLk67mysZljUDbocl2R4ZEFyBvrBRsJQmdf1I1ESXu/hfwS3C++lPXJcoF008zgc8T uCG33NBtrAZfJQ+k+8gYNUYAZP/00YtyYxIR7k+R6KBeFYVfIrM8zMnISCKoP6TDzdwQ IXzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=soEmAuBjEszn8pf98ldLFRL5ujODoTGOCIahcsWuApw=; b=5gDlX2+eXF/2JqdeQbNi3wd/up3897gsnKnEiGaOY+ic8T/RyCquWrEvu+O9gFeAyT wOcWDWvNtvO7L0n7vZznryweV2kTdP9IyyOqNqQMZbseneRzAxWmQeT7bhdVNIx+nJFx dRc/E3pYsLtcZRTRNwo9JsxKijIl2HEURmogvq2qdzjdJKL+P9eGmSsRuIzX8PZ9bm8R B2muUiaxHfTdw8ezhYwSakMDT/08l31eMT791MQiJUfbWhzFG7p5qaMN5px8EcXATz3Z OEIS1WLpSTHUH9L7JxjvN8BT5l1kyUtRVgnAyissX76fzluG66K8hhXBcEVQeTzlcnSP qvUg== X-Gm-Message-State: ACrzQf3m2NaE6+e2jTyLZPly584L2Y+Fc1Xh0x9X47ensmS6FwbDp4aQ fbsKD2Zzshlr7/tOGbz2Nts= X-Google-Smtp-Source: AMsMyM6PGenF6suyM8Ji7VFmUmk8giB/Q9bvSv8DXeQQ8bDRyRB263uzSOoyeKxQx8aZ4VRTkMTHIQ== X-Received: by 2002:a19:c503:0:b0:4a2:b966:37ec with SMTP id w3-20020a19c503000000b004a2b96637ecmr18303820lfe.319.1667763752323; Sun, 06 Nov 2022 11:42:32 -0800 (PST) Received: from [192.168.1.12] (91-159-148-109.elisa-laajakaista.fi. [91.159.148.109]) by smtp.gmail.com with ESMTPSA id u18-20020ac258d2000000b00497a32e2576sm839487lfo.32.2022.11.06.11.42.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 06 Nov 2022 11:42:31 -0800 (PST) Message-ID: <25bd279e-f429-3772-bbea-ad56a7a810e5@gmail.com> Date: Sun, 6 Nov 2022 21:42:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH v1 0/2] mm: In-kernel support for memory-deny-write-execute (MDWE) To: Joey Gouly , Catalin Marinas , Andrew Morton , Lennart Poettering , =?UTF-8?Q?Zbigniew_J=c4=99drzejewski-Szmek?= Cc: Alexander Viro , Kees Cook , 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, nd@arm.com, shuah@kernel.org References: <20221026150457.36957-1-joey.gouly@arm.com> Content-Language: en-US From: Topi Miettinen In-Reply-To: <20221026150457.36957-1-joey.gouly@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667763754; a=rsa-sha256; cv=none; b=KKElkqs8jlBIBgrft/oE86lpeM2ry74BZxkxIE7G96/6hSSGvKVZOFUu/+9e3hyYsksRlA wiqssrq7EBzd6jgON7Ubv+jP/uJC3/oYUPUIYFmxMXKgwPSqfKG7flvmclMJjmmzOr7b28 UVOIAeqCpS2kl99S8KGfVO1kyHhRp8U= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=R2TvARUJ; spf=pass (imf17.hostedemail.com: domain of toiwoton@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=toiwoton@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667763754; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=soEmAuBjEszn8pf98ldLFRL5ujODoTGOCIahcsWuApw=; b=yyqDYykySeU1LQzYOj3MWWn7uywZL/JaQg6R8DS19MJYCNEiZCkrnqgEzdFQVEKME0et6a QcSWo7a7JSX7yTIr5KWyEvUrCDzHVcRddPYY673NddhqHt1ddTJu3IiY3ECY/LT0acbC6o jzgpyxw1UvdncVWoUOLdtcXzDywqGZ8= Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=R2TvARUJ; spf=pass (imf17.hostedemail.com: domain of toiwoton@gmail.com designates 209.85.167.49 as permitted sender) smtp.mailfrom=toiwoton@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: k5m4zqr13zrog5p7t9f5nn1f6jmk5aoa X-Rspamd-Queue-Id: 1AB2F40002 X-HE-Tag: 1667763753-778607 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 26.10.2022 18.04, Joey Gouly wrote: > Hi all, > > This is a follow up to the RFC that Catalin posted: > https://lore.kernel.org/linux-arm-kernel/20220413134946.2732468-1-catalin.marinas@arm.com/ > > The background to this is that systemd has a configuration option called > MemoryDenyWriteExecute [1], implemented as a SECCOMP BPF filter. Its aim > is to prevent a user task from inadvertently creating an executable > mapping that is (or was) writeable. Since such BPF filter is stateless, > it cannot detect mappings that were previously writeable but > subsequently changed to read-only. Therefore the filter simply rejects > any mprotect(PROT_EXEC). The side-effect is that on arm64 with BTI > support (Branch Target Identification), the dynamic loader cannot change > an ELF section from PROT_EXEC to PROT_EXEC|PROT_BTI using mprotect(). > For libraries, it can resort to unmapping and re-mapping but for the > main executable it does not have a file descriptor. The original bug > report in the Red Hat bugzilla - [2] - and subsequent glibc workaround > for libraries - [3]. > > This series adds in-kernel support for this feature as a prctl PR_SET_MDWE, > that is inherited on fork(). The prctl denies PROT_WRITE | PROT_EXEC mappings. > Like the systemd BPF filter it also denies adding PROT_EXEC to mappings. > However unlike the BPF filter it only denies it if the mapping didn't previous > have PROT_EXEC. This allows to PROT_EXEC -> PROT_EXEC | PROT_BTI with mprotect(), > which is a problem with the BPF filter. Draft PR for systemd: https://github.com/systemd/systemd/pull/25276 -Topi > > Thanks, > Joey > > [1] https://www.freedesktop.org/software/systemd/man/systemd.exec.html#MemoryDenyWriteExecute= > [2] https://bugzilla.redhat.com/show_bug.cgi?id=1888842 > [3] https://sourceware.org/bugzilla/show_bug.cgi?id=26831 > > Joey Gouly (2): > mm: Implement memory-deny-write-execute as a prctl > kselftest: vm: add tests for memory-deny-write-execute > > include/linux/mman.h | 15 ++ > include/linux/sched/coredump.h | 6 +- > include/uapi/linux/prctl.h | 6 + > kernel/sys.c | 18 +++ > mm/mmap.c | 3 + > mm/mprotect.c | 5 + > tools/testing/selftests/vm/mdwe_test.c | 194 +++++++++++++++++++++++++ > 7 files changed, 246 insertions(+), 1 deletion(-) > create mode 100644 tools/testing/selftests/vm/mdwe_test.c >