From patchwork Tue Oct 8 23:12:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 11180129 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 4BEEA76 for ; Tue, 8 Oct 2019 23:13:58 +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 2801220873 for ; Tue, 8 Oct 2019 23:13:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="e4kkOPze" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2801220873 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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 1iHyed-0000Wv-8v; Tue, 08 Oct 2019 23:12:31 +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 1iHyec-0000Wq-Ez for xen-devel@lists.xenproject.org; Tue, 08 Oct 2019 23:12:30 +0000 X-Inumbo-ID: 19abcf38-ea21-11e9-97da-12813bfff9fa Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 19abcf38-ea21-11e9-97da-12813bfff9fa; Tue, 08 Oct 2019 23:12:30 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.xilinx.com (c-67-164-102-47.hsd1.ca.comcast.net [67.164.102.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1F45620873; Tue, 8 Oct 2019 23:12:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570576349; bh=25iMfaqC1F6oK1rkD/uiw057ATgoxbtKJ0lJwKT6Tsw=; h=From:To:Cc:Subject:Date:From; b=e4kkOPzexdixkdtVK06jaUcDt/vQ1bDLHt+upTq95fT1boF1ZH+uNYfzPnHnZOKsz jfBfdMzvymwgV/LUs7FZXxJTPZeoXM/zQTR1TbIoaCpanSXgXbYqd+LxntB9N2+5yT pXjzShQgONOninXC2BjtjYXM8I/8MwN9mpMRNXhc= From: Stefano Stabellini To: xen-devel@lists.xenproject.org Date: Tue, 8 Oct 2019 16:12:11 -0700 Message-Id: <20191008231211.31110-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 Subject: [Xen-devel] [PATCH for-4.13 v3] xen/arm: fix buf size in make_cpus_node X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: jgross@suse.com, Julien.Grall@arm.com, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com, Stefano Stabellini MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The size of buf is calculated wrongly: the number is printed as a hexadecimal number, so we need 8 bytes for 32bit, not 10 bytes. As a result, it should be sizeof("cpu@") + 8 bytes for a 32-bit number + 1 byte for \0. Total = 13. mpidr_aff is 64-bit, however, only bits [0-23] are used. Add a check for that. Fixes: c81a791d34 (xen/arm: Set 'reg' of cpu node for dom0 to match MPIDR's affinity) Signed-off-by: Stefano Stabellini Release-acked-by: Juergen Gross --- Changes in v3: - make sure only [23:0] bits are used in mpidr_aff - clarify that we only need 32bit for buf writes Changes in v2: - patch added --- xen/arch/arm/domain_build.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 921b054520..d5ee639548 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -789,7 +789,7 @@ static int __init make_cpus_node(const struct domain *d, void *fdt) const void *compatible = NULL; u32 len; /* Placeholder for cpu@ + a 32-bit number + \0 */ - char buf[15]; + char buf[13]; u32 clock_frequency; bool clock_valid; uint64_t mpidr_aff; @@ -847,8 +847,18 @@ static int __init make_cpus_node(const struct domain *d, void *fdt) * the MPIDR's affinity bits. We will use AFF0 and AFF1 when * constructing the reg value of the guest at the moment, for it * is enough for the current max vcpu number. + * + * We only deal with AFF{0, 1, 2} stored in bits [23:0] at the + * moment. */ mpidr_aff = vcpuid_to_vaffinity(cpu); + if ( (mpidr_aff & ~GENMASK_ULL(23, 0)) != 0 ) + { + printk(XENLOG_ERR "Unable to handle MPIDR AFFINITY 0x%"PRIx64"\n", + mpidr_aff); + return -EINVAL; + } + dt_dprintk("Create cpu@%"PRIx64" (logical CPUID: %d) node\n", mpidr_aff, cpu);