Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3089311pxb; Mon, 9 Nov 2020 02:08:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgHamjMS7w0KuHjKLW3Jx7CCbElqunWP/f7Bz8CQk7NT7OiaFOwJ5JmyyZ+QezaZvFyqbf X-Received: by 2002:a17:906:2886:: with SMTP id o6mr14970005ejd.259.1604916537331; Mon, 09 Nov 2020 02:08:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604916537; cv=none; d=google.com; s=arc-20160816; b=hDI5N1Dc28XxFXCjENm1tL1M9OqcqI0IrlSBU516sDkrKxx5IFOAC9jJePEqJ17zY9 pONKKdOV4+udUC9zCeXDLiZSmT41w6j9Zk0KNn/xzgjIYgrz5YUVLgh8LzH2ExQGRuzh diypqMXY+SZOT6nbR077ehC6LfPKV9N8fELJv72pAyNebyjVYfqGUC1lONepN2YY0OsG gAgzWkFFOUyRGSH1BwKcSgxudgoj64y5PmubJ1jczKf+GsmuJ8MuZf+AoCnksLSgP/4N pVwR8FCBQShmLp6Q93FqIZhaULR3MXki8iK/C+Re5UyHmAXRcDetodImjBaG2jcyyzW2 lQyQ== 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=7HmXGBYoS09GoozyfmH+xb/d9FOWeeDG+N6hfNplN0c=; b=u7M/YMsuR/iZI+lljXKAM5ghdl5eEeDlkElP+C1p+tCzKp2m5NreetlpLapS0Hd9+d 3vSuQjFAVb3JlkEq02S6z8NQxYUgqMtSeTv0KyHzpZl0DxCvnihxCXDzzu/Vid8fAsjB pDtA7Egv3FA7/douZiGgk0MVZs3jAF/OPTi7Vh2fPZJJRZmQOsdwBtcskv1Qe3mkjZeR Hg0NTSvv8GaY2wSa5RVRUykgcl1Jsd7FxZaDcoURdbVbW+BJhmW8PiPqO4XjhTrfqbgw gSOwDHNYMfRaIdlfV8iyDMjs18+WWR/kI6OSIOW+ZvWf+DvCV0ycDYGGvdjBNU+R8OuP OHgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uCNZMTv+; 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 b13si6318254eje.225.2020.11.09.02.08.34; Mon, 09 Nov 2020 02:08:57 -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=uCNZMTv+; 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 S1729336AbgKIKEa (ORCPT + 99 others); Mon, 9 Nov 2020 05:04:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729045AbgKIKE1 (ORCPT ); Mon, 9 Nov 2020 05:04:27 -0500 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87E2FC0613CF; Mon, 9 Nov 2020 02:04:27 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id j7so754681wrp.3; Mon, 09 Nov 2020 02:04:27 -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=7HmXGBYoS09GoozyfmH+xb/d9FOWeeDG+N6hfNplN0c=; b=uCNZMTv+kYnhlowwmB38hvaYw+++JWYD3Wl5sHYoRlTCCw48COYjxtRUbvRBlFIrIQ VWn+J3Ee9qJkfOG7FylVqY+JaKSuotIKTfQombXmAy1lUbAVd2l2XUzDOOkpQ2+vY7qT tZ7oPqBzPBPMlewKAahlvnYm0qncsAdqfPvL0/fJ+cbyIXpgolEChSAqFyKdCFNpPFUX p6ISnvhiILrRAB2IjPE/EAZ4kOzD7KFpVpRkPV2zxrQW/cqvvU8RgLnEIUpSEUqgjkFg nNfxTFwX5YN3SoT/nFsan+y6b+ekHkhqgbgjw62ZS7AzvtRAJtukgTH9AuBWKms+eAgG FHpg== 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=7HmXGBYoS09GoozyfmH+xb/d9FOWeeDG+N6hfNplN0c=; b=nj78+k70V36YSsNHJT6rGnPJUMkHtktsnJvRCzzHYKqmmwXMW67A2VUSQqM2+y5coo +3o+I/FCVNLhtnFdS8XbvDl8zpSZzwD1JlogRSE+MDgIoNzqko9N1sA274uloVkLYWGP BuiCDobmdfob05gQA+TT9fErnEaGlaz8txfLAlQHxUTlZN9a09czHexCM8kV9ZTCkLIq 0dUUA6G5ADoyAESI+XA+c/LlwwHgUAI7Af2f661dd4kU0stL3T1SUQU2kJ1/yef6THUk JtYLc2wNHoZrhzlwendNnGaWrsf1Aww/wa2gVT7Z77qylquyX1TogfskQvyml8yMmDWE LPXg== X-Gm-Message-State: AOAM531iFrh3XNjfY3CwS7EZy5qCtlip+H9RFBn++ZBjipcfZYVpbxRW /mRDpL9ZxiGps7LfZyhRGsQEwhVfox4ttLVW X-Received: by 2002:a5d:4448:: with SMTP id x8mr16759960wrr.364.1604916265931; Mon, 09 Nov 2020 02:04:25 -0800 (PST) Received: from localhost.localdomain (host-95-245-157-54.retail.telecomitalia.it. [95.245.157.54]) by smtp.gmail.com with ESMTPSA id 71sm13117885wrm.20.2020.11.09.02.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 02:04:25 -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 v9 2/3] scsi: storvsc: Use vmbus_requestor to generate transaction IDs for VMBus hardening Date: Mon, 9 Nov 2020 11:04:01 +0100 Message-Id: <20201109100402.8946-3-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201109100402.8946-1-parri.andrea@gmail.com> References: <20201109100402.8946-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 --- Changes in v7: - Move the allocation of the request ID after the data has been copied into the ring buffer (cf. 1/3) Changes in v2: - Add casts to unsigned long to fix warnings on 32bit 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