From patchwork Wed Jul 26 19:47:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9865733 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 9B3516038F for ; Wed, 26 Jul 2017 19:51:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D9C2281E1 for ; Wed, 26 Jul 2017 19:51:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 82304287B5; Wed, 26 Jul 2017 19:51: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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID 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 773EE281E1 for ; Wed, 26 Jul 2017 19:51: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 1daSIX-0008UY-Eg; Wed, 26 Jul 2017 19:48:45 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1daSIW-0008Tv-MK for xen-devel@lists.xenproject.org; Wed, 26 Jul 2017 19:48:44 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 86/6A-03937-C12F8795; Wed, 26 Jul 2017 19:48:44 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRWlGSWpSXmKPExsVyMfTOYV3pTxW RBnPbdCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyXp7qZCmZpVlzq28LYwLhCvouRi0NIYAaj xKneQ+wgDovABxaJlzu2soI4EgLTWCW6mv6xdDFyADlxEkfWBnQxcgKZFRIvZlxmA7GFBJQkt kx+zAgx6TmTxJkLb9hBEsICehKTv91mBLHZBPQlnq69xgxiiwjkSXTtbwCzmQXcJOb1fGKBqP eQaJg3mQlkF4uAqsT8q/YgYV4BM4lrEy6xQeyVl5jYOw1sJKeAucT7Z8+YIG4wk+i+18w4gVF wASPDKkaN4tSistQiXSMjvaSizPSMktzEzBxdQwMzvdzU4uLE9NScxKRiveT83E2MwIBjAIId jGvmBx5ilORgUhLlnWRaESnEl5SfUpmRWJwRX1Sak1p8iFGGg0NJgvfre6CcYFFqempFWmYOM PRh0hIcPEoivP9B0rzFBYm5xZnpEKlTjPYcV66s+8LEsWH1eiA55cB2IPlqwv9vTEIsefl5qV LivMUfgNoEQNoySvPghsJi9RKjrJQwLyPQmUI8BalFuZklqPKvGMU5GJWEeVtBlvNk5pXA7X4 FdBYT0FlzZpSCnFWSiJCSamDsP/r0yRdz1RDL+789lPdo2X8/N8PVbscxcabVa+O2zqxhrD3/ SPv3qoZqwbtlv6dt2Zmc5Hqhw0I/qkWo3suC1y/x5vcpb4Xu9/d0GylEPf5jb3y76OPvOUJ/f coW/Kj9oV/2LUbaidMvuTff/cmf13afJut8Ep3xtm/J0panAUW2LPODM58qsRRnJBpqMRcVJw IAN9jWEdACAAA= X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-10.tower-27.messagelabs.com!1501098522!85808071!1 X-Originating-IP: [209.85.220.195] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6166 invoked from network); 26 Jul 2017 19:48:43 -0000 Received: from mail-qk0-f195.google.com (HELO mail-qk0-f195.google.com) (209.85.220.195) by server-10.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 26 Jul 2017 19:48:43 -0000 Received: by mail-qk0-f195.google.com with SMTP id v76so4786613qka.5 for ; Wed, 26 Jul 2017 12:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zjGxDeSp/RDwUH6M++I91vjmWI7uMHiI9EF5vIEKl0w=; b=QuuqJhWJ1nchQimzsqQfT8JkuxTZWyllrrFh64TTvg0+dhKz1ZNmjJjiSA3R54IUUc PyLOiOHsY0ZWUUmGDN5gvUpmeVAc626eG16NvHckdBcv4NG+RvsPIcgQjjtXYnM5rxbr 1qhZXxXQUoyIbPAF5jDPlKjv07zQprNVDhZz+HVQdKr5tKZaiZX2gycv+8PCUzi51Zet WJjYZMvMqrHl9+RkdbJJiXQbFVs1hYQLG/6V4bkrDfgGHc9iDmbuyM2/fDvWzi1lX5YK criEQzT5GEqglE/ZGYf6FzS11zYIaS0H+5sA2TLLwFkGs3bNEpMuZ6vXDgi1HlmPIILZ 4sWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zjGxDeSp/RDwUH6M++I91vjmWI7uMHiI9EF5vIEKl0w=; b=CEnSGA9MTuSq8PGpgY7vsTNzUZAiax4Uf4TW8ZS1N2IhVeVEYsHHf4pZQX9MpkI88Q JKksZ9vMU9zzY7ulzKOD9/LwrsJDXRK+k5ktYHMK1ff0Q2xrUG7TQ3W6mx/NtU9c8e/7 qJz1CdWXd4fSbOYmYMDl6aymAmyyxKvWC6ZeIuFmtKtAiwZ8Y9HWLcyBIXDr6mlV9ZqQ pycaR5YwQQt4QHmZ5ikCdaDCZ8FF0WVuylfbECo3AO6ikLxmjf9RlBNZBacakx3YRqJu lO903YuJDbDRtMnOqzJYaiFsbYKIdku4kv+ND4sHyssaZ6ZRV3B/MDIvJzGvQ5DB3UIQ bv7w== X-Gm-Message-State: AIVw111NDAqIByklc7nzRJ7/V3Ty7V5dRsR/STZIhnkqLs4GVVzIlLn6 saQ7xE5ULL5LeX82 X-Received: by 10.55.23.204 with SMTP id 73mr2924868qkx.157.1501098522131; Wed, 26 Jul 2017 12:48:42 -0700 (PDT) Received: from dhcp-amer-vpn-adc-anyconnect-10-154-174-211.vpn.oracle.com (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id m22sm13305504qtm.15.2017.07.26.12.48.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Jul 2017 12:48:41 -0700 (PDT) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, julien.grall@arm.com, sstabellini@kernel.org, andrew.cooper3@citrix.com Date: Wed, 26 Jul 2017 15:47:53 -0400 Message-Id: <20170726194756.20265-3-konrad@kernel.org> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170726194756.20265-1-konrad@kernel.org> References: <20170726194756.20265-1-konrad@kernel.org> Cc: jbeulich@suse.com Subject: [Xen-devel] [PATCH v2 2/5] livepatch: Include sizes when an mismatch occurs 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 From: Konrad Rzeszutek Wilk If the .bug.frames.X or .livepatch.funcs sizes are different than what the hypervisor expects - we fail the payload. To help in diagnosing this include the expected and the payload sizes. Also make it more natural by having "Multiples" in the warning. Signed-off-by: Konrad Rzeszutek Wilk --- v1: Initial version v2: - Changed to 'Multiple' per Jan's recommendation. - Folded the checks in 'check_size' function and removed all the other parts of code that checked for this. --- xen/common/livepatch.c | 48 ++++++++++++++++++++++---------------------- xen/include/xen/elfstructs.h | 2 ++ 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 66d532db14..40ff6b3a27 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -457,6 +457,24 @@ static int secure_payload(struct payload *payload, struct livepatch_elf *elf) return rc; } +static int check_section(const struct livepatch_elf *elf, + const struct livepatch_elf_sec *sec, + const size_t sz, bool zero_ok) +{ + if ( !elf || !sec ) + return -EINVAL; + + if ( (!sec->sec->sh_size && !zero_ok) || + (sec->sec->sh_size % sz) ) + { + dprintk(XENLOG_ERR, LIVEPATCH "%s: Wrong size %"PRIuElfWord" of %s (must be multiple of %zu)\n", + elf->name, sec->sec->sh_size, sec->name, sz); + return -EINVAL; + } + + return 0; +} + static int check_special_sections(const struct livepatch_elf *elf) { unsigned int i; @@ -506,12 +524,8 @@ static int prepare_payload(struct payload *payload, sec = livepatch_elf_sec_by_name(elf, ELF_LIVEPATCH_FUNC); ASSERT(sec); - if ( sec->sec->sh_size % sizeof(*payload->funcs) ) - { - dprintk(XENLOG_ERR, LIVEPATCH "%s: Wrong size of "ELF_LIVEPATCH_FUNC"!\n", - elf->name); + if ( check_section(elf, sec, sizeof(*payload->funcs), true) ) return -EINVAL; - } payload->funcs = sec->load_addr; payload->nfuncs = sec->sec->sh_size / sizeof(*payload->funcs); @@ -553,7 +567,7 @@ static int prepare_payload(struct payload *payload, sec = livepatch_elf_sec_by_name(elf, ".livepatch.hooks.load"); if ( sec ) { - if ( sec->sec->sh_size % sizeof(*payload->load_funcs) ) + if ( check_section(elf, sec, sizeof(*payload->load_funcs), true) ) return -EINVAL; payload->load_funcs = sec->load_addr; @@ -563,7 +577,7 @@ static int prepare_payload(struct payload *payload, sec = livepatch_elf_sec_by_name(elf, ".livepatch.hooks.unload"); if ( sec ) { - if ( sec->sec->sh_size % sizeof(*payload->unload_funcs) ) + if ( check_section(elf, sec, sizeof(*payload->unload_funcs), true) ) return -EINVAL; payload->unload_funcs = sec->load_addr; @@ -634,12 +648,8 @@ static int prepare_payload(struct payload *payload, if ( !sec ) continue; - if ( sec->sec->sh_size % sizeof(*region->frame[i].bugs) ) - { - dprintk(XENLOG_ERR, LIVEPATCH "%s: Wrong size of .bug_frames.%u!\n", - elf->name, i); + if ( check_section(elf, sec, sizeof(*region->frame[i].bugs), true) ) return -EINVAL; - } region->frame[i].bugs = sec->load_addr; region->frame[i].n_bugs = sec->sec->sh_size / @@ -652,12 +662,8 @@ static int prepare_payload(struct payload *payload, #ifdef CONFIG_HAS_ALTERNATIVE struct alt_instr *a, *start, *end; - if ( sec->sec->sh_size % sizeof(*a) ) - { - dprintk(XENLOG_ERR, LIVEPATCH "%s: Size of .alt_instr is not multiple of %zu!\n", - elf->name, sizeof(*a)); + if ( check_section(elf, sec, sizeof(*a), true) ) return -EINVAL; - } start = sec->load_addr; end = sec->load_addr + sec->sec->sh_size; @@ -689,14 +695,8 @@ static int prepare_payload(struct payload *payload, #ifdef CONFIG_HAS_EX_TABLE struct exception_table_entry *s, *e; - if ( !sec->sec->sh_size || - (sec->sec->sh_size % sizeof(*region->ex)) ) - { - dprintk(XENLOG_ERR, LIVEPATCH "%s: Wrong size of .ex_table (exp:%lu vs %lu)!\n", - elf->name, sizeof(*region->ex), - sec->sec->sh_size); + if ( check_section(elf, sec, sizeof(*region->ex), false) ) return -EINVAL; - } s = sec->load_addr; e = sec->load_addr + sec->sec->sh_size; diff --git a/xen/include/xen/elfstructs.h b/xen/include/xen/elfstructs.h index 950e1492e5..726ca8f60d 100644 --- a/xen/include/xen/elfstructs.h +++ b/xen/include/xen/elfstructs.h @@ -555,6 +555,7 @@ typedef struct { #if defined(ELFSIZE) && (ELFSIZE == 32) #define PRIxElfAddr "08x" +#define PRIuElfWord "8u" #define Elf_Ehdr Elf32_Ehdr #define Elf_Phdr Elf32_Phdr @@ -582,6 +583,7 @@ typedef struct { #define AuxInfo Aux32Info #elif defined(ELFSIZE) && (ELFSIZE == 64) #define PRIxElfAddr PRIx64 +#define PRIuElfWord PRIu64 #define Elf_Ehdr Elf64_Ehdr #define Elf_Phdr Elf64_Phdr