From nobody Fri May 3 03:29:10 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 ARC-Seal: i=1; a=rsa-sha256; t=1611743464; cv=none; d=zohomail.com; s=zohoarc; b=oE0NF/vvqZgO66RZCIWtCeKFpwmHbKtVwEpNlC2TlMiTmM+Kk/hOt6UBpFt0Qq+CFkqjSyBMd6hThTeL0QNqoXz8EqLEDw3Cr4W/FSaGfcclGeD7d0xvC/wyrMG77jCntJbdqkx/kHaWp98Y6A59HF3e+ZMwCPj+gOluM7PAPBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611743464; 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=6/ptHMbuxYa6BXHfF9UQPcY2KxtZZywQRKCjkU8Fz9o=; b=M+2ikT4+1/cWk/aeYMhoUJveciDDVuB0OSykXtJJ6GNcnpZ2c15ZQDTynQFCmy/4+Rgc5fpHFJ0ggJ1WWWn7H+UZYoL0RwG6ugHtnJlSoBqQUl55i/daaDlPg5dQEGu/TTlSupzKnraZoH9UiCKFAtdd+5AC9NyzeOHpf8N9rWk= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611743464566360.3970714318899; Wed, 27 Jan 2021 02:31:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.75937.136930 (Exim 4.92) (envelope-from ) id 1l4i61-0004jO-AZ; Wed, 27 Jan 2021 10:30:45 +0000 Received: by outflank-mailman (output) from mailman id 75937.136930; Wed, 27 Jan 2021 10:30:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4i61-0004jH-5g; Wed, 27 Jan 2021 10:30:45 +0000 Received: by outflank-mailman (input) for mailman id 75937; Wed, 27 Jan 2021 10:30:44 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4i60-0004jC-3a for xen-devel@lists.xenproject.org; Wed, 27 Jan 2021 10:30:44 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4i5z-0003o8-AR; Wed, 27 Jan 2021 10:30:43 +0000 Received: from host86-190-149-163.range86-190.btcentralplus.com ([86.190.149.163] helo=ubuntu.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4i5y-0005F8-W1; Wed, 27 Jan 2021 10:30:43 +0000 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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Message-Id:Date:Subject:Cc:To:From; bh=6/ptHMbuxYa6BXHfF9UQPcY2KxtZZywQRKCjkU8Fz9o=; b=J0YcgcpU/TQzwemcTYqNewhQSD ziPvpCBJgSy68kc79RsBYacQqZsE3MR3iPY0Ov8RJ5b9Yx9fTBKICJSuuLK67icSdmfi4XreSC3oj KQVdPhvzPH3uDVqjCtHr9ONoKhqagQtSNAdeFmSpIsBiU5wM3ci6Vf7oxl/LkiftEmYk=; From: Paul Durrant To: xen-devel@lists.xenproject.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Konrad Rzeszutek Wilk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Jens Axboe , Dongli Zhang Subject: [PATCH] xen-blkback: fix compatibility bug with single page rings Date: Wed, 27 Jan 2021 10:30:34 +0000 Message-Id: <20210127103034.2559-1-paul@xen.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant Prior to commit 4a8c31a1c6f5 ("xen/blkback: rework connect_ring() to avoid inconsistent xenstore 'ring-page-order' set by malicious blkfront"), the behaviour of xen-blkback when connecting to a frontend was: - read 'ring-page-order' - if not present then expect a single page ring specified by 'ring-ref' - else expect a ring specified by 'ring-refX' where X is between 0 and 1 << ring-page-order This was correct behaviour, but was broken by the afforementioned commit to become: - read 'ring-page-order' - if not present then expect a single page ring - expect a ring specified by 'ring-refX' where X is between 0 and 1 << ring-page-order - if that didn't work then see if there's a single page ring specified by 'ring-ref' This incorrect behaviour works most of the time but fails when a frontend that sets 'ring-page-order' is unloaded and replaced by one that does not because, instead of reading 'ring-ref', xen-blkback will read the stale 'ring-ref0' left around by the previous frontend will try to map the wrong grant reference. This patch restores the original behaviour. Fixes: 4a8c31a1c6f5 ("xen/blkback: rework connect_ring() to avoid inconsist= ent xenstore 'ring-page-order' set by malicious blkfront") Signed-off-by: Paul Durrant --- Cc: Konrad Rzeszutek Wilk Cc: "Roger Pau Monn=C3=A9" Cc: Jens Axboe Cc: Dongli Zhang --- drivers/block/xen-blkback/common.h | 1 + drivers/block/xen-blkback/xenbus.c | 36 +++++++++++++----------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback= /common.h index b0c71d3a81a0..524a79f10de6 100644 --- a/drivers/block/xen-blkback/common.h +++ b/drivers/block/xen-blkback/common.h @@ -313,6 +313,7 @@ struct xen_blkif { =20 struct work_struct free_work; unsigned int nr_ring_pages; + bool multi_ref; /* All rings for this device. */ struct xen_blkif_ring *rings; unsigned int nr_rings; diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback= /xenbus.c index 9860d4842f36..4c1541cde68c 100644 --- a/drivers/block/xen-blkback/xenbus.c +++ b/drivers/block/xen-blkback/xenbus.c @@ -998,10 +998,15 @@ static int read_per_ring_refs(struct xen_blkif_ring *= ring, const char *dir) for (i =3D 0; i < nr_grefs; i++) { char ring_ref_name[RINGREF_NAME_LEN]; =20 - snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref%u", i); + if (blkif->multi_ref) + snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref%u", i); + else { + WARN_ON(i !=3D 0); + snprintf(ring_ref_name, RINGREF_NAME_LEN, "ring-ref"); + } + err =3D xenbus_scanf(XBT_NIL, dir, ring_ref_name, "%u", &ring_ref[i]); - if (err !=3D 1) { if (nr_grefs =3D=3D 1) break; @@ -1013,18 +1018,6 @@ static int read_per_ring_refs(struct xen_blkif_ring = *ring, const char *dir) } } =20 - if (err !=3D 1) { - WARN_ON(nr_grefs !=3D 1); - - err =3D xenbus_scanf(XBT_NIL, dir, "ring-ref", "%u", - &ring_ref[0]); - if (err !=3D 1) { - err =3D -EINVAL; - xenbus_dev_fatal(dev, err, "reading %s/ring-ref", dir); - return err; - } - } - err =3D -ENOMEM; for (i =3D 0; i < nr_grefs * XEN_BLKIF_REQS_PER_PAGE; i++) { req =3D kzalloc(sizeof(*req), GFP_KERNEL); @@ -1129,10 +1122,15 @@ static int connect_ring(struct backend_info *be) blkif->nr_rings, blkif->blk_protocol, protocol, blkif->vbd.feature_gnt_persistent ? "persistent grants" : ""); =20 - ring_page_order =3D xenbus_read_unsigned(dev->otherend, - "ring-page-order", 0); - - if (ring_page_order > xen_blkif_max_ring_order) { + err =3D xenbus_scanf(XBT_NIL, dev->otherend, "ring-page-order", "%u", + &ring_page_order); + if (err !=3D 1) { + blkif->nr_ring_pages =3D 1; + blkif->multi_ref =3D false; + } else if (ring_page_order <=3D xen_blkif_max_ring_order) { + blkif->nr_ring_pages =3D 1 << ring_page_order; + blkif->multi_ref =3D true; + } else { err =3D -EINVAL; xenbus_dev_fatal(dev, err, "requested ring page order %d exceed max:%d", @@ -1141,8 +1139,6 @@ static int connect_ring(struct backend_info *be) return err; } =20 - blkif->nr_ring_pages =3D 1 << ring_page_order; - if (blkif->nr_rings =3D=3D 1) return read_per_ring_refs(&blkif->rings[0], dev->otherend); else { --=20 2.17.1