From nobody Thu Apr 25 19:20:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1637619419; cv=none; d=zohomail.com; s=zohoarc; b=QWTWhHKvwU/T44jR9ovgusU5bxUM5dJSUQAg6hp38PCldxGinaieilN1rjFISsoqv0TpewiIB92b1uC+eMVJGfdmL5/0f5RBF1hkTKkkiN0beNehwRsdTgQ8Hi1qHVcJ3NCyBRRW7pngTlfPNT+9uIvbvh7yteNUTopQ60esElA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637619419; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=rvTz9/DQoyT2Ubv4MOz4HJbz39KzTit5RyGH5RKDOUg=; b=EY6T4LuhxRuQQYiSCvOgM6qGptJakHOs2b5drQ7w5l5XR/I8GD4NgCWZWhIUR5zWkqhNIGaKQXRfoLYXrQ0xUMoE9kaNCZjOm83HZYW6YTHOj9rMvAbthUVKnMd2l/YrA1PYZTsQ0x/Wqoau1gkqMLCk6ixHU8wmzYBPZO78aO4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1637619419776876.5692945546259; Mon, 22 Nov 2021 14:16:59 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.229093.396486 (Exim 4.92) (envelope-from ) id 1mpHc0-000569-Cs; Mon, 22 Nov 2021 22:16:32 +0000 Received: by outflank-mailman (output) from mailman id 229093.396486; Mon, 22 Nov 2021 22:16:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpHc0-000562-9w; Mon, 22 Nov 2021 22:16:32 +0000 Received: by outflank-mailman (input) for mailman id 229093; Mon, 22 Nov 2021 22:16:31 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpHbz-00055w-Rc for xen-devel@lists.xenproject.org; Mon, 22 Nov 2021 22:16:31 +0000 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id d7018849-4be1-11ec-9787-a32c541c8605; Mon, 22 Nov 2021 23:16:30 +0100 (CET) Received: by mail.kernel.org (Postfix) with ESMTPSA id 222B260FE6; Mon, 22 Nov 2021 22:16:28 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d7018849-4be1-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637619388; bh=kRlam7odlirF8W9djazKfCVOxAEG58oHirjbOnjelJI=; h=From:To:Cc:Subject:Date:From; b=oWsu7ISreFyJ3GjFm0Fsgen+xWF1YgeB24eOx63Y8aqGqj187MQBCbgP6l5BuzgBN S5t2SsFvP8EBEm6Az9QyVWAwgOwrtFAMS5AEFNyE/MdDz68XaMfLY4r1UPkPNBWn0w 5kJDqgUoJ34/fMJnL6mui6AhttQnqMUeNd0j2C2hU7YPFYXRGaBgdE8SF1QkMymafi U+tvXo1vIkEeU6wCKTK5ew7p3bEesfJTfzvHS6cBlynLJlhQ2eCE9jfdRM0mC4nBvy TZL3SjoPbv86mtVd74JzTFa6TVqhvXLGK5DPZezsynAPvkidaf1YKP1Q5wS2vEScjv R24zmreoizBww== From: Stefano Stabellini To: jgross@suse.com Cc: boris.ostrovsky@oracle.com, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, sstabellini@kernel.org, jbeulich@suse.com, Stefano Stabellini , stable@vger.kernel.org Subject: [PATCH v3] xen: detect uninitialized xenbus in xenbus_init Date: Mon, 22 Nov 2021 14:16:25 -0800 Message-Id: <20211122221625.1473164-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1637619420231100001 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini If the xenstore page hasn't been allocated properly, reading the value of the related hvm_param (HVM_PARAM_STORE_PFN) won't actually return error. Instead, it will succeed and return zero. Instead of attempting to xen_remap a bad guest physical address, detect this condition and return early. Note that although a guest physical address of zero for HVM_PARAM_STORE_PFN is theoretically possible, it is not a good choice and zero has never been validly used in that capacity. Also recognize the invalid value of INVALID_PFN which is ULLONG_MAX. For 32-bit Linux, any pfn above ULONG_MAX would get truncated. Pfns above ULONG_MAX should never be passed by the Xen tools to HVM guests anyway, so check for this condition and return early. Cc: stable@vger.kernel.org Signed-off-by: Stefano Stabellini --- Changes in v3: - improve in-code comment - improve check Changes in v2: - add check for ULLONG_MAX (unitialized) - add check for ULONG_MAX #if BITS_PER_LONG =3D=3D 32 (actual error) - add pr_err error message --- drivers/xen/xenbus/xenbus_probe.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 94405bb3829e..d3ca57d48a73 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -951,6 +951,30 @@ static int __init xenbus_init(void) err =3D hvm_get_parameter(HVM_PARAM_STORE_PFN, &v); if (err) goto out_error; + /* + * Uninitialized hvm_params are zero and return no error. + * Although it is theoretically possible to have + * HVM_PARAM_STORE_PFN set to zero on purpose, in reality it is + * not zero when valid. If zero, it means that Xenstore hasn't + * been properly initialized. Instead of attempting to map a + * wrong guest physical address return error. + * + * Also recognize the invalid value of INVALID_PFN which is + * ULLONG_MAX. + */ + if (!v || !(v + 1)) { + err =3D -ENOENT; + goto out_error; + } + /* Avoid truncation on 32-bit. */ +#if BITS_PER_LONG =3D=3D 32 + if (v > ULONG_MAX) { + pr_err("%s: cannot handle HVM_PARAM_STORE_PFN=3D%llx > ULONG_MAX\n", + __func__, v); + err =3D -EINVAL; + goto out_error; + } +#endif xen_store_gfn =3D (unsigned long)v; xen_store_interface =3D xen_remap(xen_store_gfn << XEN_PAGE_SHIFT, --=20 2.25.1