Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1391183pxb; Wed, 4 Nov 2020 07:45:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEfYN5yANqQV4BvnW+/Me8zgOz9WQ9cbXtAYEHvH9psiWjtCzwGC2dvt3EUNrjOZD9587U X-Received: by 2002:a17:906:8398:: with SMTP id p24mr26292518ejx.401.1604504744497; Wed, 04 Nov 2020 07:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604504744; cv=none; d=google.com; s=arc-20160816; b=V0MyWz9vnzktCkrrVlIlDX8qIfTZcyEBOmTIzIjzEmHIkkJWddkCzcwh5+gsRHJDlR 3wVLX+GC1EHHIjbZ7T5aUfIA1UYyfzWTtEEf8Tup9yRSpA4wBUv7fyaIaDur14hBA+MN btouLYc7JfybJTALW1SuZbhvE/LJNY25Sdo58OO51aV8vDZ8FmXd4FGsL/krRiKe1vdQ bQ/cYFWq/F5MbgthpIgoX7F+DaDq/IDlilw5DRYtzvQ0NZxEuv6GsulosiGhkZSw3dWG UywsEnYy1ggaqzCLuKKOqS1dRJ0vV6mBDL/0TYTrR5AcOAq5yYidGCiSoNndgUNhJPXk N3ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3X/UecvaO5trLPWai94Jlqtfo3VwUeozbxipUJKHrpM=; b=J6K8B7iMpopuLljzHqwB//qRoG2MwQSCvPpkETTm59XBUNc3+feEJa2YIGch2+mocM ZYQfI64bQSHunjpRqnfSPf5CVeiPXq1LQ78MNZFUmSv4Gll1e8SDEQ4dsuQMBRCPM2mF Q9beZeO81N2TiKYppw0+Swhzwgz62K+u5u/7ywVQMaKeG2OsAyqFlZnaaUYU5G5QzTUk SGdufX2SVDSX6WGsPQPqRnsVTKS/UyYzuTM9iBH3pWbrJW/tfCRFxt0lmrgOkx+mvhHe pOENCG0GY/9fl4Ry37AuL9EeoaDI+0DweA3hjRE0HC7JqWacGKVRSlW5b4vGBu0g34Av jTtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qK10rbEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g1si1425399edt.484.2020.11.04.07.45.20; Wed, 04 Nov 2020 07:45:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qK10rbEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730787AbgKDPlT (ORCPT + 99 others); Wed, 4 Nov 2020 10:41:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbgKDPlR (ORCPT ); Wed, 4 Nov 2020 10:41:17 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D23E1C0613D4; Wed, 4 Nov 2020 07:41:15 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id i19so19375273ejx.9; Wed, 04 Nov 2020 07:41:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3X/UecvaO5trLPWai94Jlqtfo3VwUeozbxipUJKHrpM=; b=qK10rbEIF/Df0GW9VpKc99eFHhW3DgR6NK46ONiOHYuDfNzNIovXftF/Vi3ilGpbMx +1HKbfTi41UbXHdzXkKaIQnOplmW+DCuIbiX3ZwGis7taiEbToLxxwy2OPJiIBP897Rj p3CBvbilgO3+nX3hMuWm0hVwNE2GSH5BamyT9sPYdPT9ca+Y1Q+P53afOZWmQfvLsfLS rxGBjTk6nkgLQZZsY8eCqgUDAIgniFn+VsN7SKbN+n+1cXui3n0dfQ0HhCxSfkgs7UHm WytGwLgI8D0aX3OEv8316SQ48lcpZx0BW/a9H/zD22mNC2Pj1Tef7pze43ucwZWkWvvu zOpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3X/UecvaO5trLPWai94Jlqtfo3VwUeozbxipUJKHrpM=; b=Nd8AndeXWUrmcq9OGEPDRkvvGYmg5Yse9PMZuqiGNmONd3ts9XJbpBFcsNdycfPOyh PvWqFUvjz8gXy25vjirWgJrD1ecYTlsk9aZ8lBh509gEuj99BpA1NGym57Ufmvw6HmYD qwBCgNpf6EOx/OmJTmndfm5zksk+jaY0hHh3eTZnlUEfEtlhSiuqlFm0R/lUDKg3spbe 91zNaajb5U7OeKPHHOuk0MMmfpqV3KJJA3dRyKYP7MjQP9UClCqHGFMo/qECnoc4D9bd KbcwfQcZv6W7BHKGe3zsyB74e5RXV8/v5Ro++a2RHPP5vremMYB6vkqV1dxdG1OHPIP5 S27A== X-Gm-Message-State: AOAM531RgzslOtjG9miGWh+HMvJ9lvX/SyhX/dkutrHfRXzUTzHGLUh/ IxNViujlvb/CnefQVarP0aehnKkQR30AFUvZ X-Received: by 2002:a17:906:17d1:: with SMTP id u17mr23058098eje.6.1604504474275; Wed, 04 Nov 2020 07:41:14 -0800 (PST) Received: from localhost.localdomain (host-87-7-71-164.retail.telecomitalia.it. [87.7.71.164]) by smtp.gmail.com with ESMTPSA id y14sm1218548edo.69.2020.11.04.07.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 07:41:13 -0800 (PST) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , linux-hyperv@vger.kernel.org, Andres Beltran , Michael Kelley , Saruhan Karademir , Juan Vazquez , Andrea Parri , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org Subject: [PATCH v8 2/3] scsi: storvsc: Use vmbus_requestor to generate transaction IDs for VMBus hardening Date: Wed, 4 Nov 2020 16:40:26 +0100 Message-Id: <20201104154027.319432-3-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201104154027.319432-1-parri.andrea@gmail.com> References: <20201104154027.319432-1-parri.andrea@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andres Beltran Currently, pointers to guest memory are passed to Hyper-V as transaction IDs in storvsc. In the face of errors or malicious behavior in Hyper-V, storvsc should not expose or trust the transaction IDs returned by Hyper-V to be valid guest memory addresses. Instead, use small integers generated by vmbus_requestor as requests (transaction) IDs. Signed-off-by: Andres Beltran Co-developed-by: Andrea Parri (Microsoft) Signed-off-by: Andrea Parri (Microsoft) Reviewed-by: Michael Kelley Cc: "James E.J. Bottomley" Cc: "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org --- drivers/scsi/storvsc_drv.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 0c65fbd41035e..369a6c6266729 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -399,6 +399,7 @@ static int storvsc_timeout = 180; static struct scsi_transport_template *fc_transport_template; #endif +static struct scsi_host_template scsi_driver; static void storvsc_on_channel_callback(void *context); #define STORVSC_MAX_LUNS_PER_TARGET 255 @@ -698,6 +699,12 @@ static void handle_sc_creation(struct vmbus_channel *new_sc) memset(&props, 0, sizeof(struct vmstorage_channel_properties)); + /* + * The size of vmbus_requestor is an upper bound on the number of requests + * that can be in-progress at any one time across all channels. + */ + new_sc->rqstor_size = scsi_driver.can_queue; + ret = vmbus_open(new_sc, storvsc_ringbuffer_size, storvsc_ringbuffer_size, @@ -1242,9 +1249,17 @@ static void storvsc_on_channel_callback(void *context) foreach_vmbus_pkt(desc, channel) { void *packet = hv_pkt_data(desc); struct storvsc_cmd_request *request; + u64 cmd_rqst; + + cmd_rqst = vmbus_request_addr(&channel->requestor, + desc->trans_id); + if (cmd_rqst == VMBUS_RQST_ERROR) { + dev_err(&device->device, + "Incorrect transaction id\n"); + continue; + } - request = (struct storvsc_cmd_request *) - ((unsigned long)desc->trans_id); + request = (struct storvsc_cmd_request *)(unsigned long)cmd_rqst; if (request == &stor_device->init_request || request == &stor_device->reset_request) { @@ -1265,6 +1280,12 @@ static int storvsc_connect_to_vsp(struct hv_device *device, u32 ring_size, memset(&props, 0, sizeof(struct vmstorage_channel_properties)); + /* + * The size of vmbus_requestor is an upper bound on the number of requests + * that can be in-progress at any one time across all channels. + */ + device->channel->rqstor_size = scsi_driver.can_queue; + ret = vmbus_open(device->channel, ring_size, ring_size, @@ -1572,7 +1593,6 @@ static int storvsc_host_reset_handler(struct scsi_cmnd *scmnd) struct vstor_packet *vstor_packet; int ret, t; - stor_device = get_out_stor_device(device); if (!stor_device) return FAILED; -- 2.25.1