From patchwork Tue Nov 26 10:07:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11261821 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 56C6715AC for ; Tue, 26 Nov 2019 10:09: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 335FE208C0 for ; Tue, 26 Nov 2019 10:09: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="nI+b/4ff" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 335FE208C0 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 1iZXmE-0007bU-Oz; Tue, 26 Nov 2019 10:08:58 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iZXmD-0007bF-Lh for xen-devel@lists.xenproject.org; Tue, 26 Nov 2019 10:08:57 +0000 X-Inumbo-ID: bdfbeadb-1034-11ea-a39d-12813bfff9fa Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id bdfbeadb-1034-11ea-a39d-12813bfff9fa; Tue, 26 Nov 2019 10:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1574762930; x=1606298930; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=2PDRsvrVZ4RXINE9Gvy2RTyL2HFgQ/FbBZ5RcRG6v0M=; b=nI+b/4ff42UDXvUEr1zrP8L5B9VoPZL7zEIU6gRHZcsodFENuCzeSNPw VoGzgXuUcGTJIxnIGwxZatPE+PSBDWYU/S3CKuO1wVx8ryrrwBFDOB+MS NbWgguj4WZbnL/1M9a6pDjowiD6w5XBC0eVmLi3fz2FRDyuHMcRSuFSq5 U=; IronPort-SDR: 5GdqnLAEgnq8M1jvEjPCiSR6zapGtKP1F6+ZmVzGDrr9iZj20zU4ieE5q0jUHqLWHKSu36Izya /p0/JMVl1Ryg== X-IronPort-AV: E=Sophos;i="5.69,245,1571702400"; d="scan'208";a="4927614" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1d-f273de60.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 26 Nov 2019 10:08:50 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-f273de60.us-east-1.amazon.com (Postfix) with ESMTPS id 3E1F5A0678; Tue, 26 Nov 2019 10:08:49 +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; Tue, 26 Nov 2019 10:08:35 +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; Tue, 26 Nov 2019 10:08:34 +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; Tue, 26 Nov 2019 10:08:32 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 26 Nov 2019 10:07:58 +0000 Message-ID: <20191126100801.124844-10-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20191126100801.124844-1-wipawel@amazon.de> References: <20191126100801.124844-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH v6 09/12] livepatch: Add support for modules .modinfo section metadata 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 , Ross Lagerwall , mpohlack@amazon.com, Konrad Rzeszutek Wilk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Having detailed livepatch metadata helps to properly identify module's origin and version. It also allows to keep track of the history of livepatch loads in the system (at least within dmesg buffer size limits). The livepatch metadata are embedded in a form of .modinfo section. Each such section contains data of the following format: key=value\0key=value\0...key=value\0 The .modinfo section may be generated and appended to the resulting livepatch ELF file optionally as an extra step of a higher level livepatch build system. The metadata section pointer and the section length is stored in the livepatch payload structure and is used to display the content upon livepatch apply operation. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Leonard Foerster Reviewed-by: Martin Pohlack Reviewed-by: Norbert Manthey Signed-off-by: Konrad Rzeszutek Wilk Reviewed-by: Ross Lagerwall --- Changed since v2: * Added .modinfo tests (Konrad) --- xen/common/livepatch.c | 34 ++++++++++++++++++++++++++++++++++ xen/include/xen/livepatch_payload.h | 6 ++++++ xen/test/livepatch/Makefile | 10 +++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 9923df9ed2..133f58bcf2 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -853,6 +853,23 @@ static int prepare_payload(struct payload *payload, #endif } + sec = livepatch_elf_sec_by_name(elf, ".modinfo"); + if ( sec ) + { + if ( !section_ok(elf, sec, sizeof(*payload->metadata.data)) ) + return -EINVAL; + + payload->metadata.data = sec->load_addr; + payload->metadata.len = sec->sec->sh_size; + + /* The metadata is required to consists of null terminated strings. */ + if ( payload->metadata.data[payload->metadata.len - 1] != '\0' ) + { + printk(XENLOG_ERR LIVEPATCH "%s: Incorrect metadata format detected\n", payload->name); + return -EINVAL; + } + } + return 0; } @@ -1201,6 +1218,19 @@ static int livepatch_list(struct xen_sysctl_livepatch_list *list) * for XEN_SYSCTL_LIVEPATCH_ACTION operation (see livepatch_action). */ +static inline void livepatch_display_metadata(const struct livepatch_metadata *metadata) +{ + const char *str; + + if ( metadata && metadata->data && metadata->len > 0 ) + { + printk(XENLOG_INFO LIVEPATCH "module metadata:\n"); + for ( str = metadata->data; str < (metadata->data + metadata->len); str += (strlen(str) + 1) ) + printk(XENLOG_INFO LIVEPATCH " %s\n", str); + } + +} + static int apply_payload(struct payload *data) { unsigned int i; @@ -1241,6 +1271,8 @@ static int apply_payload(struct payload *data) arch_livepatch_revive(); + livepatch_display_metadata(&data->metadata); + return 0; } @@ -2019,6 +2051,8 @@ static void livepatch_printall(unsigned char key) data->name, state2str(data->state), data->state, data->text_addr, data->rw_addr, data->ro_addr, data->pages); + livepatch_display_metadata(&data->metadata); + for ( i = 0; i < data->nfuncs; i++ ) { struct livepatch_func *f = &(data->funcs[i]); diff --git a/xen/include/xen/livepatch_payload.h b/xen/include/xen/livepatch_payload.h index ff16af0dd6..9f5f064205 100644 --- a/xen/include/xen/livepatch_payload.h +++ b/xen/include/xen/livepatch_payload.h @@ -33,6 +33,11 @@ struct livepatch_hooks { } apply, revert; }; +struct livepatch_metadata { + const char *data; /* Ptr to .modinfo section with ASCII data. */ + uint32_t len; /* Length of the metadata section. */ +}; + struct payload { uint32_t state; /* One of the LIVEPATCH_STATE_*. */ int32_t rc; /* 0 or -XEN_EXX. */ @@ -63,6 +68,7 @@ struct payload { unsigned int n_load_funcs; /* Nr of the funcs to load and execute. */ unsigned int n_unload_funcs; /* Nr of funcs to call durung unload. */ char name[XEN_LIVEPATCH_NAME_SIZE]; /* Name of it. */ + struct livepatch_metadata metadata; /* Module meta data record */ }; /* diff --git a/xen/test/livepatch/Makefile b/xen/test/livepatch/Makefile index cebd3eb49c..ebb343c314 100644 --- a/xen/test/livepatch/Makefile +++ b/xen/test/livepatch/Makefile @@ -79,9 +79,17 @@ config.h: xen_hello_world_func.o xen_hello_world.o: config.h .PHONY: $(LIVEPATCH) -$(LIVEPATCH): xen_hello_world_func.o xen_hello_world.o note.o xen_note.o +$(LIVEPATCH): xen_hello_world_func.o xen_hello_world.o note.o xen_note.o modinfo.o $(LD) $(LDFLAGS) $(build_id_linker) -r -o $(LIVEPATCH) $^ +.PHONY: modinfo.o +modinfo.o: + (set -e; \ + printf "LIVEPATCH_RULEZ\0") > $@.bin + $(OBJCOPY) $(OBJCOPY_MAGIC) \ + --rename-section=.data=.modinfo,alloc,load,readonly,data,contents -S $@.bin $@ + #rm -f $@.bin + # # This target is only accessible if CONFIG_LIVEPATCH is defined, which # depends on $(build_id_linker) being available. Hence we do not