From patchwork Wed Sep 18 07:35:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11149733 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 67D5914E5 for ; Wed, 18 Sep 2019 07:37:51 +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 4352621920 for ; Wed, 18 Sep 2019 07:37:51 +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="WX6vQzpq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4352621920 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 1iAUVM-0005LZ-DJ; Wed, 18 Sep 2019 07:36:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iAUVK-0005LU-T8 for xen-devel@lists.xenproject.org; Wed, 18 Sep 2019 07:35:59 +0000 X-Inumbo-ID: f425aae4-d9e6-11e9-b299-bc764e2007e4 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f425aae4-d9e6-11e9-b299-bc764e2007e4; Wed, 18 Sep 2019 07:35:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1568792157; x=1600328157; h=from:to:cc:subject:date:message-id:mime-version; bh=lTJmZlcrzCZECR9cZB5bPN/VI+R4g75oO1zPYrAPLQM=; b=WX6vQzpqAdZ7DgShmR+yK7wlfDLt+Tt03MvLk2JtWRSziTgx4Q5amQiM LjFmr0aGPNNOWLn1L08c2HOJLwALLFhqD1GF33HtR+hjj0kXpxr5g2sjG rzvIdgBJJubw52gmPvo2raQIB5NwxJ3l7adWeuAiK5cIzgHlFr2sKIpsQ Q=; X-IronPort-AV: E=Sophos;i="5.64,519,1559520000"; d="scan'208";a="833753052" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2a-e7be2041.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP; 18 Sep 2019 07:35:54 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-e7be2041.us-west-2.amazon.com (Postfix) with ESMTPS id AA1D5A0830; Wed, 18 Sep 2019 07:35:53 +0000 (UTC) Received: from EX13D05EUB001.ant.amazon.com (10.43.166.87) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Sep 2019 07:35:53 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D05EUB001.ant.amazon.com (10.43.166.87) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 18 Sep 2019 07:35:52 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.62.226) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 18 Sep 2019 07:35:50 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 18 Sep 2019 07:35:38 +0000 Message-ID: <20190918073538.24707-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH] create-diff-object: more precisely identify .rodata sections 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, Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , mpohlack@amazon.com, Tim Deegan , Pawel Wieczorkiewicz , Julien Grall , Jan Beulich Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is needed for more precise patchability verification. Only non-special .rodata sections should be subject for such a non-referenced check in kpatch_verify_patchability(). Current check (non-standard, non-rela, non-debug) is too weak and allows also non-rodata sections without referenced symbols to slip through. Detect .rodata section by checking section's type (SHT_PROGBITS), flags (no exec, no write) and finally name prefix. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- common.c | 7 +++++++ common.h | 1 + create-diff-object.c | 13 ++++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/common.c b/common.c index 0ddc9fa..8f553ea 100644 --- a/common.c +++ b/common.c @@ -249,6 +249,13 @@ int is_text_section(struct section *sec) (sec->sh.sh_flags & SHF_EXECINSTR)); } +int is_rodata_section(struct section *sec) +{ + return sec->sh.sh_type == SHT_PROGBITS && + !(sec->sh.sh_flags & (SHF_EXECINSTR | SHF_WRITE)) && + !strncmp(sec->name, ".rodata", 7); +} + int is_debug_section(struct section *sec) { char *name; diff --git a/common.h b/common.h index 7c6fb73..b6489db 100644 --- a/common.h +++ b/common.h @@ -159,6 +159,7 @@ struct symbol *find_symbol_by_index(struct list_head *list, size_t index); struct symbol *find_symbol_by_name(struct list_head *list, const char *name); int is_text_section(struct section *sec); +int is_rodata_section(struct section *sec); int is_debug_section(struct section *sec); int is_rela_section(struct section *sec); int is_standard_section(struct section *sec); diff --git a/create-diff-object.c b/create-diff-object.c index e4592a6..2f0e162 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1672,13 +1672,12 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) } if (sec->include) { - if (!is_standard_section(sec) && !is_rela_section(sec) && - !is_debug_section(sec) && !is_special_section(sec)) { - if (!is_referenced_section(sec, kelf)) { - log_normal("section %s included, but not referenced\n", - sec->name); - errs++; - } + if (is_rodata_section(sec) && + !is_special_section(sec) && + !is_referenced_section(sec, kelf)) { + log_normal(".rodata section %s included, but not referenced\n", + sec->name); + errs++; } /* Check if a RELA section does not contain any entries with