From patchwork Wed Nov 4 15:40:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Parri X-Patchwork-Id: 11881125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 98EA2921 for ; Wed, 4 Nov 2020 15:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F283206E3 for ; Wed, 4 Nov 2020 15:41:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qK10rbEI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730785AbgKDPlS (ORCPT ); Wed, 4 Nov 2020 10:41:18 -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-Google-Smtp-Source: ABdhPJwJzhCsWSa7ZU6dqa7DoMh+Yv5uZf3ZlqbDfKrq3T+iMhlVKbwh6Yxa2tzAnJfHX5/dEMd/Gg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@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;