From patchwork Tue Nov 5 15:37:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11228191 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 7F3E01599 for ; Tue, 5 Nov 2019 15:39:48 +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 5B3D42190F for ; Tue, 5 Nov 2019 15:39:48 +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="hJr7o9bY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5B3D42190F 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 1iS0uY-0007yO-G1; Tue, 05 Nov 2019 15:38:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iS0uX-0007yB-Je for xen-devel@lists.xenproject.org; Tue, 05 Nov 2019 15:38:25 +0000 X-Inumbo-ID: 4dd3a106-ffe2-11e9-9631-bc764e2007e4 Received: from smtp-fw-9102.amazon.com (unknown [207.171.184.29]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4dd3a106-ffe2-11e9-9631-bc764e2007e4; Tue, 05 Nov 2019 15:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1572968306; x=1604504306; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=lTJmZlcrzCZECR9cZB5bPN/VI+R4g75oO1zPYrAPLQM=; b=hJr7o9bYRmexMMkjKdv0l9U4rCr1/VPj97NCV1xvggn4xZcCSmjUZ4tW Rq3k+1rywv0mdVyxsOIb2iGB8OMxLSpUPZyIT81px6sYODZW2srTNQiRV /Q6btSkiwhzjOPqmnjCkqrduZfWnwMAYUdQtMRYm3OHGsyTHAkNXKeyPY c=; IronPort-SDR: cdgjU8AHYCF+kMak7E4lc97FWNGp8u8brBnHg5T71Vdcl3KL3wk13TcQg4TppE/yn0lt5aypBb XiYXvtoiWmeQ== X-IronPort-AV: E=Sophos;i="5.68,271,1569283200"; d="scan'208";a="4028953" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 05 Nov 2019 15:38:19 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (Postfix) with ESMTPS id BE797242386; Tue, 5 Nov 2019 15:38:17 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 5 Nov 2019 15:38:15 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 5 Nov 2019 15:38:14 +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; Tue, 5 Nov 2019 15:38:13 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 5 Nov 2019 15:37:45 +0000 Message-ID: <20191105153745.74257-2-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20191105153745.74257-1-wipawel@amazon.de> References: <20191105153745.74257-1-wipawel@amazon.de> 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: Pawel Wieczorkiewicz , wipawel@amazon.com, Ross Lagerwall , mpohlack@amazon.com, Konrad Rzeszutek Wilk 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 Reviewed-by: Ross Lagerwall --- 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