Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp736960pxb; Mon, 25 Oct 2021 17:48:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylQpRqoGlpPj5keY0JfoNPiGD9gkl0hYgDTKXAA6EkzSGlQilQwSvxkyLJ4UKePZeCP1wO X-Received: by 2002:a17:907:1c0b:: with SMTP id nc11mr18190619ejc.366.1635209293105; Mon, 25 Oct 2021 17:48:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635209293; cv=none; d=google.com; s=arc-20160816; b=PmccCRX5+0nk+wN/efb8GRlmfb3gSxghHhYVSsp4YF/WWXH5GfuK3AyvhfqiuUBanP /gh77bz/x+cqcNBD8Va9ri//6PaE2I2LCTXPyjFVZ+IRTA/UARkBlA9fQeAsnMOPGF8Y vVc3ZqJ2HOda1VyDqB6eODW8Xn/EG/cXTX+eIsmb4Hm/4k/LkXipXseta40UFQGtJGk7 K6ngyJ4/DKrZhbnuz0SgFjHF/VtKqZyAaTRFH/c+Tcx7tcNlp4dd3j3bSJ3flDfVop6w tVZpTE+IMu0Jn3FBVwNlgo5UZNKlwP9LBGHRST9I0juotPutwy5fFJ6ELRhghs2nlQWY buIQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tsIh9oIAapB3x6KoOC4VxsfK2PBttIYF/rUHhq63/IA=; b=V2XWhQNQJk1ZNrEw4DCwpWM2Kp0uQbyUmstkMM5SBc25/e5OjY5e6z0NKb9P+64aZo ANKndbUXGQ/iqjUmTBxHpwjxfZuxeUb4FqrjH1fAoNi2i/bfC3IsfoQynyM/SK7Wpsky 1gjIrG6YpDRTUjezmTFR5KjqfF7g46gttsF03I1k3J9lyzU8bccxdHs3qSHON05YkfUY K7K29wXRirVeU8lr20QEhXHkRCD3Vccm3n06PN7yqtjEQAxSC8C3WHktd+PPMeXTX07k 1Y6bHetozT9DaUzoOBR415sO3kI8DKeYSB+Z0gKhq5ZQ2A/+5vCol5vgi3pX9xsYOiLJ c5tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QvAvcyY6; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb11si8480183ejc.447.2021.10.25.17.47.49; Mon, 25 Oct 2021 17:48:13 -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=@linuxfoundation.org header.s=korg header.b=QvAvcyY6; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240346AbhJYUAX (ORCPT + 99 others); Mon, 25 Oct 2021 16:00:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:42516 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235534AbhJYT43 (ORCPT ); Mon, 25 Oct 2021 15:56:29 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A9FF761166; Mon, 25 Oct 2021 19:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635191199; bh=PIGsyyUj0X0Ys2iVMV+q+1ixTRzBlSVMdvmBndpyHZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QvAvcyY6ghu/cttZS964Rd2ySmJAVMH5dxuQtpPwZS77ZDcp+EASdfkrVO6MYBeUs lT5+aTwml5tgC0QQlICyj7fdApB/2QtmH2raleBl/O1WweBOnLOnyff8AuAMXF2TKP Horin48N5cbVgTZzIufjDxn04vlAkTNH9+IPy5YY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dexuan Cui , Michael Kelley , Haiyang Zhang , "Andrea Parri (Microsoft)" , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 5.14 150/169] scsi: storvsc: Fix validation for unsolicited incoming packets Date: Mon, 25 Oct 2021 21:15:31 +0200 Message-Id: <20211025191036.554792295@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025191017.756020307@linuxfoundation.org> References: <20211025191017.756020307@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrea Parri (Microsoft) [ Upstream commit 6fd13d699d24beaa28310848fe65fd898fbb9043 ] 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. Link: https://lore.kernel.org/r/20211007122828.469289-1-parri.andrea@gmail.com Fixes: 91b1b640b834b2 ("scsi: storvsc: Validate length of incoming packet in storvsc_on_channel_callback()") Reported-by: Dexuan Cui Reviewed-by: Michael Kelley Reviewed-by: Haiyang Zhang Signed-off-by: Andrea Parri (Microsoft) Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/storvsc_drv.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 37506b3fe5a9..5fa1120a87f7 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,23 @@ 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. */ - 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.33.0