From patchwork Wed Sep 20 22:31:39 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: 9962701 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 1D4FC601D5 for ; Wed, 20 Sep 2017 22:34:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 068FB2926F for ; Wed, 20 Sep 2017 22:34:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF42729277; Wed, 20 Sep 2017 22:34:44 +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 41B0B2926F for ; Wed, 20 Sep 2017 22:34:43 +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 1dunXN-0007E2-7i; Wed, 20 Sep 2017 22:32:09 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dunXM-0007DZ-A0 for xen-devel@lists.xenproject.org; Wed, 20 Sep 2017 22:32:08 +0000 Received: from [85.158.143.35] by server-10.bemta-6.messagelabs.com id AD/EB-03642-76CE2C95; Wed, 20 Sep 2017 22:32:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRWlGSWpSXmKPExsVyMfTGEd20N4c iDS7+sbT4vmUykwOjx+EPV1gCGKNYM/OS8isSWDOerb7KUnBXoOLS5e1sDYyPeboYuTiEBKYz Six5+4wRxGER+MAiMf/3WWYQR0JgGqtEw5WNrF2MnEBOlsSqXeeh7DSJ+afuQtmVEr+vNbCD2 EICShJbJj9mhLAPMUkc7i4EsYUF9CQmf7sNFmcT0Jd4uvYa0AIOoF43iU/XuEB2iQi0M0rMvv ILbCazgKFE69ujbBC9dhLn964Bs1kEVCXaWjpYQGxeAWuJK1/vQ90gLzGxdxrYfE4BG4n9nzq ZIW6wlniy9TTbBEbhBYwMqxg1ilOLylKLdA0N9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK 9ZLzczcxAkOUAQh2MH5aFnCIUZKDSUmU1/rloUghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErzGr 4FygkWp6akVaZk5wGiBSUtw8CiJ8C54BZTmLS5IzC3OTIdInWK05Lhw59IfJo4De24ByY6bd/ 8wCbHk5eelSonzfgVpEABpyCjNgxsHi+hLjLJSwryMQAcK8RSkFuVmlqDKv2IU52BUEua9AjK FJzOvBG7rK6CDmIAOyt5wAOSgkkSElFQDo9rDiODU+87tJ1pYpr9mW/HzJOv99XMWvpKrWb++ qtrqZGeyzTEmccnQIxvqVn3p31o5zc+xfvLFxwVz/OqDX8fz7X1y9pyFzFv54HOJOc5y+nNFH Q9eP/WsJyDvBJ/udKWTU07Muc+09F9d8zV36bxJczbWRxl6G0x5IupQvveczJfzHyNZtZVYij MSDbWYi4oTATOsybTjAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1505946726!83735868!1 X-Originating-IP: [209.85.216.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 20469 invoked from network); 20 Sep 2017 22:32:06 -0000 Received: from mail-qt0-f196.google.com (HELO mail-qt0-f196.google.com) (209.85.216.196) by server-8.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 20 Sep 2017 22:32:06 -0000 Received: by mail-qt0-f196.google.com with SMTP id o3so2083988qte.5 for ; Wed, 20 Sep 2017 15:32:06 -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=Ej18JygWRgkuVpjyiL03CkRDUqFNXOkOoV6sfSZWg8U=; b=cZtiXNemvzAVXsAs97gkh2nlTT0xdo7f0+85elA98qh+vw1Mkopox6HDoZHuwdOSRe pyyq86hH2l3BeglcGxtq7m6nE4HEJZE2fcHPrIO+IR0eco+5bvS//yoShlL3ua/U7klD jerruL1WLP9L17nuLUVPjlx09r9vThmQwh81wQdIa7joDEZNpsUWoKvtKYBZYf7rO8wV kZ/jqAigcJRg5EjG/A2JKKe2B0M6p+UaVljeUrwHXxs1WC0d8ywyb1N+3+vAKCf7EO9l MgID3nXvQ7zp4EociO9Cx74NmoViPk4n7e5WtFhxRsgTWGfBSK0K1XMv2dJU1/K2pGpt 1NsQ== 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=Ej18JygWRgkuVpjyiL03CkRDUqFNXOkOoV6sfSZWg8U=; b=qvx+GuXnIV9G3OzTvXrI6XooBvpjOQWopOkH2xakrcU8NjJAQ0C6DYX+462sgF+jBQ +xhvDiioHxk0Czmeo1+CBVvLxMN7/UgJS0Y1mdDYYJ8AVVNHOPrx9Szq48OM4mHuaYpy 6Bjnig4N4vUKe15nh8zAekDeXjwfG36O+TWPtbaUJiJiKqIfCnzRNuxvJSIJ8j2l/JIK C7ElpWC5YQ2Rj1De2lSXwRTbcX8Nkp739jNx+lSpQKSqbdpMU8wANTWxJQgMI1NbAdC6 uXpJBMm6Sc7HNwvDHo1hP/7w/z7Q+70+IfuT/focgLze4ea5xU3/9IVpiWjg4jyDOBXq tMag== X-Gm-Message-State: AHPjjUhfx0GvgJaG2C5G0VKxiQLQLFbNjM86xHZz3G5tP99oFyOYA1E7 tHVUQ+quz5+7+OlubnSJXd9nTA== X-Google-Smtp-Source: AOwi7QAZ8v5xclRGpICChIn0C+qSluyfOtBWTizmkCNx8PIHoiwRNdp4urQ91ZGaAUoBbrJmvnO4bQ== X-Received: by 10.200.27.226 with SMTP id m31mr397420qtk.198.1505946725633; Wed, 20 Sep 2017 15:32:05 -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 z192sm2012656qka.91.2017.09.20.15.32.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Sep 2017 15:32:05 -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: Wed, 20 Sep 2017 18:31:39 -0400 Message-Id: <20170920223148.13137-3-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170920223148.13137-1-konrad.wilk@oracle.com> References: <20170920223148.13137-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v4 02/11] 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. Reviewed-by: Jan Beulich Signed-off-by: Konrad Rzeszutek Wilk --- Cc: Ross Lagerwall 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. v4: Add Jan's Reviewed-by. Swap the two conditionals around. --- 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..dd8b47a1fa 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_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_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_flags & (SHF_WRITE | SHF_ALLOC)) && sec[i].sec->sh_type == SHT_NOBITS && sec[i].sec->sh_size > LIVEPATCH_MAX_SIZE )