From patchwork Thu Aug 8 12:48:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11084089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A3AA14DB for ; Thu, 8 Aug 2019 12:50:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4684328A8F for ; Thu, 8 Aug 2019 12:50:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 380AB28B21; Thu, 8 Aug 2019 12:50:29 +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,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C5EA428A8F for ; Thu, 8 Aug 2019 12:50:28 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvhqT-0005h1-BG; Thu, 08 Aug 2019 12:48:41 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvhqR-0005gw-Tb for xen-devel@lists.xen.org; Thu, 08 Aug 2019 12:48:39 +0000 X-Inumbo-ID: d7c595f7-b9da-11e9-8980-bc764e045a96 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id d7c595f7-b9da-11e9-8980-bc764e045a96; Thu, 08 Aug 2019 12:48:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1565268518; x=1596804518; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=eAv3PQrHbGS7ayoKuo5sudyqQS72GJzUecBqKPQzui4=; b=Dg1VaLrLzGByeWN9lfzOhcbF3eECsVcAomOKjNOw8HEgdLZ8bMNioKpn 0g5cKZ+c/tv8SEDaVB+4U6RQvwhe4XEfxFvD+mFmo/AFG5LBlZFP8kgFr kem6XQkiaL+MHgsfGJANE0HJElGlxDmSxlRBAcf1J/vyzlTPoLilVGVG+ 4=; X-IronPort-AV: E=Sophos;i="5.64,361,1559520000"; d="scan'208";a="745774240" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-c5104f52.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 08 Aug 2019 12:48:37 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2a-c5104f52.us-west-2.amazon.com (Postfix) with ESMTPS id 28B02A274A; Thu, 8 Aug 2019 12:48:37 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 8 Aug 2019 12:48:36 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 8 Aug 2019 12:48:35 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 8 Aug 2019 12:48:34 +0000 From: Pawel Wieczorkiewicz To: Date: Thu, 8 Aug 2019 12:48:31 +0000 Message-ID: <20190808124831.10094-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416122241.28342-2-wipawel@amazon.de> References: <20190416122241.28342-2-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part3 v2 2/3] create-diff-object: Extend patchability verification: STN_UNDEF X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: mpohlack@amazon.de, ross.lagerwall@citrix.com, Pawel Wieczorkiewicz , konrad.wilk@oracle.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP During verification check if all sections do not contain any entries with undefined symbols (STN_UNDEF). This situation can happen when a section is copied over from its original object to a patched object, but various symbols related to the section are not copied along. This scenario happens typically during stacked hotpatches creation (between 2 different hotpatch modules). Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Martin Pohlack Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Andra-Irina Paraschiv --- v2: * Refactored code by creating a new function kpatch_section_has_undef_symbols() for the complicated multi-loop code of kpatch_verify_patchability(). Hopefully this makes code more readable and easier to maintain. * Kept lines limits to 80 chars (whereever possible) * Detection of an undefined symbol counts as a single error --- create-diff-object.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 41adb09..e905131 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1531,6 +1531,61 @@ static void kpatch_print_changes(struct kpatch_elf *kelf) } } +static inline int get_section_entry_size(const struct section *sec, + struct kpatch_elf *kelf) +{ + int entry_size; + + /* + * Base sections typically do not define fixed size elements. + * Detect section's element size in case it's a special section. + * Otherwise, skip it due to an unknown sh_entsize. + */ + entry_size = sec->sh.sh_entsize; + if (entry_size == 0) { + struct special_section *special; + + /* Find special section group_size. */ + for (special = special_sections; special->name; special++) { + if (!strcmp(sec->name, special->name)) + return special->group_size(kelf, 0); + } + } + + return entry_size; +} + +static int kpatch_section_has_undef_symbols(struct kpatch_elf *kelf, + const struct section *sec) +{ + int offset, entry_size; + struct rela *rela; + size_t d_size; + + entry_size = get_section_entry_size(sec, kelf); + if (entry_size == 0) + return false; + + d_size = sec->base->data->d_size; + for ( offset = 0; offset < d_size; offset += entry_size ) { + list_for_each_entry(rela, &sec->relas, list) { + if (rela->offset < offset || + rela->offset >= offset + entry_size) { + continue; + } + + if ((GELF_R_SYM(rela->rela.r_info) == STN_UNDEF) || + (!rela->sym->include && rela->sym->status == SAME)) { + log_normal("section %s has an entry with a STN_UNDEF symbol: %s\n", + sec->name, rela->sym->name ?: "none"); + return true; + } + } + } + + return false; +} + static void kpatch_verify_patchability(struct kpatch_elf *kelf) { struct section *sec; @@ -1563,6 +1618,17 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) errs++; } } + + /* Check if a RELA section does not contain any entries with + * undefined symbols (STN_UNDEF). This situation can happen + * when a section is copied over from its original object to + * a patched object, but various symbols related to the section + * are not copied along. + */ + if (is_rela_section(sec)) { + if (kpatch_section_has_undef_symbols(kelf, sec)) + errs++; + } } /*