From patchwork Tue Sep 12 00:37:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9948251 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 4CB116038F for ; Tue, 12 Sep 2017 00:41:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E97128CE9 for ; Tue, 12 Sep 2017 00:41:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 305D028D31; Tue, 12 Sep 2017 00:41:13 +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 284B828D6E for ; Tue, 12 Sep 2017 00:41:04 +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 1drZD6-0000cj-4U; Tue, 12 Sep 2017 00:37:52 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZD4-0000c7-Sn for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:37:50 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 47/54-03423-E5C27B95; Tue, 12 Sep 2017 00:37:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRWlGSWpSXmKPExsVyMfTOEd1Yne2 RBmsOylh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkbJpgV7OevmHWrn6mB8TZ3FyMXh5DADEaJ GS/WM4M4LAIfWCR2Lt3NCuJICExjlZh3fh5bFyMnkBMn8XvLM2YIO03i6bFrUHa5RMekBhYQW 0hASWLL5MeMEGMPMkkcXL8PrFlYQE9i8rfbjCA2m4C+xNO1IM0cQM1uEp+ucYHUiwi0M0rMvv KLFaSGWcBQovXtUaheO4nmzh1gcRYBVYmWCWvZQWxeAUuJZacOMkIcIS8xsXcamM0pYCXx+8c 8VoiDLCU6FlxhmsAovICRYRWjRnFqUVlqka6hoV5SUWZ6RkluYmaOrqGBmV5uanFxYnpqTmJS sV5yfu4mRmCIMgDBDsZPywIOMUpyMCmJ8v4W3h4pxJeUn1KZkVicEV9UmpNafIhRhoNDSYJ3h RZQTrAoNT21Ii0zBxgtMGkJDh4lEd4skDRvcUFibnFmOkTqFKMlx4U7l/4wcRzYcwtIdty8+4 dJiCUvPy9VSpy3SBuoQQCkIaM0D24cLKIvMcpKCfMyAh0oxFOQWpSbWYIq/4pRnINRSZh3Hch ansy8Eritr4AOYgI6iOfSFpCDShIRUlINjLyll2pfpipf1VT8PNGjmvESX2HQL64VO+yS9C2v 6sUGXy3T6deqYa05r3HvnMeOnUYs4TtuxMc2SUZrfmYV5GX4UPjcuOGetMQdf6dTUx/Nlt3fu jdkb9hMS7uGVb9+lDIqfd9Ryu611s/00K/n8yO3LFar37KUN3FhavRvJ5mdBvxv+xa0KbEUZy QaajEXFScCAAWd0dXjAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-8.tower-27.messagelabs.com!1505176668!105328688!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.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27193 invoked from network); 12 Sep 2017 00:37:49 -0000 Received: from mail-qk0-f196.google.com (HELO mail-qk0-f196.google.com) (209.85.220.196) by server-8.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:37:49 -0000 Received: by mail-qk0-f196.google.com with SMTP id r66so6217903qke.4 for ; Mon, 11 Sep 2017 17:37:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=mC2ck5Ql2e16Qf9ReObnE3HeJrYSf9BFvW/hX0mO6qk=; b=StZdl5zoT6klMiqDLz8qJBkrFUVp2jLxmWxcS/pg6NdEfqUEaqaDzUPR5VPEBQbY/6 opy32TMR2+vp1cz8E7UaMaFbadPZEflZfWGWXp9N+hbDyn9Zz1o0NK3xvKNSfohCmPAL x8jXcovK10H+Z78IGcKGPvNMxB4Mq89XCEEKOGMjMgTJtOiBaU0XaUkGDMavdgXQhqZt pfDUm4BrKV8BZwWEDkqMpDhoBiO/Kn1qITImQZ3v8eVuVrzuIAFD9Jd6TL0SUUMzbXYz x3epGWUL8SSC0QEMFhUzvtBQjRas9TsD/KXARxsgxEsRnct3xqqGeHBufwMYhpiWj0ej z0/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=mC2ck5Ql2e16Qf9ReObnE3HeJrYSf9BFvW/hX0mO6qk=; b=XtIAQGMqq+ME9eZlDHqadJIEvARm7fEGFz7FQpBlTVCVYYCZATsS43DDGNIvkhpNUT nk5VNBZ0AqNPiAdW5Hbp6rO49TYzFsQa2flAJHqVOhwVXxQUpsUrSy88579ckR21UFcg +onxtgA2/JimCnkUkiMKi4R9KUA8oMwId/o2vZXITjGFckpG5wX+3shxMJ4g7Go3ooDt 4fl4G5VHNbi9b+S8x6qjYy6DwSPWpH6+mRk5tFSIKoXFZqGW/exU5p1/+n446BNQl6jN /fT8RgeC+EmjrxQaqe8IQYAfrniPeqD7kuBwBBVWo/sZiiuvA8IPG/9aTCqIZwcRkUNB 2hOA== X-Gm-Message-State: AHPjjUjf+OeKCJiErIsq9fYq55HcnfSuGzLhYSYfIg4ZOTEvWluS2KCU dMpb2ZCwf43EGEnA X-Google-Smtp-Source: AOwi7QDhjio65HhzJaaqdcutf5rLG/6fEwORB8oVZaRu2ntxV5xTWwfKqD+try6gDcJNa0SXVhrG/g== X-Received: by 10.55.21.5 with SMTP id f5mr13502281qkh.335.1505176668173; Mon, 11 Sep 2017 17:37:48 -0700 (PDT) Received: from localhost.localdomain (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id z75sm6771034qkb.71.2017.09.11.17.37.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:37:47 -0700 (PDT) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad.wilk@oracle.com, julien.grall@arm.com, sstabellini@kernel.org Date: Mon, 11 Sep 2017 20:37:11 -0400 Message-Id: <20170912003726.368-3-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170912003726.368-1-konrad.wilk@oracle.com> References: <20170912003726.368-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v3 02/17] livepatch: Tighten alignment checks. 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 The ELF specification mentions nothing about the sh_size being modulo the sh_addralign. Only that sh_addr MUST be aligned on sh_addralign if sh_addralign is not zero or one. We on loading did not take this in-to account so this patch adds a check on the ELF file as it is being parsed. Signed-off-by: Konrad Rzeszutek Wilk Reviewed-by: Jan Beulich --- v1: Initial patch v2: Drop the check when loading it in memory Add check for alignment being anything but power of two (ignoring 0, and 1) Change dprintk to include hex values and print addr not size. v3: Change the two checks to be per Jan's recommendations. --- xen/common/livepatch_elf.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c index b69e2718dd..7839913ff5 100644 --- a/xen/common/livepatch_elf.c +++ b/xen/common/livepatch_elf.c @@ -86,6 +86,19 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data) delta < sizeof(Elf_Ehdr) ? "at ELF header" : "is past end"); return -EINVAL; } + else if ( sec[i].sec->sh_addralign && + sec[i].sec->sh_addr % sec[i].sec->sh_addralign ) + { + dprintk(XENLOG_ERR, LIVEPATCH "%s: Section [%u] addr (%#"PRIxElfAddr") is not aligned properly (%#"PRIxElfAddr")\n", + elf->name, i, sec[i].sec->sh_addr, sec[i].sec->sh_addralign); + return -EINVAL; + } + else if ( sec[i].sec->sh_addralign & (sec[i].sec->sh_addralign - 1) ) + { + dprintk(XENLOG_ERR, LIVEPATCH "%s: Section [%u] alignment (%#"PRIxElfAddr") is not supported\n", + elf->name, i, sec[i].sec->sh_addralign); + return -EOPNOTSUPP; + } else if ( (sec[i].sec->sh_flags & (SHF_WRITE | SHF_ALLOC)) && sec[i].sec->sh_type == SHT_NOBITS && sec[i].sec->sh_size > LIVEPATCH_MAX_SIZE )