From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [62.140.7.102]) by mx.groups.io with SMTP id smtpd.web11.10946.1594885613071820969 for ; Thu, 16 Jul 2020 00:46:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@suse.com header.s=mimecast20200619 header.b=lsQJs3Dh; spf=pass (domain: suse.com, ip: 62.140.7.102, mailfrom: glin@suse.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1594885611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GTqVTlPBL7s9yX1288TZLA/gDdeay+qcOjs7f18qvro=; b=lsQJs3DhYpiFKGa4nri8gi/UDjb8Ar4+d4MnyVHIRIO2ReyfmIiLeo63OUay8LEydcX1yH 57cLsietOCzBt+yXCQub85Oe9HXQbWVCM5CpwbEY8SUnPQ8eIRq0f8VxwBRKB+eGHVWb0E 0qurXZPGQ/aAKKrownHRJjU2bAYJA7U= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2177.outbound.protection.outlook.com [104.47.17.177]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-26-JfV3JUdfP5eu6bWsyqNWxQ-1; Thu, 16 Jul 2020 09:46:50 +0200 X-MC-Unique: JfV3JUdfP5eu6bWsyqNWxQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C6X453UZn3essIwX/+qOyg6z0ezl6z7bfMHWGpfYkWJhX7rKI8Fuplep1UCIhZWuOd7OouNZ9LAxE8J0E9GUiL6uk5DiFMHSsmQU1xaBEbFlvqRie3bGUAuRBkGWYZNCFrh2Pqu8ppO0ZbJwwNKd4vmWEikAYH4TswTC7jKHHcVTQml0HIdsSGunc/5qqBYJiBx2R4KaxJxJCb7ReD9XJjLPxL/3U6LB5uWkl4RjA05N3DRpU/vWqqybMXpBw0HgJ4jnIrtxZkrdFFrpYivmVogt5RVLQ0dX0lFYTJzTQ+M7dhCdnIUOrf0kngIoHV/+L5CjAowJEC+1uKYFqX5Wng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GTqVTlPBL7s9yX1288TZLA/gDdeay+qcOjs7f18qvro=; b=HXcQuPrR+VjAyeOEFHMhNKhTwTnyuKgPLI+SqhA/DeO1BDweBxMjL/daqcc4wLMuWj/jUHI2EbMcf9887zZrBvhTY8NKXoo52xY84A4VWwimpJpiFgtyqRF3HiNRW6cesKctUZWAnjFILbfX+eGIG1NQG/XNYTfCLDLv+FhXhsiISo/cunUxCm/4XBO4FK4JIsuasn+MA11lSZBJlt5/nb6hiIcT6ioyg+Oz0XsZ7HNE4t/ceDuV+qqKejQl91q3zozyFPdN1rOfaMcb6qZ5A0hcOsql5yAqIxY5hr4+/46JOCbEJQ6fIIGurfqhUscy8PsT5pGcgLtr0o88VOkjQw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=suse.com; Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) by AM0PR04MB4740.eurprd04.prod.outlook.com (2603:10a6:208:c8::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Thu, 16 Jul 2020 07:46:44 +0000 Received: from AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba]) by AM0PR0402MB3809.eurprd04.prod.outlook.com ([fe80::a14c:d441:c8a9:77ba%6]) with mapi id 15.20.3174.026; Thu, 16 Jul 2020 07:46:44 +0000 From: "Gary Lin" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 09/12] OvmfPkg/LsiScsiDxe: Examine the incoming SCSI Request Packet Date: Thu, 16 Jul 2020 15:46:04 +0800 Message-Id: <20200716074607.18048-10-glin@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200716074607.18048-1-glin@suse.com> References: <20200716074607.18048-1-glin@suse.com> X-ClientProxiedBy: AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) To AM0PR0402MB3809.eurprd04.prod.outlook.com (2603:10a6:208:10::30) Return-Path: glin@suse.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from GaryWorkstation.suse.cz (60.251.47.115) by AM3PR07CA0118.eurprd07.prod.outlook.com (2603:10a6:207:7::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Thu, 16 Jul 2020 07:46:42 +0000 X-Mailer: git-send-email 2.25.1 X-Originating-IP: [60.251.47.115] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f3c21fa-ad85-499a-44a6-08d8295c6271 X-MS-TrafficTypeDiagnostic: AM0PR04MB4740: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AsJeILjkjlA3U3C3tgnyW3v3j5p36OIHKmIxhRkjSbAnPENb2M2JsYb7flIfkcXDaUTdRYG/jBw0u118c5Lk0HomkpCOpNNEh50GBjis5v1LzsNLQ41eWt7Cnkf5jHNPwiBmLV/hWEY2tNI91s+4q9Ohiob0lcVdOmg6ax+6QGV6XFcwCj5a7gQ3x/L1qlR01D528V2nD1XJTIkvUX2nUc1GnBOpQcnRfv1Ol/LRPci28wkcQc8/q0MPesaS3Af0z+31+CWZa7e1jKLC0fDwgpeoZNT2pFOmNalrkY/hxNzoNwO0RoEn0Cs7OPo4/JONmYigjDE25thPVY+xO2OMeg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR0402MB3809.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(136003)(376002)(346002)(39860400002)(366004)(396003)(2616005)(956004)(26005)(478600001)(8936002)(36756003)(2906002)(54906003)(8676002)(52116002)(6916009)(316002)(6512007)(186003)(16526019)(1076003)(6486002)(5660300002)(66556008)(66476007)(66946007)(6666004)(83380400001)(86362001)(6506007)(55236004)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: RPRatpDWMLhXZK3OjcliZxO2S0lymlOA5bMOM32/iH2H/3bW+hfu5SvPi6UYPODHH7wSD6AFef0udSICD6anANml5sRtbxTdQ1/p4JS6BhfIoaaDHJ46H5/efrMA2rqoEp3QZ/55bw85VNOOwD4ya8wGSArBP55ziNWVi9h2GHeEdRRE9HtKHt8JZvlTPxN4aYfs33RglR6Hx3NLmo6oOyUZXZ0LSCQb4n6yJyVa2SlJ6Ar4Yk4+ObE0ntmGLiPouBK4t/TsWsczX22SOh+1kuIn24eqAxRJiKNhLrRt4B8c8a6vCe/pjjcFwmE7RqagUWDlwwRrYS4Ll/+DZI+vqIcjayXGj73J20nv3vzQCQbNAYs8QhC0oxcWBxQyli8k/H5cEAVl9Kq8ybhIDTQysJVd1gCFQ07Jwt2arwRNQHaHjBaRiWxJRvC5rXfSNLHp+wFkl3X6hQFmUphUlBMK/f1znuec5K7rV6dwHqLPlUQ= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f3c21fa-ad85-499a-44a6-08d8295c6271 X-MS-Exchange-CrossTenant-AuthSource: AM0PR0402MB3809.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jul 2020 07:46:44.4841 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gjxue7DUrA9pb3l+9aCsQgoAKKi0Q+rQ68hIoSnmLaphpONAz9/wLjE6Gi2Qbji3 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4740 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This is the first part of LsiScsiPassThru(). Before processing the SCSI Request packet, we have to make sure whether the packet is valid or not. v2: Make LsiScsiPassThru() return EFI_UNSUPPORTED since this function is half-implemented Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Gary Lin Reviewed-by: Laszlo Ersek --- OvmfPkg/LsiScsiDxe/LsiScsi.c | 98 ++++++++++++++++++++++++++++++++++++ OvmfPkg/LsiScsiDxe/LsiScsi.h | 4 ++ 2 files changed, 102 insertions(+) diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.c b/OvmfPkg/LsiScsiDxe/LsiScsi.c index 4e84afa40085..b3a88cc7119b 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.c +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.c @@ -52,6 +52,95 @@ LsiScsiReset ( return Out8 (Dev, LSI_REG_ISTAT0, LSI_ISTAT0_SRST);=0D }=0D =0D +STATIC=0D +EFI_STATUS=0D +ReportHostAdapterOverrunError (=0D + OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet=0D + )=0D +{=0D + Packet->SenseDataLength =3D 0;=0D + Packet->HostAdapterStatus =3D=0D + EFI_EXT_SCSI_STATUS_HOST_ADAPTER_DATA_OVERRUN_UNDERRUN;=0D + Packet->TargetStatus =3D EFI_EXT_SCSI_STATUS_TARGET_GOOD;=0D + return EFI_BAD_BUFFER_SIZE;=0D +}=0D +=0D +/**=0D +=0D + Check the request packet from the Extended SCSI Pass Thru Protocol. The= =0D + request packet is modified, to be forwarded outwards by LsiScsiPassThru(= ),=0D + if invalid or unsupported parameters are detected.=0D +=0D + @param[in] Dev The LSI 53C895A SCSI device the packet targets.= =0D +=0D + @param[in] Target The SCSI target controlled by the LSI 53C895A SC= SI=0D + device.=0D +=0D + @param[in] Lun The Logical Unit Number under the SCSI target.=0D +=0D + @param[in out] Packet The Extended SCSI Pass Thru Protocol packet.=0D +=0D +=0D + @retval EFI_SUCCESS The Extended SCSI Pass Thru Protocol packet was val= id.=0D +=0D + @return Otherwise, invalid or unsupported parameters were=0D + detected. Status codes are meant for direct forward= ing=0D + by the EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru()=0D + implementation.=0D +=0D + **/=0D +STATIC=0D +EFI_STATUS=0D +LsiScsiCheckRequest (=0D + IN LSI_SCSI_DEV *Dev,=0D + IN UINT8 Target,=0D + IN UINT64 Lun,=0D + IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet=0D + )=0D +{=0D + if (Target > Dev->MaxTarget || Lun > Dev->MaxLun ||=0D + Packet->DataDirection > EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTIONAL ||= =0D + //=0D + // Trying to receive, but destination pointer is NULL, or contradict= ing=0D + // transfer direction=0D + //=0D + (Packet->InTransferLength > 0 &&=0D + (Packet->InDataBuffer =3D=3D NULL ||=0D + Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_WRITE=0D + )=0D + ) ||=0D +=0D + //=0D + // Trying to send, but source pointer is NULL, or contradicting tran= sfer=0D + // direction=0D + //=0D + (Packet->OutTransferLength > 0 &&=0D + (Packet->OutDataBuffer =3D=3D NULL ||=0D + Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_READ=0D + )=0D + )=0D + ) {=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (Packet->DataDirection =3D=3D EFI_EXT_SCSI_DATA_DIRECTION_BIDIRECTION= AL ||=0D + (Packet->InTransferLength > 0 && Packet->OutTransferLength > 0) ||=0D + Packet->CdbLength > sizeof Dev->Dma->Cdb) {=0D + return EFI_UNSUPPORTED;=0D + }=0D +=0D + if (Packet->InTransferLength > sizeof Dev->Dma->Data) {=0D + Packet->InTransferLength =3D sizeof Dev->Dma->Data;=0D + return ReportHostAdapterOverrunError (Packet);=0D + }=0D + if (Packet->OutTransferLength > sizeof Dev->Dma->Data) {=0D + Packet->OutTransferLength =3D sizeof Dev->Dma->Data;=0D + return ReportHostAdapterOverrunError (Packet);=0D + }=0D +=0D + return EFI_SUCCESS;=0D +}=0D +=0D //=0D // The next seven functions implement EFI_EXT_SCSI_PASS_THRU_PROTOCOL=0D // for the LSI 53C895A SCSI Controller. Refer to UEFI Spec 2.3.1 + Errata = C,=0D @@ -70,6 +159,15 @@ LsiScsiPassThru ( IN EFI_EVENT Event OPTIONAL=0D )=0D {=0D + EFI_STATUS Status;=0D + LSI_SCSI_DEV *Dev;=0D +=0D + Dev =3D LSI_SCSI_FROM_PASS_THRU (This);=0D + Status =3D LsiScsiCheckRequest (Dev, *Target, Lun, Packet);=0D + if (EFI_ERROR (Status)) {=0D + return Status;=0D + }=0D +=0D return EFI_UNSUPPORTED;=0D }=0D =0D diff --git a/OvmfPkg/LsiScsiDxe/LsiScsi.h b/OvmfPkg/LsiScsiDxe/LsiScsi.h index 9f9e5c7fed00..05deeed379fe 100644 --- a/OvmfPkg/LsiScsiDxe/LsiScsi.h +++ b/OvmfPkg/LsiScsiDxe/LsiScsi.h @@ -13,6 +13,10 @@ #define _LSI_SCSI_DXE_H_=0D =0D typedef struct {=0D + //=0D + // The max size of CDB is 32.=0D + //=0D + UINT8 Cdb[32];=0D //=0D // Allocate 64KB for read/write buffer. It seems sufficient for the comm= on=0D // boot scenarios.=0D --=20 2.25.1