From patchwork Wed Oct 23 13:58:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11206887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ABE4C139A for ; Wed, 23 Oct 2019 14:00:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82EA72173B for ; Wed, 23 Oct 2019 14:00:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="HGGjXnyT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82EA72173B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNH9s-0004qY-RQ; Wed, 23 Oct 2019 13:58:40 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iNH9r-0004py-Nu for xen-devel@lists.xenproject.org; Wed, 23 Oct 2019 13:58:39 +0000 X-Inumbo-ID: 2b3cf092-f59d-11e9-947f-12813bfff9fa Received: from esa3.hc3370-68.iphmx.com (unknown [216.71.145.155]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2b3cf092-f59d-11e9-947f-12813bfff9fa; Wed, 23 Oct 2019 13:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1571839100; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m2kh9QpgbBW0t3CfPqyCV8pyy7mWwqyKUQok2IrkiPo=; b=HGGjXnyTF270p7N7zM/A9UGlGzagUxng66tZjJOcQJyiebiyU3e0i9Mv MZAc+exFldhSjS6F0QgVac9rfWcUdlyOW1nuJOKoT+Phr6GnI5GkJYcZI uYZssPs+YVUbFEtGHGDSKI+7v5gNKR2KQG8UU0rlR8Ifn1aUXDtm3FlBs 8=; Authentication-Results: esa3.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa3.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa3.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa3.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: 1Xv42v6vv9H4f21Bp8k5eR3v/Mwfm/KnI79Abul3Wm3J7gMqlTPdIjlDgVvBCg+pbtibGct67q v4HAGsJ3nz82Q5ynZgDfGVbeJe7Hi2sHLJjwvrFuHSisba8wlxFqtO/zQaYWkjaFmyVnPNnLFH /38bg0WC/p/EG7Er9vVHXoQm3ugF2v0l1TWzx9HZYQMm3MMsksMCXG/R+fdXhEmrTxwKaRwRFV sIe1gaOwmJ6sT4bzFNexpsZcK8GMxlWqwMcxDVQxXW/IvK0QVq9e3v10nr2w7SmpeKJ1HQp58g +TU= X-SBRS: 2.7 X-MesageID: 7320436 X-Ironport-Server: esa3.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.68,221,1569297600"; d="scan'208";a="7320436" From: Andrew Cooper To: Xen-devel Date: Wed, 23 Oct 2019 14:58:10 +0100 Message-ID: <20191023135812.21348-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191023135812.21348-1-andrew.cooper3@citrix.com> References: <20191023135812.21348-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 5/7] x86/livepatch: Fail the build if duplicate symbols exist X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Wei Liu , Konrad Rzeszutek Wilk , Andrew Cooper , Ross Lagerwall , Norbert Manthey , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Ross Lagerwall The binary diffing algorithm used by xen-livepatch depends on having unique symbols. Signed-off-by: Ross Lagerwall The livepatch loading algorithm used by Xen resolves relocations by symbol name, and thus also depends on having unique symbols. Introduce CONFIG_ENFORCE_UNIQUE_SYMBOLS to control failing the build if duplicate symbols are found, and disable it in the RANDCONFIG build. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Ross Lagerwall CC: Konrad Rzeszutek Wilk CC: Norbert Manthey CC: Juergen Gross v3: * Use a new config option --- xen/arch/x86/Makefile | 1 + xen/common/Kconfig | 18 ++++++++++++++++-- xen/tools/kconfig/allrandom.config | 1 + xen/tools/symbols.c | 11 +++++++++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index 2443fd2cc5..6b369f21cb 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -99,6 +99,7 @@ endif syms-warn-dup-y := --warn-dup syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) := +syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup $(TARGET): TMP = $(@D)/.$(@F).elf32 $(TARGET): $(TARGET)-syms $(efi-y) boot/mkelf32 diff --git a/xen/common/Kconfig b/xen/common/Kconfig index c9e671869e..4c837d6892 100644 --- a/xen/common/Kconfig +++ b/xen/common/Kconfig @@ -361,9 +361,23 @@ config FAST_SYMBOL_LOOKUP If unsure, say Y. +config ENFORCE_UNIQUE_SYMBOLS + bool "Enforce unique symbols" if LIVEPATCH + default y if LIVEPATCH + ---help--- + Multiple symbols with the same name aren't generally a problem + unless Live patching is to be used. + + Livepatch loading involves resolving relocations against symbol + names, and attempting to a duplicate symbol in a livepatch will + result in incorrect livepatch application. + + This option should be used to ensure that a build of Xen can have a + livepatch build and apply correctly. + config SUPPRESS_DUPLICATE_SYMBOL_WARNINGS - bool "Suppress duplicate symbol warnings" if !LIVEPATCH - default y if !LIVEPATCH + bool "Suppress duplicate symbol warnings" if !ENFORCE_UNIQUE_SYMBOLS + default y if !ENFORCE_UNIQUE_SYMBOLS ---help--- Multiple symbols with the same name aren't generally a problem unless Live patching is to be used, so these warnings can be diff --git a/xen/tools/kconfig/allrandom.config b/xen/tools/kconfig/allrandom.config index 76f74320b5..c480896b96 100644 --- a/xen/tools/kconfig/allrandom.config +++ b/xen/tools/kconfig/allrandom.config @@ -2,3 +2,4 @@ CONFIG_GCOV_FORMAT_AUTODETECT=y CONFIG_UBSAN=n +CONFIG_ENFORCE_UNIQUE_SYMBOLS=n diff --git a/xen/tools/symbols.c b/xen/tools/symbols.c index 05139d1600..9f9e2c9900 100644 --- a/xen/tools/symbols.c +++ b/xen/tools/symbols.c @@ -599,7 +599,7 @@ static int compare_name(const void *p1, const void *p2) int main(int argc, char **argv) { unsigned int i; - bool unsorted = false, warn_dup = false; + bool unsorted = false, warn_dup = false, error_dup = false, found_dup = false; if (argc >= 2) { for (i = 1; i < argc; i++) { @@ -619,6 +619,8 @@ int main(int argc, char **argv) sort_by_name = 1; else if (strcmp(argv[i], "--warn-dup") == 0) warn_dup = true; + else if (strcmp(argv[i], "--error-dup") == 0) + warn_dup = error_dup = true; else if (strcmp(argv[i], "--xensyms") == 0) map_only = true; else @@ -634,14 +636,19 @@ int main(int argc, char **argv) for (i = 1; i < table_cnt; ++i) if (strcmp(SYMBOL_NAME(table + i - 1), SYMBOL_NAME(table + i)) == 0 && - table[i - 1].addr != table[i].addr) + table[i - 1].addr != table[i].addr) { fprintf(stderr, "Duplicate symbol '%s' (%llx != %llx)\n", SYMBOL_NAME(table + i), table[i].addr, table[i - 1].addr); + found_dup = true; + } unsorted = true; } + if (error_dup && found_dup) + exit(1); + if (unsorted) qsort(table, table_cnt, sizeof(*table), compare_value);