Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1999632rwd; Wed, 17 May 2023 04:33:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6exhC6qxNmyaN340Ny7Z8F8sevtIGu2rYq6Ir4RtCa7+EsoZfw2xsoDWui+z4BCf5vXRs2 X-Received: by 2002:a17:903:192:b0:1a9:2a9e:30a8 with SMTP id z18-20020a170903019200b001a92a9e30a8mr2443246plg.9.1684323199444; Wed, 17 May 2023 04:33:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684323199; cv=none; d=google.com; s=arc-20160816; b=CycSbCnvfhidZW+VWOJILUxCjNdXmOdVBqfdPXUGvhIQLQD9/oYrHZPO5dwjM13ZPD THdMjrTSzgxlGDMr1EYTe0YIEj9aTsvauen1OsEF6AMuvx6KbbQ0cvN92zs8XX3vwRMp 8qObBebOspjnvsmq2tIBp9BUboEX5b1v6/r4uet1hY9i7aQHkEH/neoJKaHKECqyx8HO uKTQehd27geYpAliM7RSuW2I2BSd5ELuRCemIK2IbKDKHihEis2vLJLF6jPtY+QweNSm UpSxNkhXYWMGRaJfJ7oFzY+dPfmvcJHiUQRGI3KO32JFgWSIggjlKX6EZwBbRiukggP0 C+Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7mTkreLk1S38pVhpjYS+E6EVJi635U9wuNn5v8Z8PYg=; b=FN0cJrYBjj2RamaOvrxdnXEv41s0OHQ4ZilPiWQrLtMOOQKGrBuLs7e0WzsCrZbdof 82t20r4yuDifz23bdXYD4lPvFLnQE52OJxETQ7ZheReNch+pGR1aPbuftAR7qcXHJbSO x3H/bv0eiIQ6RO7jCI9MIioWFKSmoE0FNe4ivgPFne5fnscEA6BJxALOH9yBidDL3+GF T4WbHhpShM84BGif1KKKYbzz8F5Qsf3upOyUv3rDzVCNkBrFYjINtm4SVfUXsR3TF4Yk c0YXH+noBKQbrXcXUK7KhvOCl8m6aQkTVdA6nKEsYWg4DtQnouXZ39+ebQ4/Vkq4wksh ItTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=X5DOygxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a170903120900b001aaf2ced278si22638457plh.430.2023.05.17.04.33.07; Wed, 17 May 2023 04:33:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=X5DOygxY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230282AbjEQLHu (ORCPT + 99 others); Wed, 17 May 2023 07:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbjEQLHg (ORCPT ); Wed, 17 May 2023 07:07:36 -0400 Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A4A47ABB for ; Wed, 17 May 2023 04:07:15 -0700 (PDT) Received: by mail-ua1-x932.google.com with SMTP id a1e0cc1a2514c-783ef1c0cfdso4972918241.0 for ; Wed, 17 May 2023 04:07:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684321633; x=1686913633; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=7mTkreLk1S38pVhpjYS+E6EVJi635U9wuNn5v8Z8PYg=; b=X5DOygxY+mzaGWWC9vskO7SHUYQyeRUmkr3gu37I+6bfgCzuI0r6KyxOpetU7HgCrH 6NTE+8KHM+fSHAAATU3rpGWH1gY0aPKoYqL/5GlN4ZNnnqdBaKSFjifuxoqEqGbXi2l5 2LDImYXLn59fdcXc3ryA1WdjHMPclM+qjt9/lbF9xdzfh5czY+HuGExeYm0uXkVIxC5m Ok2M2D724FTnS4LVx+HPNbKkoTri09iU2Q00TIZTQeGgehSuFk6iYgd7PX5Y/E+tKXUJ wFlownNI1qwUd+CyZT0rkahnep6zv2bOwjCD0MRbGaBIEdAWNkE1mfmN0aoXbCF1impr JShQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684321633; x=1686913633; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7mTkreLk1S38pVhpjYS+E6EVJi635U9wuNn5v8Z8PYg=; b=cztpv0ou+ae12blXiBQAlVdpfYN68vWY2O0PYXU4fSMu/Tb2pCkhT/5zHETpOhVWzs rrrYSbwAXBDpABJHaXmIaO9Rfg3zulrN1K1v/xw0mpBli1PCyP8Mlaa24xWqC1IjjUhm o0TbvuYP3otbsvzkmZy0uQpOZu3OHSeOl0BLoE4tJ5Gk+ecdIJapsfWKtagueZ8ePnBk VQlZretS6FfDojUoZrwvx2LLwy1pAkGNypi8ilBNKogRPEZnFafmTxeJS6Ec1vvG90pf rSoATDUJInbKGzMM5akYEghfWoYkntCnKUXzCVy/U11BAIWl82Bck76jfSirY6ouC65V awKQ== X-Gm-Message-State: AC+VfDxxgSP7dOY9RmPoSAOlSmUWObU+RJk5mN2EBHu+kj6IFyNnz3l2 nmtckV3QJe4GTm6lBOgGWnJQAFZCwWKvkqobw2TECw== X-Received: by 2002:a05:6102:1506:b0:42e:5b08:ec71 with SMTP id f6-20020a056102150600b0042e5b08ec71mr540575vsv.11.1684321633590; Wed, 17 May 2023 04:07:13 -0700 (PDT) MIME-Version: 1.0 References: <20230515130553.2311248-1-jeffxu@chromium.org> <20230515130553.2311248-2-jeffxu@chromium.org> <6cb7df56-0479-30be-5389-b4b819572deb@intel.com> In-Reply-To: <6cb7df56-0479-30be-5389-b4b819572deb@intel.com> From: =?UTF-8?Q?Stephen_R=C3=B6ttger?= Date: Wed, 17 May 2023 13:07:02 +0200 Message-ID: Subject: Re: [PATCH 1/6] PKEY: Introduce PKEY_ENFORCE_API flag To: Dave Hansen Cc: jeffxu@chromium.org, luto@kernel.org, jorgelo@chromium.org, keescook@chromium.org, groeck@chromium.org, jannh@google.com, akpm@linux-foundation.org, jeffxu@google.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000ad63e605fbe1b007" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 --000000000000ad63e605fbe1b007 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, May 17, 2023 at 1:14=E2=80=AFAM Dave Hansen = wrote: > > On 5/15/23 06:05, jeffxu@chromium.org wrote: > > --- a/arch/x86/mm/pkeys.c > > +++ b/arch/x86/mm/pkeys.c > > @@ -20,7 +20,7 @@ int __execute_only_pkey(struct mm_struct *mm) > > /* Do we need to assign a pkey for mm's execute-only maps? */ > > if (execute_only_pkey =3D=3D -1) { > > /* Go allocate one to use, which might fail */ > > - execute_only_pkey =3D mm_pkey_alloc(mm); > > + execute_only_pkey =3D mm_pkey_alloc(mm, 0); > > if (execute_only_pkey < 0) > > return -1; > > need_to_set_mm_pkey =3D true; > > In your threat model, what mechanism prevents the attacker from > modifying executable mappings? There are different options how we can address this: 1) having a generic mseal() API as Jeff mentioned 2) tagging all code pages with the pkey we're using (would this affect memory sharing between processes?) 3) prevent this with seccomp + userspace validation If we have pkey support, we will only create executable memory using pkey_mprotect and everything else can be blocked with seccomp. This would s= till allow turning R-X memory into RW- memory, but you can't change it back with= out going through our codepath that has added validation. There's a similar challenge with making RO memory writable. For this we'll = need to use approach 1) or 2) instead. > I was trying to figure out if the implicit execute-only pkey should have > the PKEY_ENFORCE_API bit set. I think that in particular would probably > cause some kind of ABI breakage, but it still reminded me that I have an > incomplete picture of the threat model. --000000000000ad63e605fbe1b007 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIPoQYJKoZIhvcNAQcCoIIPkjCCD44CAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg ggz7MIIEtjCCA56gAwIBAgIQeAMYYHb81ngUVR0WyMTzqzANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA3MjgwMDAwMDBaFw0yOTAzMTgwMDAwMDBaMFQxCzAJBgNVBAYT AkJFMRkwFwYDVQQKExBHb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