Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1001909pxj; Thu, 27 May 2021 17:31:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2L3w3WDPk8Mwgtn9xQjGD7KlotIP9VS/XR5IY7BRIc+k40JJpCVj6tahcmM/TbKuv/BeO X-Received: by 2002:a17:907:1b20:: with SMTP id mp32mr6629940ejc.495.1622161895695; Thu, 27 May 2021 17:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622161895; cv=none; d=google.com; s=arc-20160816; b=mY6uPPli5T1VjMhokI8ATKk+UxXzEUa6iEynZihF1qPRa1yH+qodD87rMQufNzdryn /r5D7EAOp54Bls2llPLDwIoIVjG9tqP0VbKuTm/oi2wZIYHJ3YlLW7F6GloKUPbO4ST0 b16qnkFS8qgExWDzYV5IMxL7seZvSDbOZOYrrJ1J6yPJUmSKV9Bh7TolFzAqn5/A/1xb sglPGhGxJV7j8GPW7V5iUH3FZrMU6fq8Z2qg/pTTf5OI3NO4c35Y3v775TkD1lgmtf9S Yk8Tq9IlB+cQpe3PX43AE+P+UggAWdWR8zqQ0I4ZIbf+z/UYvBqUqMSkXr0hHTFPWibV 0+lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:from:cc:to:subject:ironport-sdr :ironport-sdr; bh=WdFZv692mSme0i0jaXdVswMW2Ph0VONjqCFzZzEQmoU=; b=0OuhBXFz9jeqGr/q0Jo/ogtpckMhbl4L5TKnn9a0GkjTBSUUbGa8k3Yu4LumLHGwW9 knzU1HoOc45NS15sAm0IGolziahQ2TJSyxLgscMt1FfDgy+zRTc0PvXpRfj9v/VSduxR AGR7VLbXkgPpMCy6acgFgyklOFVrlaaUD62LZ4+5a9iiMGYX2wKX+UjYlydtj6hEl0Hj +N5Wd8V7y0KouPADVeiIQJBnjs8H3sGRIUiO1b/6srGu03w7soTxxGK75wPsipn5bSHc QRhHVCr6WfMmi2hqIUjeC2/Cw88m727ZbXIGT2vUaUo6u53D/rzrM9Sr1ZgP6pa89U90 9J4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zk4si1178465ejb.247.2021.05.27.17.31.12; Thu, 27 May 2021 17:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232891AbhE0X7e (ORCPT + 99 others); Thu, 27 May 2021 19:59:34 -0400 Received: from mga11.intel.com ([192.55.52.93]:49062 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235491AbhE0X7I (ORCPT ); Thu, 27 May 2021 19:59:08 -0400 IronPort-SDR: T2W9qIr/dtqz+GUuBWsVkMxC04o0jkwa5ItcseE6VGH2YNPw51Tzeiay9QGF7eN4inVNl5Tktx Hg2wZAmEFqoA== X-IronPort-AV: E=McAfee;i="6200,9189,9997"; a="199820394" X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="199820394" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2021 16:57:32 -0700 IronPort-SDR: EdBbJMdOe+AIAvP+bJlbPTifDhKTmzM3qg8+7htfJwckCp78t3RIrkyvxgwspQIHQK2Xq1uFGA nhkMOHUu2zEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="548362372" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by fmsmga001.fm.intel.com with ESMTP; 27 May 2021 16:57:31 -0700 Subject: [PATCH 0/5] x86/pkeys: PKRU manipulation bug fixes and cleanups To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Dave Hansen , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, luto@kernel.org, shuah@kernel.org, babu.moger@amd.com, dave.kleikamp@oracle.com, linuxram@us.ibm.com, bauerman@linux.ibm.com From: Dave Hansen Date: Thu, 27 May 2021 16:51:09 -0700 Message-Id: <20210527235109.B2A9F45F@viggo.jf.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andy Lutomirski recently noted a probable bug in write_pkru(), but it was unclear if it was user-visible. A recent bug report in related code[1] forced me to take a look. Basically, manipulation of XSAVE state is too unstructured. get_xsave_addr() gives callers the impression they can read and write XSAVE state when there are a lot of pitfalls, like updates to xstate.features bits. As a result, more than one call site screws up the modification of PKRU in the XSAVE buffer. This series fixes that problem up and also hopefully carves out a less error-prone path that can be reused for other XSAVE features. This series: * Moves the PKRU manipulation to a more appropriate location, away from the page table code * Wraps get_xsave_addr() with more structured, less error-prone interfaces. * Conditionally hides a pkey debugfs file, eliminating the need for new runtime checks to work with the new interface. * Add a selftest to make it more likely to catch bugs like this in the future. This improved selftest catches this issue on Intel CPUs. Without the improvement, it only triggers on AMD. This has been lightly tested so far. It probably needs a tested-by from at least the AMD folks before anyone applies it. 1. https://lore.kernel.org/linux-kselftest/b2e0324a-9125-bb34-9e76-81817df27c48@amd.com/ -- arch/x86/include/asm/fpu/internal.h | 8 - arch/x86/include/asm/fpu/xstate.h | 130 +++++++++++++++++++++++++++ arch/x86/include/asm/pgtable.h | 29 ------ arch/x86/include/asm/processor.h | 7 + arch/x86/kernel/cpu/common.c | 6 - arch/x86/kernel/fpu/xstate.c | 2 arch/x86/kernel/process_64.c | 1 arch/x86/kvm/svm/sev.c | 1 arch/x86/kvm/x86.c | 1 arch/x86/mm/pkeys.c | 13 +- tools/testing/selftests/vm/Makefile | 4 tools/testing/selftests/vm/pkey-x86.h | 1 tools/testing/selftests/vm/protection_keys.c | 73 +++++++++++++++ 13 files changed, 227 insertions(+), 49 deletions(-) Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski Cc: Shuah Khan Cc: Babu Moger Cc: Dave Kleikamp Cc: Ram Pai Cc: Thiago Jung Bauermann