Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5099440yba; Tue, 30 Apr 2019 09:07:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwy+W0YkMYvKsMo55pQLBo2P0om/9fj7tmOaMzuD1MHp1K6pJGVReICHivCTlbMBLbq0pX X-Received: by 2002:aa7:8455:: with SMTP id r21mr21465436pfn.253.1556640451794; Tue, 30 Apr 2019 09:07:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556640451; cv=none; d=google.com; s=arc-20160816; b=CLsLVABUBYDWnammeMTmhvd/+9fAzGtoG4xs85FfVNiV1dk6ZTlHbTUAwP6nh0P/BU aFz0omQxqfnF3DmFdp6OEoKX+ked7VvpYOnBY4L1fTHMLrY3bNeTXIvZq93xqIT6BRB7 GQpYMbzLLOSLgFpF0EthCnDCvOFG7Xo9tRUHWk+/TcCV5F+vEb07GZ7WlsV9ctf1r2hG nSME/N7KGTtRfkuynafCGePsYYK2ms58QhYqk7n9Fah6WP2QggwDsxj9pGvr+BUV+LD8 0c8cEV/mzT+Dle/txlpJCKSv7BMTvW3tY9o298j78vdeRoc9Nd4qFkWHO4aOGjtBxmsw BeXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=/rjmcgFmgp4FJfF1KZLJ/O634csf05g/DF0ZHvo/3Aw=; b=trG5DGpwgEmyihYAWf2UtcvQbWxbCRRq+5Il0fAZbGPNEc/0sNB8ueYUA7G17XLUZA tx0DRP/5gMKGg9c3Rh4kxG6vqywo2Zj9Mfc7t7ijlHjdvkEDtsSVmgVYXFyW6MjbSRER Oq1TDVR8vKGC6JTzTmeHaHAznwfoKMtkJZYV+VKXss0hxR/Mr1EUe+tvRWf5EifVq6Vj Np+m3ziX14aMelIppQ0I+oTPj/bwZgB7ldgODd3kirxiU1oeB+HaI0AVGrI8ZjlTpVDk FYlrBLlTWTnwHPY2gv+Z3GvA2RVUYvaucoLoYH4XAv1gtBocHWfpZcxWD3KK9AaTVG5j p7Vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=LqKjHjvI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o6si33366260pgm.317.2019.04.30.09.07.13; Tue, 30 Apr 2019 09:07:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=LqKjHjvI; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726102AbfD3QGT (ORCPT + 99 others); Tue, 30 Apr 2019 12:06:19 -0400 Received: from terminus.zytor.com ([198.137.202.136]:43709 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfD3QGT (ORCPT ); Tue, 30 Apr 2019 12:06:19 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3UG4HHU1441025 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 30 Apr 2019 09:04:17 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3UG4HHU1441025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556640258; bh=/rjmcgFmgp4FJfF1KZLJ/O634csf05g/DF0ZHvo/3Aw=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=LqKjHjvI9ZE0Z6Zo6I2Ss66PDpeEx8oCSTmoHtt9L0OGtDkUxt6yVtpaV9IK76AB+ GQ3mPLV4kEzW0KMeuZCHTbsW2+mGcG9vNdDoIzqjh0XkzU9NJ00afWlUObTRN3zRvN 9yXnlbOtSBo5dBytt0V8sUXa+ICxgyp2HAaFv4k2887RvTa9UAOEHlngbx4kSgiw8H BSVIvCA47nYhQgahBPcsqIhuQDPto7NupmH9eLdCX3Op98qY8DuxV0NSSN01y+BkMI xB7p6d3s5O5/euGWo4sSUhyyrdTTwCNpOT9AcOnmXRP/0ga9R+NF3HJqFnpGB39kWj 6W8CE+aL1o+RQ== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3UG4FHa1441014; Tue, 30 Apr 2019 09:04:15 -0700 Date: Tue, 30 Apr 2019 09:04:15 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Gary Hook Message-ID: Cc: bigeasy@linutronix.de, andriy.shevchenko@linux.intel.com, tglx@linutronix.de, kent.overstreet@gmail.com, dave.hansen@linux.intel.com, peterz@infradead.org, lirongqing@baidu.com, bp@suse.de, colyli@suse.de, mingo@redhat.com, bbrezillon@kernel.org, Gary.Hook@amd.com, luto@kernel.org, akpm@linux-foundation.org, willy@infradead.org, gary.hook@amd.com, mingo@kernel.org, keescook@chromium.org, alexander.shishkin@linux.intel.com, yamada.masahiro@socionext.com, hpa@zytor.com, linux-kernel@vger.kernel.org, x86@kernel.org Reply-To: mingo@redhat.com, colyli@suse.de, Gary.Hook@amd.com, bbrezillon@kernel.org, lirongqing@baidu.com, dave.hansen@linux.intel.com, peterz@infradead.org, bp@suse.de, tglx@linutronix.de, kent.overstreet@gmail.com, andriy.shevchenko@linux.intel.com, bigeasy@linutronix.de, linux-kernel@vger.kernel.org, x86@kernel.org, alexander.shishkin@linux.intel.com, yamada.masahiro@socionext.com, hpa@zytor.com, mingo@kernel.org, keescook@chromium.org, willy@infradead.org, akpm@linux-foundation.org, luto@kernel.org, gary.hook@amd.com In-Reply-To: <155657657552.7116.18363762932464011367.stgit@sosrh3.amd.com> References: <155657657552.7116.18363762932464011367.stgit@sosrh3.amd.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/mm/mem_encrypt: Disable all instrumentation for early SME setup Git-Commit-ID: b51ce3744f115850166f3d6c292b9c8cb849ad4f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_FORGED_REPLYTO,T_DATE_IN_FUTURE_96_Q autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: b51ce3744f115850166f3d6c292b9c8cb849ad4f Gitweb: https://git.kernel.org/tip/b51ce3744f115850166f3d6c292b9c8cb849ad4f Author: Gary Hook AuthorDate: Mon, 29 Apr 2019 22:22:58 +0000 Committer: Borislav Petkov CommitDate: Tue, 30 Apr 2019 17:59:08 +0200 x86/mm/mem_encrypt: Disable all instrumentation for early SME setup Enablement of AMD's Secure Memory Encryption feature is determined very early after start_kernel() is entered. Part of this procedure involves scanning the command line for the parameter 'mem_encrypt'. To determine intended state, the function sme_enable() uses library functions cmdline_find_option() and strncmp(). Their use occurs early enough such that it cannot be assumed that any instrumentation subsystem is initialized. For example, making calls to a KASAN-instrumented function before KASAN is set up will result in the use of uninitialized memory and a boot failure. When AMD's SME support is enabled, conditionally disable instrumentation of these dependent functions in lib/string.c and arch/x86/lib/cmdline.c. [ bp: Get rid of intermediary nostackp var and cleanup whitespace. ] Fixes: aca20d546214 ("x86/mm: Add support to make use of Secure Memory Encryption") Reported-by: Li RongQing Signed-off-by: Gary R Hook Signed-off-by: Borislav Petkov Cc: Alexander Shishkin Cc: Andrew Morton Cc: Andy Shevchenko Cc: Boris Brezillon Cc: Coly Li Cc: "dave.hansen@linux.intel.com" Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: Kees Cook Cc: Kent Overstreet Cc: "luto@kernel.org" Cc: Masahiro Yamada Cc: Matthew Wilcox Cc: "mingo@redhat.com" Cc: "peterz@infradead.org" Cc: Sebastian Andrzej Siewior Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/155657657552.7116.18363762932464011367.stgit@sosrh3.amd.com --- arch/x86/lib/Makefile | 12 ++++++++++++ lib/Makefile | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index 140e61843a07..3cb3af51ec89 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -6,6 +6,18 @@ # Produces uninteresting flaky coverage. KCOV_INSTRUMENT_delay.o := n +# Early boot use of cmdline; don't instrument it +ifdef CONFIG_AMD_MEM_ENCRYPT +KCOV_INSTRUMENT_cmdline.o := n +KASAN_SANITIZE_cmdline.o := n + +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_cmdline.o = -pg +endif + +CFLAGS_cmdline.o := $(call cc-option, -fno-stack-protector) +endif + inat_tables_script = $(srctree)/arch/x86/tools/gen-insn-attr-x86.awk inat_tables_maps = $(srctree)/arch/x86/lib/x86-opcode-map.txt quiet_cmd_inat_tables = GEN $@ diff --git a/lib/Makefile b/lib/Makefile index 3b08673e8881..18c2be516ab4 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,6 +17,17 @@ KCOV_INSTRUMENT_list_debug.o := n KCOV_INSTRUMENT_debugobjects.o := n KCOV_INSTRUMENT_dynamic_debug.o := n +# Early boot use of cmdline, don't instrument it +ifdef CONFIG_AMD_MEM_ENCRYPT +KASAN_SANITIZE_string.o := n + +ifdef CONFIG_FUNCTION_TRACER +CFLAGS_REMOVE_string.o = -pg +endif + +CFLAGS_string.o := $(call cc-option, -fno-stack-protector) +endif + lib-y := ctype.o string.o vsprintf.o cmdline.o \ rbtree.o radix-tree.o timerqueue.o xarray.o \ idr.o int_sqrt.o extable.o \