Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5695791rdb; Wed, 13 Dec 2023 17:16:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFN5Om3NhP0Itz47zQxD8oKVgfZx1W56bzHqty+bV/asDCuSQ6KJqL6aUTEqPD2Lhwkv5Ur X-Received: by 2002:a05:6358:2919:b0:170:b0fe:13a2 with SMTP id y25-20020a056358291900b00170b0fe13a2mr11496109rwb.17.1702516604631; Wed, 13 Dec 2023 17:16:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702516604; cv=none; d=google.com; s=arc-20160816; b=N/Vrf0MMJjetZLv/fjzyzQXZjE54bYCVCl1hpAwf/QWMVV57WKtkDVJhXwoSffxcZ0 Pejq/blKJpsuZSJKmIBBYIumn/eNe4ZWrIqS+8EbhaxNizX/QjLXtus9+WmMrMB6kpzK 0PoYplNYrTJ/BWW2g65p0tuRhYna6fpr73lezhWDhQo4Q6cyXHXvVu0uJL28AKXMPMD0 IEaZfNaVMWU+H1wfeFrBoLVGn8X1n+o542arKb9BzQNOYj6+38y1s/WDnFhudLdRdNGI wLfyBY92SFetaG++Tbb/New2FdCIbwvGOL3q4FxiCAeQuy2/tROrhj0h49YHPSDYNu6A QC0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:content-id:mime-version:comments :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=E8HsOAIis8K7UX70/GaYD9X9pwaXT+XIttZkvbGogmo=; fh=5kvza0GUGju7Txpf7xXTT8LXQMsSKONSVee7GfgWsuc=; b=0BT2qhjiKZZdAcAuxhfvbI3tqzWsG8vadM5gIy828XUzD+Ry8bl0mI42v7vLUtChQC ZsikYtDi1r088oBB2dKktVCLJaUWJmX7VspPAQV3HQZGyZcF9l5CZ3N7kzRxg0hGORAQ q5D/kwXvofBEMN94r1VPCt1wwYIDJav1PWzxbH7Ecb+3Tt1Xx///m2gHVJ5r457I4zGN kT0OSlV5Tm1MxS4iCANc4/GQUiFYCAXNt221kV/oOxXz+yDN8HwK6s6+wZAPmfMDQStm lX2v2GqRbcBMEvYGt8CPVTHb3cyPnNBmUuU9hcONkbn94Kyr/jRi7KoaZs6TwhcwmZtT OmtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@openbsd.org header.s=selector1 header.b=f8EJnL1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id t20-20020a17090ad51400b0028af280a709si1185251pju.96.2023.12.13.17.16.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 17:16:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=fail header.i=@openbsd.org header.s=selector1 header.b=f8EJnL1p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DDFEF822A49E; Wed, 13 Dec 2023 17:16:30 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233926AbjLNBQP (ORCPT + 99 others); Wed, 13 Dec 2023 20:16:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234093AbjLNBQN (ORCPT ); Wed, 13 Dec 2023 20:16:13 -0500 X-Greylist: delayed 399 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 13 Dec 2023 17:16:18 PST Received: from cvs.openbsd.org (cvs.openbsd.org [199.185.137.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEA1CE4; Wed, 13 Dec 2023 17:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=selector1; bh=whGKbpn2mK dixz+7VYNABz/psNG/LtxK3IfpFNItFm0=; h=date:references:in-reply-to: subject:cc:to:from; d=openbsd.org; b=f8EJnL1pM686HWnsDZ2MM+QERZ5fn5hkB jS2UEz9O0HQ3CMCPdqYpqvgemPzK/k3sYnnneBkmxRB2mwcLGksMDxQUepWmAMwQXOZWow UnukNeZTT7/fyuRPG/vc6WY0665nhjTCzO3swQTttAdyYfO+ykooxNcn7hq9Jif7k877Zg NzTQhv5fS8QmQ1kODqjycmd0+HMFk6tqn25KWRfbvwutgEQ8WduyIIyF5VupOqoooaYpMm PcMkj3UvHwRNaSIbk8cWjCxE4kuZUOGfwXj+Pof8/c4Lkak7sNxM8KgYhPRr+6RT7pTSqL cfcNtU11WwqUAXQZzouEGgjK2Ln1A== Received: from cvs.openbsd.org (localhost [127.0.0.1]) by cvs.openbsd.org (OpenSMTPD) with ESMTP id 3f9af318; Wed, 13 Dec 2023 18:09:38 -0700 (MST) From: "Theo de Raadt" To: Jeff Xu cc: Linus Torvalds , jeffxu@chromium.org, akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, jorgelo@chromium.org, groeck@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, pedro.falcato@gmail.com, dave.hansen@intel.com, linux-hardening@vger.kernel.org Subject: Re: [RFC PATCH v3 11/11] mseal:add documentation In-reply-to: References: <20231212231706.2680890-1-jeffxu@chromium.org> <20231212231706.2680890-12-jeffxu@chromium.org> Comments: In-reply-to Jeff Xu message dated "Wed, 13 Dec 2023 16:35:26 -0800." MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <45779.1702516178.1@cvs.openbsd.org> Date: Wed, 13 Dec 2023 18:09:38 -0700 Message-ID: <58421.1702516178@cvs.openbsd.org> X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 17:16:31 -0800 (PST) Jeff Xu wrote: > > Or when would you *ever* say "seal this area, but mprotect()" is ok. > > > The fact that openBSD allows RW=>RO transaction, as in its man page [2] > > " At present, mprotect(2) may reduce permissions on immutable pages > marked PROT_READ | PROT_WRITE to the less permissive PROT_READ." Let me explain this. We encountered two places that needed this less-permission-transition. Both of these problems were found in either .data or bss, which the kernel makes immutable by default. The OpenBSD kernel makes those regions immutable BY DEFAULT, and there is no way to turn that off. One was in our libc malloc, which after initialization, wants to protect a control data structure from being written in the future. The other was in chrome v8, for the v8_flags variable, this is similarily mprotected to less permission after initialization to avoid tampering (because it's an amazing relative-address located control gadget). We introduced a different mechanism to solve these problem. So we added a new ELF section which annotates objects you need to be MUTABLE. If these are .data or .bss, they are placed in the MUTABLE region annotated with the following Program Header: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align OPENBSD_MUTABLE 0x0e9000 0x00000000000ec000 0x00000000000ec000 0x001000 0x001000 RW 0x1000 associated with this Section Header [20] .openbsd.mutable PROGBITS 00000000000ec000 0e9000 001000 00 WA 0 0 4096 (It is vaguely similar to RELRO). You can place objects there using the a compiler __attribute__((section declaration, like this example from our libc/malloc.c code static union { struct malloc_readonly mopts; u_char _pad[MALLOC_PAGESIZE]; } malloc_readonly __attribute__((aligned(MALLOC_PAGESIZE))) __attribute__((section(".openbsd.mutable"))); During startup the code can set the protection and then the immutability of the object correctly. Since we have no purpose left for this permission reduction semantic upon immutable mappings, we may be deleting that behaviour in the future. I wrote that code, because I needed it to make progress with some difficult pieces of code. But we found a better way.