Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp963235rdb; Fri, 2 Feb 2024 09:07:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IG9fGa9nt5EXBp840sATgzD8oMtBFlNbxDHQ/MV8EwkBCSOtOhrytU2zbjz8ObAhaiCG+jX X-Received: by 2002:a17:906:1c2:b0:a36:fc15:c6d0 with SMTP id 2-20020a17090601c200b00a36fc15c6d0mr1779510ejj.13.1706893646377; Fri, 02 Feb 2024 09:07:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706893646; cv=pass; d=google.com; s=arc-20160816; b=09Cyg6ITrouYv/ipG48d+6w5foD3g0VUyMDjly8GFDe3pWuOY4+bAKj0lZ1UjLfWgg xBIVZcCXDcy22LXXn5krcdzsbyF7dmNcibH2saKYAszLways9jFw7p7pxuaEYfemK4m5 Dq+JmDFKUUQWHugqmdro6crSaXSRkQU9QMM5KlZQPnLEU37Afl1c5K/Z6ORX+TKKaFtv Hqq+VFlIE21WFTf5fv6znSATHtACSt6ErP0TPa+RzeUdthkRuPDULMuKiqsg+2usXbsm gBAvg3qSNUjsAov4y1/jWKpj2hDhBmsz3ZZR+94/tPpIzYBs2FUX0w8YuE1tD/rI30Gt U7dQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:content-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:comments:references:in-reply-to :subject:cc:to:from:dkim-signature; bh=zWnoe924Wrq6oYpA28mTvKN0Mvp9/G4Dozi/7BNMUi0=; fh=PRTUU/PI/W0zah2/ksOje5Hs9zMWkJDSSPLBB5B65Io=; b=MyInFJks5DxBkEYIGdR4qV8YpZTU1OAK64CTr+zvdi91Ou/7plw2xFWRgy8WBGNOKL J6Ih8ev4CCB8dMeQn9T/HJBZvTmHFzrf0f/G3fN52XDF7aBOIQdo1Jr/OnFzVAgUpS/t LbWDYqPTxeExGq7yqcDdYueD2iX7CN7rqv0P0Swosdge/ZUWQnefttfNQVOIX3//C4yF YdYlyAm3vYELJ+tBIpjkX16YVkFH3xGduiIsumhPGsZmlpEc5TajCNwi6nzTo8E9aN7R vY3ADgTdfL10c/8y4i+xIqVLSTIwsQ8a/sYzpwIf5kzNWosZ16VaIArRQS/VaWTpyiJI Tw2Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@openbsd.org header.s=selector1 header.b="3zgv7TD/"; arc=pass (i=1 spf=pass spfdomain=openbsd.org dkim=pass dkdomain=openbsd.org); spf=pass (google.com: domain of linux-kernel+bounces-50202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50202-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWP7ia7Y8rKDSzbwhw22MibKPvJ90jI8y1dxijZEAPdc/Hd4m2sbIs67GPRPPVMDQ59cJ+/pZ61biXrLo56VxwNn8SUrJ6VvP8TDyEdCQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l14-20020a1709061c4e00b00a36134c3e03si973842ejg.770.2024.02.02.09.07.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 09:07:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@openbsd.org header.s=selector1 header.b="3zgv7TD/"; arc=pass (i=1 spf=pass spfdomain=openbsd.org dkim=pass dkdomain=openbsd.org); spf=pass (google.com: domain of linux-kernel+bounces-50202-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50202-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 74D1A1F257E0 for ; Fri, 2 Feb 2024 17:07:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 287FD14AD07; Fri, 2 Feb 2024 17:05:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openbsd.org header.i=@openbsd.org header.b="3zgv7TD/" Received: from cvs.openbsd.org (cvs.openbsd.org [199.185.137.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C26A21420B3; Fri, 2 Feb 2024 17:05:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=199.185.137.3 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706893547; cv=none; b=mriKGij5w24zX+l2n5jjpDFp4H93Pq5OhX0GjFdQI5DbYRGHe4t35Egd31+pLE7++3TagzCHPBaAPSp3gNi6hZRH7t94qsVEbZwewe2lnJDC/Sux4hG3qcTHxTHfq/30VmTuhGKK7X0kpjjM5f9y6wIN+/2ZllrLH4JCaLzIfLs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706893547; c=relaxed/simple; bh=BAwvHs1egQiGyh3Tep3tXQoRaot7EO9KKStazGkphj8=; h=From:To:cc:Subject:In-reply-to:References:MIME-Version: Content-Type:Date:Message-ID; b=uRzfieG6tTHAlX5GpfEM/1EsQ+a2fi7MLGxQbMElnxQVEZRJ9B1MujCN5+gkWzZ3s4xY3I8sKdjrus6UIoIJE/T6MZdkCVU1iidH9EPYYfox5OQgIlF7PkVQO+uUQTcYkiRrv+26IpAouJc+QsdRDVsR6PYmmSCogmb9qfEm33k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=openbsd.org; spf=pass smtp.mailfrom=openbsd.org; dkim=pass (2048-bit key) header.d=openbsd.org header.i=@openbsd.org header.b=3zgv7TD/; arc=none smtp.client-ip=199.185.137.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=openbsd.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openbsd.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=selector1; bh=BAwvHs1egQ iGyh3Tep3tXQoRaot7EO9KKStazGkphj8=; h=date:references:in-reply-to: subject:cc:to:from; d=openbsd.org; b=3zgv7TD/ZhY+aUl0O7cUsE/W4VVRIWxeD MKVJaQwalupXyQ9cd/mhDSVOFEJmr7qpl+Dj4k1x8hh61Ao1qVQdaBTm2vFYSCo+nd0cdN jgIAK6z+F94bc6MtyRqcZN9tRbz6V5BzwE4RYcZapApJhS0SQeTS4tTXp9ZDsZkdd1Qwcz 3K+WKRIiTh/kD/gPXvdQd5CyGmHAjZvja4JxoKYC1Zc7gMu6ztpnhCj1b+gZQ/86FWI2vR SKNXSYcY1E0uG8XGN3T8ayov7q1ihEb3QY9kh5GfwMsAP3mS1BQMy4G6bZLcUFNz5mCAM5 3i29NM/koL7kJT9x3vSOva+ioeorg== Received: from cvs.openbsd.org (localhost [127.0.0.1]) by cvs.openbsd.org (OpenSMTPD) with ESMTP id e09d1d9f; Fri, 2 Feb 2024 10:05:43 -0700 (MST) From: "Theo de Raadt" To: Linus Torvalds cc: Jeff Xu , "Liam R. Howlett" , Jonathan Corbet , akpm@linux-foundation.org, keescook@chromium.org, jannh@google.com, sroettger@google.com, willy@infradead.org, gregkh@linuxfoundation.org, usama.anjum@collabora.com, rdunlap@infradead.org, jeffxu@google.com, 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: [PATCH v8 0/4] Introduce mseal In-reply-to: References: <20240131175027.3287009-1-jeffxu@chromium.org> <20240131193411.opisg5yoyxkwoyil@revolver> <20240201204512.ht3e33yj77kkxi4q@revolver> <58408.1706828083@cvs.openbsd.org> Comments: In-reply-to Linus Torvalds message dated "Thu, 01 Feb 2024 15:15:27 -0800." Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <95708.1706893543.1@cvs.openbsd.org> Date: Fri, 02 Feb 2024 10:05:43 -0700 Message-ID: <66496.1706893543@cvs.openbsd.org> Another interaction to consider is sigaltstack(). In OpenBSD, sigaltstack() forces MAP_STACK onto the specified (pre-allocated) region, because on kernel-entry we require the "sp" register to point to a MAP_STACK region (this severely damages ROP pivot methods). Linux does not have MAP_STACK enforcement (yet), but one day someone may try to do that work. This interacted poorly with mimmutable() because some applications allocate the memory being provided poorly. I won't get into the details unless pushed, because what we found makes me upset. Over the years, we've upstreamed diffs to applications to resolve all the nasty allocation patterns. I think the software ecosystem is now mostly clean. I suggest someone in Linux look into whether sigaltstack() is a mseal() bypass, perhaps somewhat similar to madvise MADV_FREE, and consider the correct strategy. This is our documented strategy: On OpenBSD some additional restrictions prevent dangerous address space modifications. The proposed space at ss_sp is verified to be contiguously mapped for read-write permissions (no execute) and incapable of syscall entry (see msyscall(2)). If those conditions are met, a page- aligned inner region will be freshly mapped (all zero) with MAP_STACK (see mmap(2)), destroying the pre-existing data in the region. Once the sigaltstack is disabled, the MAP_STACK attribute remains on the memory, so it is best to deallocate the memory via a method that results in munmap(2). OK, I better provide the details of what people were doing. sigaltstacks() in .data, in .bss, using malloc(), on a buffer on the stack, we even found one creating a sigaltstack inside a buffer on a pthread stack. We told everyone to use mmap() and munmap(), with MAP_STACK if #ifdef MAP_STACK finds a definition.