From patchwork Thu Nov 24 01:08:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9444627 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30AB46075F for ; Thu, 24 Nov 2016 01:10:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A8A327D76 for ; Thu, 24 Nov 2016 01:10:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F40127DCD; Thu, 24 Nov 2016 01:10:45 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3C72827D8D for ; Thu, 24 Nov 2016 01:10:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c9iWu-0006BA-CR; Thu, 24 Nov 2016 01:08:48 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c9iWt-0006Ak-0p for xen-devel@lists.xenproject.org; Thu, 24 Nov 2016 01:08:47 +0000 Received: from [85.158.143.35] by server-8.bemta-6.messagelabs.com id 13/8B-15390-E9D36385; Thu, 24 Nov 2016 01:08:46 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsVyMfTOEd25tmY RBg1LtCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owTp/6zFEwXqVj9UaKB8YRAFyMXh5DATEaJ jS/nsHcxcnKwCHxgkTh+owQkISEwjVXi/OU9bCAJCYEYiUlnzrBD2BUSDx7fZgaxhQSUJLZMf swIMWkHk8S5jV1gRcICehKTv91mBLHZBPQlnq69BtYgIhAu8aLzEZDNwcEsoCtxcZ8HRHmixN wL66GOUJXYNvsBmM0rYCbxc9FzqBvkJC5t+wI2hlPAXGLq6r2MEDfkS5zpmcI+gVFwASPDKkb 14tSistQiXUu9pKLM9IyS3MTMHF1DAzO93NTi4sT01JzEpGK95PzcTYzAYGMAgh2MdzcFHGKU 5GBSEuVd/dk0QogvKT+lMiOxOCO+qDQntfgQowwHh5IE7xQbswghwaLU9NSKtMwcYNjDpCU4e JREeFeCpHmLCxJzizPTIVKnGI05Xn148YCJo+PDhwdMQix5+XmpUuK8Z0BKBUBKM0rz4AbB4v ESo6yUMC8j0GlCPAWpRbmZJajyrxjFORiVhHl3gEzhycwrgdv3CugUJqBTJL8Zg5xSkoiQkmp gZJU2dxHqOrNBaeU8acajp3crVtaUMSYLZloqimhO8/l0gl/p6Lw1l++anzH6XlK/RHD9fo44 v/PnfXeEqAXwc5xx3Xhkx1L7v13Odwtu7VmQoim0uCdhocw26QmeT4o+aK1dyzVbtclg3pTDd 3l6yxW2P9cuWywQ8i738iXbE9sX/j4UJ+xupsRSnJFoqMVcVJwIAME0WuzCAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1479949724!44772030!1 X-Originating-IP: [209.85.220.196] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60045 invoked from network); 24 Nov 2016 01:08:45 -0000 Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by server-8.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 24 Nov 2016 01:08:45 -0000 Received: by mail-qk0-f196.google.com with SMTP id x190so2184931qkb.0 for ; Wed, 23 Nov 2016 17:08:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fFpj7q4o0t7tIzLydnmgM4G/nMrM4RcqcdNrkVqQhos=; b=xchtPcNH18CRutAcMD2X0b4ZtDLUrGAUcl4XyPRJEKk39Ug1Aswig8ixR/bHUSW+WL S5zsZEbuKt9Tl1cQqMHc0rrHT4lB2hh0ZqYEzs/CCJRxGv77QBC2v/mr8FRr3dYhU4ti 8AUjh5QjdY7QM1F6kipVeyDqiXgWgFkBRlWRtDaRqJD1pC0lP6GYSUa/VBrsTx4qOV/c hyba8RlnaNd9YLo9HhZPXrxhmsafvLdpNPl50SbHGaP6kX0mUeQ6WJlT9FP7fzvooQ+U C2zZMJu27XbrjqO+zKp8ImSqsScqY5fcL6EQO1tXa1ctCHeJFyCQcRrQ5YCdpSrQzaBh Lrog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=fFpj7q4o0t7tIzLydnmgM4G/nMrM4RcqcdNrkVqQhos=; b=eq1zDOw1YDe/ZAGLQV4cZ/ydtfzNOxUQHEyeQDghpjzM74F3xZK0xLzs7LHD1wP+ZN T+TsHa47N7iYXFDqknpv2603HsabhJSFUo3hN0bSv7FcSV7QrE6duK2a5TizKetWLSEy 1YuuxgxcXEKCpWYGxqQwo7lKJXTVIdNmUQAyka4NqMqTrgbV/NYjyQDyHKWQUk052Dbc MVTRUlgeD1JM1TIFnfANqEqC0lT5zq4V0h8ENDN5ca+0LtOfIvvBL8kW/mflZ9EVcCeL BI++ETbjIwCJ7RQFShwwJXyGl/qJu+hW859OHXhmPD6vs9negpKdBKmjgFdzNFCDa/7z RGAA== X-Gm-Message-State: AKaTC019OKb++vanhRLWeSC5mmxxQj+42E2N3DvhhEPugR9YMTa9l1q002/VAsj05C4F+w== X-Received: by 10.55.78.147 with SMTP id c141mr6356635qkb.4.1479949724542; Wed, 23 Nov 2016 17:08:44 -0800 (PST) Received: from localhost.localdomain.com (209-6-196-81.c3-0.smr-ubr2.sbo-smr.ma.cable.rcn.com. [209.6.196.81]) by smtp.gmail.com with ESMTPSA id u13sm17694656qtc.37.2016.11.23.17.08.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Nov 2016 17:08:44 -0800 (PST) From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, m.a.young@durham.ac.uk Date: Wed, 23 Nov 2016 20:08:37 -0500 Message-Id: <20161124010837.18077-2-konrad@kernel.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161124010837.18077-1-konrad@kernel.org> References: <20161124010837.18077-1-konrad@kernel.org> Cc: Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH LIVEPATCH-BUILD-TOOLS] create-diff-object: Update fixup offsets in .rela.ex_table X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Ross Lagerwall When pruning entries from the fixup table, update the offsets in .rela.ex_table otherwise the relas might point to the wrong fixup entry or even out of the .fixup section. Signed-off-by: Ross Lagerwall Signed-off-by: Konrad Rzeszutek Wilk --- v2: Squashed fix from kpatch upstream [see https://github.com/dynup/kpatch/pull/616] --- create-diff-object.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index 69bcd88..58f7c4c 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1057,6 +1057,34 @@ static int should_keep_rela_group(struct section *sec, int start, int size) return found; } +/* + * When updating .fixup, the corresponding addends in .ex_table need to be + * updated too. Stash the result in rela.r_addend so that the calculation in + * fixup_group_size() is not affected. + */ +void kpatch_update_ex_table_addend(struct kpatch_elf *kelf, + struct special_section *special, + int src_offset, int dest_offset, + int group_size) +{ + struct rela *rela; + struct section *sec; + + if (strcmp(special->name, ".fixup")) + return; + + sec = find_section_by_name(&kelf->sections, ".rela.ex_table"); + if (!sec) + ERROR("missing .rela.ex_table section"); + + list_for_each_entry(rela, &sec->relas, list) { + if (!strcmp(rela->sym->name, ".fixup") && + rela->addend >= src_offset && + rela->addend < src_offset + group_size) + rela->rela.r_addend = rela->addend - (src_offset - dest_offset); + } +} + static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, struct special_section *special, struct section *sec) @@ -1073,6 +1101,14 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, if (!dest) ERROR("malloc"); + /* Restore the stashed r_addend from kpatch_update_ex_table_addend. */ + if (!strcmp(special->name, ".ex_table")) { + list_for_each_entry(rela, &sec->relas, list) { + if (!strcmp(rela->sym->name, ".fixup")) + rela->addend = rela->rela.r_addend; + } + } + group_size = 0; src_offset = 0; dest_offset = 0; @@ -1100,6 +1136,11 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, rela->rela.r_offset = rela->offset; rela->sym->include = 1; + + kpatch_update_ex_table_addend(kelf, special, + src_offset, + dest_offset, + group_size); } }