Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp349270pxb; Wed, 6 Oct 2021 06:22:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeVNlc3PQJ33ZCIn+1gez5Fmw9Cpef/wl/MiVG7aHX0umkSOCZ2RTKYRULQnoLr1Ea1ZNM X-Received: by 2002:a17:902:e544:b0:13e:e863:6cd2 with SMTP id n4-20020a170902e54400b0013ee8636cd2mr7857161plf.41.1633526534593; Wed, 06 Oct 2021 06:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633526534; cv=none; d=google.com; s=arc-20160816; b=LuCE1DYiCi4vjnRZ/9ZwvsXkXEGWdzU9DQLY+2iJtXrp2d1lJvlIPbwhCqTqOfGwu2 f9lt9YKZ1lUN1CAZiv9R/dn8NiYCE35nnoKLvruZlmE99nRpR9fttI9m+cdI0WO1e4BI TW2hlF646kVx46BW8wuE7IycYOvh5RkGbIe0FtHnmyoj2LLGYuO3Gw2F/VhCSwGT0gC4 CiaLdOsV4Ghnn1i26c1xP8ptStBpzo1DFt2FUoWGmpD3wJb1Dj21/V0ZcidY28JXxqjB /NDt3v5SteRuM9RdiuYM8fLVbDYx6nwLLJi2INpE290/5ie3lDHRHkrh/OtVGSFXKhb/ 4u0A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=vOkTBrJ8rFY8f9IVX0lA4SgMpHXgic0fky3oKRvqHqk=; b=Rx9yYMgA+kQc8qIND2JCY6H3PHFLvI0/x3EUka6gpgDw754wW6YWUNc9GjgFf4+RWk g6hV22gmGGcfgVdzE7iyOgAaqerVBXA6yEwx1ayANPy+1RvRWDm4CsGmQAl7W1St9BIm jLgWIhqKFPe+dgTU4LRPInS4HCJEUnmV9isv+1VR3c1fbAKCiJxNzyRnc/QkBlEEpOEc Hqv3PdJNf/Jj8Gf9rDkum4y8vNyZ+txgBcRM8VIAgDQQGvmlNcNWokrID2Sk3Mez7qCN zP/6bDJOebRIbo40bO31zC4jRzo0nZZgVLjKRvIqBjDeZ4as+n8D1qAT0PMgabQx4uvD s9ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=mUVLyEYq; 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 a24si25138740pls.254.2021.10.06.06.21.59; Wed, 06 Oct 2021 06:22:14 -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=20210112 header.b=mUVLyEYq; 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 S238447AbhJFNWo (ORCPT + 99 others); Wed, 6 Oct 2021 09:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231384AbhJFNWn (ORCPT ); Wed, 6 Oct 2021 09:22:43 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27624C061749; Wed, 6 Oct 2021 06:20:51 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id x7so9642859edd.6; Wed, 06 Oct 2021 06:20:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vOkTBrJ8rFY8f9IVX0lA4SgMpHXgic0fky3oKRvqHqk=; b=mUVLyEYqh9+b5aOkFH+/WeECuuGtmvZkHphEI2tlT6gRdiywDz1xqhzW5W7E9xEWmv 5NReq7Fj7EFtSeVWE0nul7Rw8VG9wHSHqthUclc6QxgWH7/c4nqnKwC6EYBfwevJm3x6 AKqs22eCqVb6XPalNajSXItmeTULrJhkyVuwPbTqvtXPNoIhYHQWpd1CFYz9UdVCCk2Q ytp2YvK0205TSd7/vQCR+pNZDHa1JjGHE+kR6zg6HHXvoV/xCye0xPVMI+b8r8O5L6A2 IPvdT2aEp1yN9eOkaJkLT/ETKTvmqHncvK6ARonCHBgHCzwBe465PvemsnfNGKWAMw2f O+jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vOkTBrJ8rFY8f9IVX0lA4SgMpHXgic0fky3oKRvqHqk=; b=J+uydIRkmafsK9OhDSSx4VfZYD8PPpslFu7/SSpXY9ZkEZ6MMmcmI1o+cp9OJQ6cXz 1PpYAMIs5NeH7DgUmVww2rigYNqzyQBi5gMbeMHuh56ng4+se5c8kxthSDoprjwiUjbW FeZohP8S4ZQcuPgjg4obuf0TMARkXduGYRzqzd2v13XeP0jzCq81ZngxpWBvW/SEu39s H3t4bL8vdC/E1o7tHdbP9gCd7PWBNyBedTHXwlCzXitMezRXQtjUQQTyeb64v8iY9xzd OegayFQQDfWnvIXA3H2TTaBYLnX+pc9xFwa5kOTe+QpLk7g++w6gFgdRZSjzLZaAMhQg WoWQ== X-Gm-Message-State: AOAM532Yo8AAyyvWTlJ6HP2emuiPK9xg4MEMDG5BLxD5mGleTGQVUWB1 hte0F/XHSljQtQsvIH9NTh/3omjRcRXKMP7L X-Received: by 2002:a17:906:c317:: with SMTP id s23mr29050930ejz.127.1633526441458; Wed, 06 Oct 2021 06:20:41 -0700 (PDT) Received: from anparri.mshome.net (host-79-49-65-228.retail.telecomitalia.it. [79.49.65.228]) by smtp.gmail.com with ESMTPSA id e7sm10952836edk.3.2021.10.06.06.20.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 06:20:40 -0700 (PDT) From: "Andrea Parri (Microsoft)" To: linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-scsi@vger.kernel.org Cc: "K . Y . Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , "James E . J . Bottomley" , "Martin K . Petersen" , Michael Kelley , "Andrea Parri (Microsoft)" , Dexuan Cui Subject: [PATCH v2] scsi: storvsc: Fix validation for unsolicited incoming packets Date: Wed, 6 Oct 2021 15:20:26 +0200 Message-Id: <20211006132026.4089-1-parri.andrea@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The validation on the length of incoming packets performed in storvsc_on_channel_callback() does not apply to unsolicited packets with ID of 0 sent by Hyper-V. Adjust the validation for such unsolicited packets. Fixes: 91b1b640b834b2 ("scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()") Reported-by: Dexuan Cui Signed-off-by: Andrea Parri (Microsoft) --- Changes since v1[1]: - Use sizeof(enum vstor_packet_operation) instead of 48 (Michael Kelley) - Filter out FCHBA_DATA packets (Michael Kelley) Changes since RFC[2]: - Merge length checks (Haiyang Zhang) [1] https://lkml.kernel.org/r/20211005114103.3411-1-parri.andrea@gmail.com [2] https://lkml.kernel.org/r/20210928163732.5908-1-parri.andrea@gmail.com drivers/scsi/storvsc_drv.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index ebbbc1299c625..4869ebad7ec97 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -1285,11 +1285,15 @@ static void storvsc_on_channel_callback(void *context) foreach_vmbus_pkt(desc, channel) { struct vstor_packet *packet = hv_pkt_data(desc); struct storvsc_cmd_request *request = NULL; + u32 pktlen = hv_pkt_datalen(desc); u64 rqst_id = desc->trans_id; + u32 minlen = rqst_id ? sizeof(struct vstor_packet) - + stor_device->vmscsi_size_delta : sizeof(enum vstor_packet_operation); - if (hv_pkt_datalen(desc) < sizeof(struct vstor_packet) - - stor_device->vmscsi_size_delta) { - dev_err(&device->device, "Invalid packet len\n"); + if (pktlen < minlen) { + dev_err(&device->device, + "Invalid pkt: id=%llu, len=%u, minlen=%u\n", + rqst_id, pktlen, minlen); continue; } @@ -1302,13 +1306,25 @@ static void storvsc_on_channel_callback(void *context) if (rqst_id == 0) { /* * storvsc_on_receive() looks at the vstor_packet in the message - * from the ring buffer. If the operation in the vstor_packet is - * COMPLETE_IO, then we call storvsc_on_io_completion(), and - * dereference the guest memory address. Make sure we don't call - * storvsc_on_io_completion() with a guest memory address that is - * zero if Hyper-V were to construct and send such a bogus packet. + * from the ring buffer. + * + * - If the operation in the vstor_packet is COMPLETE_IO, then + * we call storvsc_on_io_completion(), and dereference the + * guest memory address. Make sure we don't call + * storvsc_on_io_completion() with a guest memory address + * that is zero if Hyper-V were to construct and send such + * a bogus packet. + * + * - If the operation in the vstor_packet is FCHBA_DATA, then + * we call cache_wwn(), and access the data payload area of + * the packet (wwn_packet); however, there is no guarantee + * that the packet is big enough to contain such area. + * Future-proof the code by rejecting such a bogus packet. + * + * XXX. Filter out all "invalid" operations. */ - if (packet->operation == VSTOR_OPERATION_COMPLETE_IO) { + if (packet->operation == VSTOR_OPERATION_COMPLETE_IO || + packet->operation == VSTOR_OPERATION_FCHBA_DATA) { dev_err(&device->device, "Invalid packet with ID of 0\n"); continue; } -- 2.25.1