Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3317193pxk; Mon, 7 Sep 2020 09:21:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwz40GhMoYQmdErs/FBCE8jnSk6g9k99+waU6p7ZEtsGV81JhwgeDXNjWKxpkJgxei7NW3B X-Received: by 2002:a17:907:70cb:: with SMTP id yk11mr21419140ejb.312.1599495686466; Mon, 07 Sep 2020 09:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599495686; cv=none; d=google.com; s=arc-20160816; b=M48HNb3I6z+86w3JjPBy3I4vCjgoKDf49SwomFTlZnXh0Jb/lIqs3+3h0HNaS69fPd e/UTHtQShu/I1sbUfWI69JxFFljhEtniatQ/0OemfC19b2fjAGdZ/SBcM8ZNHTMRD6Pv 4q3xZYw2sbY8dqfmQrDZ3wrylF3fGJdwFN0H/QNCOxunE5TwwevJFDNrxW9W5oe6vHTc hb+5rTIagTOLHJ+CZySWrDwJso/a2kv+fz4BzCmSktCJ0AMdivF37F7mka+AM/KIes+i /lZTrL3BoLIo8FRl/JS3AUvC0COnUI6q4nrAxMDVyOyF2cFKedSjke3d7dbs/i0sLaTH TYkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T7f55k2r5OlXk34A84CpxQUybUpvWvz4gMNJy8/sgno=; b=r7x2h0IpAHVPb5ivUK+xh6q4PowdvrU4P3wn06StdWZ5d1laZdHILf0rvsa+RWN0Vs E8FJ2X1OaUHcNnYY2p6dnYQ2qJ842bRE/6LopF+7C31r3Ws5woRCXRVYZJSXGpHUdrV6 mSTM0QIXB6qX4UAIs28D99jiXn6/1sFM7rxEOZEYZ1hW1Yb+UVaaZG2YE6O0h6SU5UIF 1bTr7fZxSzSTQe2NazqBHwiWDyLKtGOZpua6oP4LQCz1g/4EAiyodniVXTXJ2YvbIfAf v6iHIaA1hZbwZH48QHxspk9jji/sBPZHLEi0a2B7qZ3Z6ICPSBW5epK/gvuFbE4yTCVm x2Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="j/G2Jgb5"; 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 h19si9369828edv.301.2020.09.07.09.21.03; Mon, 07 Sep 2020 09:21:26 -0700 (PDT) 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="j/G2Jgb5"; 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 S1730413AbgIGQUb (ORCPT + 99 others); Mon, 7 Sep 2020 12:20:31 -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-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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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) 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; -- 2.25.1