From nobody Sat Feb 7 09:34:06 2026 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1570668190; cv=none; d=zoho.com; s=zohoarc; b=Eo20vEwtI8V1XyY4rmvjcA5UzkhfqN3i0STbtqLSrsnQLqjU4/yhf2DaVL8ZOCA5D+4Q0pM5f6y6RoRUwPP3JxF8U4O1cgpBtV922+guOSLnUZfh7tjs2ZCHpVd5DFG3X7jbUabTEqJFUi0kl1k3jSY3bE6tZCKp72A6K8jzJxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570668190; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZjpTrZW7Ooie93su7mqIytq0P//iTbuXHb09OMe2c7Q=; b=GiQiaexe7QBg6ll15mLnw20H5tgH/XJa20lZrRavtwyd4h4oNBjoLdmOxom0Hv2hjQuNGdDrDm3HQswbW8TIfX4Pp10Uj7iI2pG5IHTwrX/IsAXQrhZl7zlh82EmaR5oqsjQgXK0UQxLob/mcR2vngFGqjXsDjNcVT7Vlhotn7M= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1570668190417631.1426682266366; Wed, 9 Oct 2019 17:43:10 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIMX1-0005jS-ER; Thu, 10 Oct 2019 00:42:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIMX0-0005jK-IW for xen-devel@lists.xenproject.org; Thu, 10 Oct 2019 00:42:14 +0000 Received: from mail.kernel.org (unknown [198.145.29.99]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ccd85cfe-eaf6-11e9-80e3-bc764e2007e4; Thu, 10 Oct 2019 00:42:13 +0000 (UTC) Received: from sstabellini-ThinkPad-T480s.hsd1.ca.comcast.net (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 9F67320B7C; Thu, 10 Oct 2019 00:42:12 +0000 (UTC) X-Inumbo-ID: ccd85cfe-eaf6-11e9-80e3-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570668132; bh=E3OgBK+Xi6PVuKpoyyJXGXOVa1BJjWGHTvZQUGqq9xo=; h=From:To:Cc:Subject:Date:From; b=AS5SUS4e9FgWN69OS/8LbXn5xW8dsa/JEicXEtStCYqn7Iwm5QtP8IQiVhPTDhomO VPV8HgcA/mgtciGC1wZPpy3AxViUQ/Gd2EBJ2A+X2+0c4cPyI0uihBZkwwztqHnjgO nGyPYB5g+AP5qN9VD0vB9jjmII+NpINrNy8Ly62A= From: Stefano Stabellini To: julien.grall@arm.com Date: Wed, 9 Oct 2019 17:42:11 -0700 Message-Id: <20191010004211.31017-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.17.1 Subject: [Xen-devel] [PATCH v4] xen/arm: domain_build: harden 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, xen-devel@lists.xenproject.org, sstabellini@kernel.org, Volodymyr_Babchuk@epam.com, Stefano Stabellini MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) make_cpus_node() is using a static buffer to generate the FDT node name. While mpdir_aff is a 64-bit integer, we only ever use the bits [23:0] as only AFF{0, 1, 2} are supported for now. To avoid any potential issues in the future, check that mpdir_aff has only bits [23:0] set. Take the opportunity to reduce the size of the buffer. Indeed, only 8 characters are needed to print a 32-bit hexadecimal number. So sizeof("cpu@") + 8 + 1 (for '\0') =3D 13 characters is sufficient. Fixes: c81a791d34 (xen/arm: Set 'reg' of cpu node for dom0 to match MPIDR's= affinity) Signed-off-by: Stefano Stabellini Reviewed-by: Julien Grall --- Changes in v4: - commit message - in-code comments 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 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 921b054520..38adb6e954 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -788,8 +788,8 @@ static int __init make_cpus_node(const struct domain *d= , void *fdt) unsigned int cpu; const void *compatible =3D NULL; u32 len; - /* Placeholder for cpu@ + a 32-bit number + \0 */ - char buf[15]; + /* Placeholder for cpu@ + a 32-bit hexadecimal number + \0 */ + char buf[13]; u32 clock_frequency; bool clock_valid; uint64_t mpidr_aff; @@ -847,11 +847,26 @@ 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 =3D vcpuid_to_vaffinity(cpu); + if ( (mpidr_aff & ~GENMASK_ULL(23, 0)) !=3D 0 ) + { + printk(XENLOG_ERR "Unable to handle MPIDR AFFINITY 0x%"PRIx64"= \n",=20 + mpidr_aff); + return -EINVAL; + } + dt_dprintk("Create cpu@%"PRIx64" (logical CPUID: %d) node\n", mpidr_aff, cpu); =20 + /* + * We use PRIx64 because mpidr_aff is a 64bit integer. However, + * only bits [23:0] are used, thus, we are sure it will fit in + * buf. + */ snprintf(buf, sizeof(buf), "cpu@%"PRIx64, mpidr_aff); res =3D fdt_begin_node(fdt, buf); if ( res ) --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel