From patchwork Wed Aug 21 08:20:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1804A1399 for ; Wed, 21 Aug 2019 08:23:26 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E967122DA7 for ; Wed, 21 Aug 2019 08:23:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="hj++1gUr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E967122DA7 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsH-0001aA-AT; Wed, 21 Aug 2019 08:21:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsF-0001VS-CU for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:43 +0000 X-Inumbo-ID: b4fd1f7e-c3ec-11e9-b95f-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b4fd1f7e-c3ec-11e9-b95f-bc764e2007e4; Wed, 21 Aug 2019 08:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375702; x=1597911702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=7aVYeW5cNqin5qJvvkplbDWIdkv5EFumHOM5UQLhOfs=; b=hj++1gUrYXJol95EV07D/bztaRUABP7njql56bdhUfm9t/oKWXVHTTtI 6abDlVAreAfDq1PhuOU8DwwTk0W5ZrYEwdSnrD6JM+0gAFHvRYPMvllMN UZr0yaSxiv/EQt5IVDcfHtFu3fT7LZvI07nvVXF9XflKwtRYmApTHgBqB U=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="695968567" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-baacba05.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 21 Aug 2019 08:21:42 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2b-baacba05.us-west-2.amazon.com (Postfix) with ESMTPS id D44F5A243C; Wed, 21 Aug 2019 08:21:41 +0000 (UTC) Received: from EX13D03EUA002.ant.amazon.com (10.43.165.166) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:27 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUA002.ant.amazon.com (10.43.165.166) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:26 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.60.129) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 21 Aug 2019 08:21:24 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:48 +0000 Message-ID: <20190821082056.91090-13-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190821082056.91090-1-wipawel@amazon.de> References: <20190821082056.91090-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 12/20] 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: wipawel@amazon.com, Konrad Rzeszutek Wilk , Andrew Cooper , Ross Lagerwall , mpohlack@amazon.com, Pawel Wieczorkiewicz Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 Reviewed-by: Ross Lagerwall --- create-diff-object.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 4e0f3be..1c84f81 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1536,6 +1536,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 an undefined 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; @@ -1568,6 +1623,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++; + } } /*