From patchwork Fri Sep 16 16:38:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9336201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 67090608A1 for ; Fri, 16 Sep 2016 16:41:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57CF12A039 for ; Fri, 16 Sep 2016 16:41:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CC8A2A03B; Fri, 16 Sep 2016 16:41:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3422C2A03E for ; Fri, 16 Sep 2016 16:41:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkwA7-0002hB-Bp; Fri, 16 Sep 2016 16:38:51 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkwA6-0002f9-7o for xen-devel@lists.xenproject.org; Fri, 16 Sep 2016 16:38:50 +0000 Received: from [193.109.254.147] by server-10.bemta-6.messagelabs.com id 63/5D-27438-9102CD75; Fri, 16 Sep 2016 16:38:49 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42KZM10+UFdC4U6 4waFGdYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWP+wY9sBScVKg6eiGlg7JPsYuTiEBKYzCQx af99dgjnN6PEsSNbWCGcjYwSPy8eZYFwuhkl2nauB3I4gZwiiTcXfwPZHBxsAiYSb1Y5gtSIC PQxStw++pcRpIYZxNl3mhnEFhYIk7i/4B4riM0ioCrRsOEoWA2vgJvE1VX32EBsCQE5iW1b9j CCzOQUcJfoOZcJscpNYsn6tUwQJcYS7W8vsk1g5F/AyLCKUb04tagstUjXQi+pKDM9oyQ3MTN H19DATC83tbg4MT01JzGpWC85P3cTIzB8GIBgB+Psy/6HGCU5mJREeYsLb4cL8SXlp1RmJBZn xBeV5qQWH2KU4eBQkuAtk78TLiRYlJqeWpGWmQMMZJi0BAePkgivAkiat7ggMbc4Mx0idYpRU UqcNwskIQCSyCjNg2uDRc8lRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfM+lgOawpOZVwI3/R XQYiagxatn3QZZXJKIkJJqYFxyRYd/Ygnf+sfdqlyrrbov8T3Ka994vVUw35Atqmvb7O+GOrq ibHtE/bxMltZ/ifG5z2PUafqh78aehiIHqcTMab6161XVzwmUK3zo+VS49mABs4rI6SqNnBfL tec+ZA5anrciU9vDcl/nksl1Zr0a15O8C2v8p/0zLeVa1R/L/XzC94evlFiKMxINtZiLihMB7 sFxnZkCAAA= X-Env-Sender: konrad@char.us.oracle.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1474043926!59411573!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15398 invoked from network); 16 Sep 2016 16:38:48 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-13.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Sep 2016 16:38:48 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8GGcax5030449 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Sep 2016 16:38:36 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u8GGcZ7b006795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Sep 2016 16:38:35 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8GGcYdr006136; Fri, 16 Sep 2016 16:38:35 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 16 Sep 2016 09:38:34 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id 02CE96A0E09; Fri, 16 Sep 2016 12:38:32 -0400 (EDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, ross.lagerwall@citrix.com, julien.grall@arm.com, sstabellini@kernel.org Date: Fri, 16 Sep 2016 12:38:19 -0400 Message-Id: <1474043908-12101-8-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1474043908-12101-1-git-send-email-konrad.wilk@oracle.com> References: <1474043908-12101-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Andrew Cooper , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v4 07/16] livepatch/arm/x86: Check payload for for unwelcomed symbols. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Certain platforms, such as ARM [32|64] add extra mapping symbols such as $x (for ARM64 instructions), or more interesting to this patch: $t (for Thumb instructions). These symbols are suppose to help the final linker to make any adjustments (such as add an veneer). But more importantly - we do not compile Xen with any Thumb instructions (which are variable length) - and if we find these mapping symbols we should disallow such payload. Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Konrad Rzeszutek Wilk Cc: Ross Lagerwall Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper v3: New submission. Use &sym[i] instead of sym (as that will always be NULL). v4: Use bool instead of int for return Update comment in common code about ARM odd symbols. s/_check/_deny/ to make it more clear. --- xen/arch/arm/livepatch.c | 14 ++++++++++++++ xen/arch/x86/livepatch.c | 7 +++++++ xen/common/livepatch_elf.c | 7 +++++++ xen/include/xen/livepatch.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index a87d48c..13d6c10 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -117,6 +117,20 @@ bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, return true; } +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ +#ifdef CONFIG_ARM_32 + /* + * Xen does not use Thumb instructions - and we should not see any of + * them. If we do, abort. + */ + if ( sym->name && *sym->name == '$' && sym->name[1] == 't' ) + return true; +#endif + return false; +} + int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela) diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index efc487a..79be833 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -125,6 +125,13 @@ bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, return true; } +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* No special checks on x86. */ + return false; +} + int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela) diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c index 79c290e..a4f6794 100644 --- a/xen/common/livepatch_elf.c +++ b/xen/common/livepatch_elf.c @@ -251,6 +251,13 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data) sym[i].sym = s; sym[i].name = strtab_sec->data + delta; + /* e.g. On ARM we should NEVER see $t* symbols. */ + if ( arch_livepatch_symbol_deny(elf, &sym[i]) ) + { + dprintk(XENLOG_ERR, LIVEPATCH "%s: Symbol '%s' should not be in payload!\n", + elf->name, sym[i].name); + return -EINVAL; + } } elf->nsym = nsym; diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 03abc5b..d107a75 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -50,6 +50,8 @@ bool_t is_patch(const void *addr); int arch_livepatch_verify_elf(const struct livepatch_elf *elf); bool arch_livepatch_symbol_ok(const struct livepatch_elf *elf, const struct livepatch_elf_sym *sym); +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym); int arch_livepatch_perform_rel(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela);