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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6434C28D13 for ; Thu, 25 Aug 2022 14:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242252AbiHYOh2 (ORCPT ); Thu, 25 Aug 2022 10:37:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242190AbiHYOhJ (ORCPT ); Thu, 25 Aug 2022 10:37:09 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F094B4E80 for ; Thu, 25 Aug 2022 07:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661438210; x=1692974210; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=dmrRfDKFYvaqDCd7Z0UVB2+tu1U+7ChjMCLoAWvf3BM=; b=UXK/iNNaby6pfzXVMUfzF4Q04mWyxMRdMoHr3TFxaIy+p8dkUfshm8ih 1zEfMGuWdwfMlDwPI5C8qBX0l5OLn4A8FFBqTiwxIEzVH/i0fUGdK/0lA 6Wsm3lWZSrkDWOL/rJTQt2o6anfuacQilS75bKR3fp4AmkfI2woxBeIH4 wZKce9rSC6/NZnbDRM4EWIj0HzrPRGFdpIkejP2CqJQOar72g1l63nTTv bikCTuAjAJHjq7FKt+onexWlDnK/O0Xbx1wGpuOdaVvYuJ0NA9jHUqbDv DATH/EzfU3SKvcsAPfWf8/4wGiA615PwJMMSKQ7ijxSN2r503+FxTbF/3 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="274646649" X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="274646649" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:36:49 -0700 X-IronPort-AV: E=Sophos;i="5.93,263,1654585200"; d="scan'208";a="752504924" Received: from rnaraya1-mobl1.amr.corp.intel.com (HELO [10.212.254.160]) ([10.212.254.160]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 07:36:48 -0700 Message-ID: Date: Thu, 25 Aug 2022 07:36:49 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: PKU usage improvements for threads Content-Language: en-US To: =?UTF-8?Q?Stephen_R=c3=b6ttger?= , Andy Lutomirski Cc: Kees Cook , Dave Hansen , the arch/x86 maintainers , Linux Kernel Mailing List , Jann Horn References: <202208221331.71C50A6F@keescook> <26078f2a-67be-4aa1-bbb2-dcd1168c9d12@www.fastmail.com> From: Dave Hansen In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/25/22 05:30, Stephen Röttger wrote: >>> We were also thinking about if this should be a more generic feature instead of >>> being tied to pkeys. I.e. the doc above has an alternative proposal to introduce >>> something like a memory seal/unseal syscall. >>> I was personally leaning towards using pkeys for this for a few reasons: >>> * intuitively it would make sense to me to extend PKEY_DISABLE_ACCESS >>> to also mean disable all changes to the memory, not just the data. >> It would make some sense, but we can't do it with the existing >> PKEY_DISABLE_ACCESS ABI. It would surely break existing users if they >> couldn't munmap() memory that was PKEY_DISABLE_ACCESS. > Our thought was that this could be opt-in with a prctl(). So, today, you have this: foo = malloc(PAGE_SIZE); pkey_mprotect(foo, PAGE_SIZE, READ|WRITE, pkey=1); munmap(foo); // <-- works fine mmap(hint=foo, ...); // now attacker controls &foo Which is problematic. What you want instead is something like this: prctl(PR_ARCH_NO_MUNMAP_ON_PKEY); // or whatever foo = malloc(PAGE_SIZE); pkey_mprotect(foo, PAGE_SIZE, READ|WRITE, pkey=1); wrpkru(PKEY_DISABLE_ACCESS<