From nobody Thu Apr 25 00:09:06 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=1637701719; cv=none; d=zohomail.com; s=zohoarc; b=T21woQ57L7BIRDS7z1WjxavXVRb57tSJrBEUjB/SY/2lORbfwM4TGJD+dio2l6n1iEQpxlEDmwYZipM4I0p7VCu7JKZVA236l2CinnxWtnJgSjmJIW4jZ+Ct8SEXdJG8ijP5Gjf9zRT1UiaOD2h61KSc2B5rytcwFZf4fE3etHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637701719; 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=e8hblXUOXOp8xQjRBkFxEQZtQ3xynh2OFvZreNoFss4=; b=ZoLFnU7m8QSGnMfuPXrbcwcfyAFiOEV5IOusLlK+CcXO24RSXWnnc/vVPNQUTUZGVadifwzqmfFdJfBsyNQ4OOBbQJrjMI6M9K2Pm6Ue3vNNM73EnxTK5G020zQkeyf9vcZP0coDoshbh+WrM82QBfX51W/iz6V1bf7uLGUWKOM= 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 1637701719617259.87850992527683; Tue, 23 Nov 2021 13:08:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.229944.397544 (Exim 4.92) (envelope-from ) id 1mpd1C-0005Ez-2h; Tue, 23 Nov 2021 21:07:58 +0000 Received: by outflank-mailman (output) from mailman id 229944.397544; Tue, 23 Nov 2021 21:07:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mpd1B-0005Es-Ud; Tue, 23 Nov 2021 21:07:57 +0000 Received: by outflank-mailman (input) for mailman id 229944; Tue, 23 Nov 2021 21:07:56 +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 1mpd1A-0005EW-89 for xen-devel@lists.xenproject.org; Tue, 23 Nov 2021 21:07:56 +0000 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6baa330c-4ca1-11ec-9787-a32c541c8605; Tue, 23 Nov 2021 22:07:54 +0100 (CET) Received: by mail.kernel.org (Postfix) with ESMTPSA id 6925D6023D; Tue, 23 Nov 2021 21:07:51 +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: 6baa330c-4ca1-11ec-9787-a32c541c8605 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637701671; bh=fmNL3u7OnTxHOXgiEAfETI2VUP4gGL2FJ5fr15s9qbA=; h=From:To:Cc:Subject:Date:From; b=Rxsf9g172XeXrnTMElnISWoUxpvJaJP4/7s1u7MpinNCISK6oeUbHJW/lpgH8JGsB puD4+oFyzmduElLopaiyTeolLisu1Xf48UOOd4Un7crdq7xpFMv57i1F0JviSNa/cZ jcXfA0lzTIp+uyHcrihkikmb99s425RVXRl7DVQhONTi4A8d606fnVMK1Xr1srsjUQ 24+5RmfZXbOsHUaWs7Wi/yKoWYF0eePtcIGng1H8cU3Hgm+STQZLefqQwQUOisJ3Ro PVh6ejIW8QkefCdwF19gP37QgiNPsfHFGc7TIbjDvT5LESWy4QMWr6vgzF/whZ+9pK xlFCgZB5syF1Q== 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 v4] xen: detect uninitialized xenbus in xenbus_init Date: Tue, 23 Nov 2021 13:07:48 -0800 Message-Id: <20211123210748.1910236-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: 1637701721037100001 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 all bits set as an invalid value. 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 Reviewed-by: Jan Beulich Reviewed-by: Juergen Gross --- Changes in v4: - say "all bits set" instead of INVALID_PFN - improve check 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 | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 94405bb3829e..251b26439733 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -951,6 +951,29 @@ 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 all bits set as an invalid value. + */ + if (!v || !~v) { + 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