From patchwork Mon Sep 7 16:19:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Parri X-Patchwork-Id: 296835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1D24C2BB84 for ; Mon, 7 Sep 2020 16:21:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCC9F207DE for ; Mon, 7 Sep 2020 16:21:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j/G2Jgb5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730509AbgIGQUD (ORCPT ); Mon, 7 Sep 2020 12:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730451AbgIGQTz (ORCPT ); Mon, 7 Sep 2020 12:19:55 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04653C061574; Mon, 7 Sep 2020 09:19:55 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id e17so14860062wme.0; Mon, 07 Sep 2020 09:19:54 -0700 (PDT) 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=T7f55k2r5OlXk34A84CpxQUybUpvWvz4gMNJy8/sgno=; b=j/G2Jgb5rqzKNExV7n7ohz9X0rhecUAfO122e2W6GiCJGkS7SRSbBs1l17qp9P20P0 cq5Whd1wnqmJWs6inM/xoE4YGdwTU/u/1ujllsBbNFCpxhwMjkBvlQEEmJzqCncZkO/v v8AqGieKdPLCM1U+H90iYzuyI4DMO50pcVu5RYluLsco2JGHRF90iF+LyU0i/QeHUUXp 6HD+LccqFGZawMX56ZfpGDVQxuQJp4cDGwbvlUmJy0TrgEhsTHboGtOS/p84MkB823g0 hdzCKYtQ1PoB61rLjnpwE0mond/cMdCvQRgJB0zB3gXemewRVdi/2AsTFMsuF83uWI85 xujg== 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=T7f55k2r5OlXk34A84CpxQUybUpvWvz4gMNJy8/sgno=; b=AqBBhE3lk+eRdpBjmFuGjf0VojGEX04ldVNQV6ZAzbvcJEdqGJr/WnnViSHUtS/4eA 7BJwC0CyHrr3jPuRf8hk6MCksOwKMfe4as8FOHT6KZEFQVeiEGdTHhqdzr4ShT14zno8 GGsztSBwRCgwHAuroZK3iDr2cheURSZQ90grSOwCNE4eRFDdbFc0kbv0tCz0+DSF+/Er aEf+rEweH+sgaT5izI/pUh3J0Xi3hFVK4oTWuDanqY9atUAd4SShXAW/uxDPlcrCHKTW CCG/qZBoOIT+5xQ9MCnC2IrBb6eU9HEEJb96hDvMGj7HKYtWHJhPlToPeyPzljyJjKg8 DpTQ== X-Gm-Message-State: AOAM532umrF2lvohQVmERRehqExttZ/defPmVmr2A9AO4j6UN7TMzFR6 Nf4nTruevNbDD2Sy5Mm5T61YExKk7kjnpPBKc1Y= X-Google-Smtp-Source: ABdhPJwUkE7qxaHw6/zuh4vX8vncU+49AVAJIbQstYfDfYYPfEucG95/E7Wi4K/ugKLUZ5K7SeBq2A== X-Received: by 2002:a1c:2d85:: with SMTP id t127mr133500wmt.22.1599495593247; Mon, 07 Sep 2020 09:19:53 -0700 (PDT) Received: from localhost.localdomain (userh713.uk.uudial.com. [194.69.103.86]) by smtp.gmail.com with ESMTPSA id y5sm19313717wrh.6.2020.09.07.09.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2020 09:19:52 -0700 (PDT) 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 v7 2/3] scsi: storvsc: Use vmbus_requestor to generate transaction IDs for VMBus hardening Date: Mon, 7 Sep 2020 18:19:19 +0200 Message-Id: <20200907161920.71460-3-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200907161920.71460-1-parri.andrea@gmail.com> References: <20200907161920.71460-1-parri.andrea@gmail.com> MIME-Version: 1.0 Sender: linux-scsi-owner@vger.kernel.org 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) 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 8f5f5dc863a4a..0b9090d031fc0 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;