From patchwork Fri Sep 23 01:29:05 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: 9347273 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 755D06077A for ; Fri, 23 Sep 2016 01:32:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D6462AAA9 for ; Fri, 23 Sep 2016 01:32:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51D0E2AC5E; Fri, 23 Sep 2016 01:32:25 +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 9ABD22AAA9 for ; Fri, 23 Sep 2016 01:32:24 +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 1bnFJ7-0003Ln-FN; Fri, 23 Sep 2016 01:29:41 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bnFJ6-0003Lh-OZ for xen-devel@lists.xenproject.org; Fri, 23 Sep 2016 01:29:40 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 54/C6-04595-48584E75; Fri, 23 Sep 2016 01:29:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrIIsWRWlGSWpSXmKPExsUyZ7p8oG5z65N wg31H5Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owP8zYxFuzVqdi34DJTA+MTpS5GLg4hgYlM ElPOLWHsYuQEcr4wSjR22kAkNjJKHFh0nxHC6WOU+DK5h72LkYODRUBVYv5pDRCTTcBE4s0qR 5BeEQF1iT8XJoCVMwucYZT4vv0LG0hCWCBa4t7fdWALeAWsJN7s2MYEMXMTo0TThT42iISgxM mZT1hAbGYBLYkb/14ygSxgFpCWWP6PA8TkFLCWmPjdF6RCVEBZomHGA2YQW0LAUOLzxqXMExg FZyEZNAvJoFkIgxYwMq9i1ChOLSpLLdI1stRLKspMzyjJTczM0TU0MNPLTS0uTkxPzUlMKtZL zs/dxAgMWgYg2MF4YFHgIUZJDiYlUd7uoCfhQnxJ+SmVGYnFGfFFpTmpxYcYZTg4lCR47VuAc oJFqempFWmZOcD4gUlLcPAoifAWg6R5iwsSc4sz0yFSpxgVpcR53UESAiCJjNI8uDZYzF5ilJ US5mUEOkSIpyC1KDezBFX+FaM4B6OSMG8PyBSezLwSuOmvgBYzAS3e8vMByOKSRISUVAPjhgu yu29He808ky6qr9GzO6yDvY/j4ul9bdX/lkj1+qh8uvrW0vaO6sreZq3JuncMn1Te/hK031ls pb/YV40nGrH5fr+PmOWsnia0pekJ9x7X96t2HdJ7wiYfryTBdZSt8OqxrddLNqScY58ktenC5 rnnlDkyMhRzxbNNLObaJe1dx3JEvXirEktxRqKhFnNRcSIA4fBkE9QCAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1474594177!60530219!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 59165 invoked from network); 23 Sep 2016 01:29:39 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-3.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 23 Sep 2016 01:29:39 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8N1TTFJ022433 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Sep 2016 01:29:29 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u8N1TS1U032674 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Sep 2016 01:29:28 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8N1TQFj011575; Fri, 23 Sep 2016 01:29:27 GMT Received: from localhost.localdomain (/10.154.153.189) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 22 Sep 2016 18:29:26 -0700 Date: Thu, 22 Sep 2016 21:29:05 -0400 From: Konrad Rzeszutek Wilk To: Julien Grall Message-ID: <20160923012905.GA29985@localhost.localdomain> References: <1474479154-20991-1-git-send-email-konrad.wilk@oracle.com> <1474479154-20991-9-git-send-email-konrad.wilk@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.1 (2016-04-27) X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: sstabellini@kernel.org, ross.lagerwall@citrix.com, Andrew Cooper , Jan Beulich , xen-devel@lists.xenproject.org Subject: Re: [Xen-devel] [PATCH v5 08/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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP > > +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, > > + const struct livepatch_elf_sym *sym) > > +{ > > +#ifdef CONFIG_ARM_32 > > Out of interest, is there any particular reason to use #ifdef rather than > adding the function in {arm32/arm64}/livepatch.c? I updated it be like that: From 5fc79e4fc3c0770ee4f6e7e0ed666e593deced65 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Tue, 13 Sep 2016 13:15:07 -0400 Subject: [PATCH v6] livepatch/arm/x86: Check payload for for unwelcomed symbols. 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 supposed 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. Reviewed-by: Julien Grall Signed-off-by: Konrad Rzeszutek Wilk Reviewed-by: Ross Lagerwall --- 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. v5: Also check for $t.* wildcard. Use Julien's variant where we roll the [2] check in the return. v6: s/suppose/supposed/ in commit description. Move arch_livepatch_symbol_deny in arm[32|64]/livepatch.c Added Julien's Reviewed-by. --- xen/arch/arm/arm32/livepatch.c | 13 +++++++++++++ xen/arch/arm/arm64/livepatch.c | 7 +++++++ xen/arch/x86/livepatch.c | 7 +++++++ xen/common/livepatch_elf.c | 7 +++++++ xen/include/xen/livepatch.h | 2 ++ 5 files changed, 36 insertions(+) diff --git a/xen/arch/arm/arm32/livepatch.c b/xen/arch/arm/arm32/livepatch.c index 80f9646..5fc2e63 100644 --- a/xen/arch/arm/arm32/livepatch.c +++ b/xen/arch/arm/arm32/livepatch.c @@ -20,6 +20,19 @@ int arch_livepatch_verify_elf(const struct livepatch_elf *elf) return -EOPNOTSUPP; } +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* + * Xen does not use Thumb instructions - and we should not see any of + * them. If we do, abort. + */ + if ( sym->name && sym->name[0] == '$' && sym->name[1] == 't' ) + return ( !sym->name[2] || sym->name[2] == '.' ); + + return false; +} + int arch_livepatch_perform_rela(struct livepatch_elf *elf, const struct livepatch_elf_sec *base, const struct livepatch_elf_sec *rela) diff --git a/xen/arch/arm/arm64/livepatch.c b/xen/arch/arm/arm64/livepatch.c index 0fe73d9..0f25e1e 100644 --- a/xen/arch/arm/arm64/livepatch.c +++ b/xen/arch/arm/arm64/livepatch.c @@ -95,6 +95,13 @@ int arch_livepatch_verify_elf(const struct livepatch_elf *elf) return 0; } +bool arch_livepatch_symbol_deny(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* No special checks on ARM 64. */ + return false; +} + enum aarch64_reloc_op { RELOC_OP_NONE, RELOC_OP_ABS, diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 7a369a0..9663ef6 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -131,6 +131,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 dec904a..53b3fba 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 e8c67d6..98ec012 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);