From patchwork Tue Sep 6 18:57:53 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: 9317801 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 5AC5A607D3 for ; Tue, 6 Sep 2016 19:00:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5176528E8B for ; Tue, 6 Sep 2016 19:00:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45CD428E93; Tue, 6 Sep 2016 19:00:10 +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 95B9E28E8B for ; Tue, 6 Sep 2016 19:00:09 +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 1bhLZP-0005LH-FD; Tue, 06 Sep 2016 18:58:07 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bhLZO-0005L1-Q8 for xen-devel@lists.xenproject.org; Tue, 06 Sep 2016 18:58:06 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id B8/D7-01945-DB11FC75; Tue, 06 Sep 2016 18:58:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLIsWRWlGSWpSXmKPExsXSO6nOVXev4Pl wg499Ehbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bss+sZCx7oVGxqesrWwHhAqYuRi0NIYAKT xM0NBxkhnD+MEsu2XQdyOIGcDYwS0y8bQSS6GSXOPD/EBpEokpjUdRSsiEVAReLY1W4gm4ODT cBE4s0qR5CwiIC6xJ8LE8CGMgucYZSYPOclO0iNsEC4xNsmb5AaXgEziS+bV7NBzN/MKLHt/w 82iISgxMmZT1hAbGYBLYkb/14ygfQyC0hLLP/HARLmFLCWOD3hJdgJogLKEov7e8BaJQQMJT5 vXMo8gVFoFpJJs5BMmoUwaQEj8ypG9eLUorLUIl0jvaSizPSMktzEzBxdQwNjvdzU4uLE9NSc xKRiveT83E2MwGCuZ2Bg3MF4qtn5EKMkB5OSKK9a4LlwIb6k/JTKjMTijPii0pzU4kOMMhwcS hK8twTOhwsJFqWmp1akZeYA4womLcHBoyTCex0kzVtckJhbnJkOkTrFqCglznsJJCEAksgozY Nrg8XyJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCENt5MvNK4Ka/AlrMBLR43e7TIItLEhF SUg2M2cr3VzpPsJEruGetL3tRJKp29ekO39k/zkq+3vh64mv+h7pGzDNjrrvKvf3UnPV6k1/x 07Ntd298XheZ/PnVMjFNtxeLNYSUfx5N1mbI/rBVxv2H1eJPWukmH/e3bnWcVRw/44htld1Ot r0ps9QFncPfLj/iqZghoPrLqCj1Y5Zop4b/7CRnJZbijERDLeai4kQAlC1ZXeACAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1473188283!32940633!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9743 invoked from network); 6 Sep 2016 18:58:05 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-6.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 6 Sep 2016 18:58:05 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u86IvuJv022840 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Sep 2016 18:57:57 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u86Ivteh020495 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 6 Sep 2016 18:57:56 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u86Ivt2j025982; Tue, 6 Sep 2016 18:57:55 GMT Received: from char.us.oracle.com (/10.137.176.158) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 06 Sep 2016 11:57:55 -0700 Received: by char.us.oracle.com (Postfix, from userid 1000) id EAE806A0DC6; Tue, 6 Sep 2016 14:57:53 -0400 (EDT) Date: Tue, 6 Sep 2016 14:57:53 -0400 From: Konrad Rzeszutek Wilk To: Julien Grall Message-ID: <20160906185753.GH2161@char.us.oracle.com> References: <1472132255-23470-1-git-send-email-konrad.wilk@oracle.com> <1472132255-23470-15-git-send-email-konrad.wilk@oracle.com> <2e04fef1-4846-d077-478b-6a911f6a88e9@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <2e04fef1-4846-d077-478b-6a911f6a88e9@arm.com> User-Agent: Mutt/1.6.2 (2016-07-01) X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: sstabellini@kernel.org, Andrew Cooper , ross.lagerwall@citrix.com, Jan Beulich , xen-devel@lists.xenproject.org Subject: Re: [Xen-devel] [PATCH v2 14/20] livepatch: ARM 32|64: Ignore mapping symbols: $[d, a, x, t] 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 .snip.. > > diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c > > index f49e347..c290602 100644 > > --- a/xen/arch/arm/livepatch.c > > +++ b/xen/arch/arm/livepatch.c > > @@ -82,6 +82,38 @@ void arch_livepatch_unmask(void) > > local_abort_enable(); > > } > > > > +int arch_is_payload_symbol(const struct livepatch_elf *elf, > > + const struct livepatch_elf_sym *sym) > > I think this function should return bool (or bool_t) as the return will be > used by is_payload_symbol as bool. I also took the liberty of changing the name. It is now: bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf, const struct livepatch_elf_sym *sym) As that sounds much more understanding I think. > > +#ifdef CONFIG_ARM_32 > > + p == 'a' || p == 't' > > Note that Xen is not using Thumb instructions which have variable length, so > we shouldn't expect to see $t. symbols. /me nods. Let me spin off a seperate patch that will check for arch specific symbols. And if found within the payload will abort loading of it. Something like this (compile tested on x86 for right now): From e513d9d2e689870ab5b381a7a6d7d3ad24a517e5 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Tue, 6 Sep 2016 14:52:21 -0400 Subject: [PATCH] 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 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. --- xen/arch/arm/livepatch.c | 15 ++++++++++++++- xen/arch/x86/livepatch.c | 7 +++++++ xen/common/livepatch_elf.c | 9 +++++++++ xen/include/xen/livepatch.h | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 95a538b..6a9502b 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -114,7 +114,20 @@ bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf, } return true; } - +int arch_livepatch_symbol_check(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[1] == 't' ) + return -EINVAL; +#else + return 0; +#endif +} 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 b3581ff..781dab9 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -137,6 +137,13 @@ bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf, return true; } +int arch_livepatch_symbol_check(const struct livepatch_elf *elf, + const struct livepatch_elf_sym *sym) +{ + /* No special checks on x86. */ + return 0; +} + 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 ee6fef4..26c8df7 100644 --- a/xen/common/livepatch_elf.c +++ b/xen/common/livepatch_elf.c @@ -244,6 +244,7 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data) for ( i = 1; i < nsym; i++ ) { const Elf_Sym *s = symtab_sec->data + symtab_sec->sec->sh_entsize * i; + int rc; delta = s->st_name; /* Boundary check within the .strtab. */ @@ -256,6 +257,14 @@ static int elf_get_sym(struct livepatch_elf *elf, const void *data) sym[i].sym = s; sym[i].name = strtab_sec->data + delta; + /* On ARM we should NEVER see $t* symbols. */ + rc = arch_livepatch_symbol_check(elf, sym); + if ( rc ) + { + dprintk(XENLOG_ERR, LIVEPATCH "%s: Symbol '%s' should not be in payload!\n", + elf->name, sym[i].name); + return rc; + } } elf->nsym = nsym; diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index c47f43d..6a0ad7f 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -48,6 +48,8 @@ int arch_verify_insn_length(unsigned long len); int arch_livepatch_verify_elf(const struct livepatch_elf *elf); bool_t arch_livepatch_symbol_ok(const struct livepatch_elf *elf, const struct livepatch_elf_sym *sym); +int arch_livepatch_symbol_check(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);