From patchwork Tue Sep 12 00:37:12 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: 9948243 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 8DB99603F4 for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E9A228D33 for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7353C28D6F; Tue, 12 Sep 2017 00:41:11 +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 2F83328D7A for ; Tue, 12 Sep 2017 00:41:04 +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 1drZD7-0000d6-Bg; Tue, 12 Sep 2017 00:37:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZD5-0000cO-UR for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:37:52 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 5F/BF-03414-F5C27B95; Tue, 12 Sep 2017 00:37:51 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOIsWRWlGSWpSXmKPExsVyMfTOEd04ne2 RBue2q1l83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBmv385iKTiiWbHyyUrmBsbz8l2MXBxCAjMY Jf7f3MwC4rAIfGCR6L66AcyREJjGKvF8zmO2LkZOICdO4tjGbmYIO01i37qHUHaNxJblp1lAb CEBJYktkx8zQow9yCSxZm4vWEJYQE9i8rfbjCA2m4C+xNO114CaOYCa3SQ+XeMCqRcRaGeUmH 3lFytIDbOAoUTr26NsEL1eEstXnAObwyKgKvFxTwNYDa+ApcSclRugjpCXmNg7DWw+p4CVxO8 f81ghDrKU6FhwhWkCo/ACRoZVjBrFqUVlqUW6hiZ6SUWZ6RkluYmZObqGBmZ6uanFxYnpqTmJ ScV6yfm5mxiBQcoABDsYr28MOMQoycGkJMr7W3h7pBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3 jJtoJxgUWp6akVaZg4wXmDSEhw8SiK8WVpAad7igsTc4sx0iNQpRnuOC3cu/WHiOLbpMpA8sO cWkOy4efcPkxBLXn5eqpQ4bxHIVAGQtozSPLihsPi+xCgrJczLCHSmEE9BalFuZgmq/CtGcQ5 GJWHexSBTeDLzSuB2vwI6iwnoLJ5LW0DOKklESEk1MDL3VBtU387QNbDfer2yfNUNyew9cy+9 2sqpy/DEfYp0yAnXRovnS0JK+Mp4TJ3kU02vvF7c+vfrBv1HQvdDOk9sM4m/oDmB/bBn9bstI Z2tYgtD7U7/fnHRdZmY8bvyyml6wREHQ5tXHy9YbfytTC74guKR9MnSmp0zLFwvR8x9u+Bv96 Otn5VYijMSDbWYi4oTAaYQu3fqAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1505176669!82217233!1 X-Originating-IP: [209.85.220.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 62822 invoked from network); 12 Sep 2017 00:37:50 -0000 Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by server-8.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:37:50 -0000 Received: by mail-qk0-f196.google.com with SMTP id r66so6217917qke.4 for ; Mon, 11 Sep 2017 17:37:50 -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=IzmWCTN4AvTeo0KkxudIo6Ya7L5ZivwcFz4jYY6V2q8=; b=QwsAz8b21CbAuVLMBokCjruV448M64tY4Jxf58WTGK53FsTwmloEMSkzUpdQYro2/r r9FHmbfUHtMIKEwu3XY5spicZS/KRalJ80m8ZeRvhQQjuGb+YL1FE/aw+9WR+j0RRk7i AIRprkTOg92TyC7jWc/HxVeSiS+Nnv/JCa58F2jGd9n3NNqiZpk7DuirKS8APgpvNkOR WG7r+z67zoQvW2PAtLHOEzeGSa6igCAAQEDN3h3wlk+UXrJ1hQduPHx5CF7aYmNm6a93 ImagRtTAuVNrxM4tRw+VIRVdELu12HxXMs00HtDtfxEWmhWi1zJgkpSEMDF4Sn9umsuA qIHg== 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=IzmWCTN4AvTeo0KkxudIo6Ya7L5ZivwcFz4jYY6V2q8=; b=b6dJjka8xugA7s/ME/uk43g5bql4tqxP75KMtzDFWOKfWDpGtP4t6FEEUjjARZsK58 RAGuX4jUvxDm1jWjTf7QoWziqnkS8v/KQcyEdplTAVHeYU3GLssII+zNFjcAMye2c6cT cg8mMjggg2exuROTIxGRsL6MhM0hNBD2/b2FmkMKcUr5Y1Ol2RR6SCo2ZYpBw5WXZTvY G/4em53h7vScyJDk8soBlov043ztR+m2OVVtW64/cdefpf0VArGn3a4TUzy1UQXfEMb3 iMpXIqedNIm+PNTEHMXHcrtkwB0LNwUhgVeBS9b2UVhSgEejd5hIF9aBqeC6nwTMQTDK +Z+g== X-Gm-Message-State: AHPjjUg/KLTjaL0mX6xQMrnrtFnyLw+K+1UBPWvWEiVksH4ACJCQTmd7 N15v8LnqvNsFgsH3 X-Google-Smtp-Source: AOwi7QAi4E2Ixl9BXaeMZc+EHNvLGwna0PebOx7nTBoYUheJEW/Nz42TJ2WSMO500rcPBxRyBGwetg== X-Received: by 10.55.104.138 with SMTP id d132mr18724837qkc.151.1505176669146; Mon, 11 Sep 2017 17:37:49 -0700 (PDT) Received: from localhost.localdomain (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 z75sm6771034qkb.71.2017.09.11.17.37.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:37:48 -0700 (PDT) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad.wilk@oracle.com, julien.grall@arm.com, sstabellini@kernel.org Date: Mon, 11 Sep 2017 20:37:12 -0400 Message-Id: <20170912003726.368-4-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170912003726.368-1-konrad.wilk@oracle.com> References: <20170912003726.368-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v3 03/17] 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 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. Also fix one case where we would fail if the size of the .ex_table was being zero - but that is OK. 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. v3: - Drop bool zero_ok - Return bool instead of int (and invert the return condition) - Change name of the function to be more clear --- xen/common/livepatch.c | 46 +++++++++++++++++++++----------------------- xen/include/xen/elfstructs.h | 2 ++ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index a1f54c42d3..c6ee95fbcf 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -460,6 +460,22 @@ static int secure_payload(struct payload *payload, struct livepatch_elf *elf) return rc; } +static bool section_ok(const struct livepatch_elf *elf, + const struct livepatch_elf_sec *sec, size_t sz) +{ + if ( !elf || !sec ) + return false; + + if ( 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 false; + } + + return true; +} + static int check_special_sections(const struct livepatch_elf *elf) { unsigned int i; @@ -509,12 +525,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 ( !section_ok(elf, sec, sizeof(*payload->funcs)) ) return -EINVAL; - } payload->funcs = sec->load_addr; payload->nfuncs = sec->sec->sh_size / sizeof(*payload->funcs); @@ -556,7 +568,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 ( !section_ok(elf, sec, sizeof(*payload->load_funcs)) ) return -EINVAL; payload->load_funcs = sec->load_addr; @@ -566,7 +578,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 ( !section_ok(elf, sec, sizeof(*payload->unload_funcs)) ) return -EINVAL; payload->unload_funcs = sec->load_addr; @@ -637,12 +649,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 ( !section_ok(elf, sec, sizeof(*region->frame[i].bugs)) ) return -EINVAL; - } region->frame[i].bugs = sec->load_addr; region->frame[i].n_bugs = sec->sec->sh_size / @@ -655,12 +663,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 ( !section_ok(elf, sec, sizeof(*a)) ) return -EINVAL; - } start = sec->load_addr; end = sec->load_addr + sec->sec->sh_size; @@ -692,14 +696,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 ( !section_ok(elf, sec, sizeof(*region->ex)) ) 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