From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 621C8740032 for ; Sat, 26 Aug 2023 01:58:20 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=jazbO/At9fdoO+qLWW/mQyAba5SATJocCjh+1++cxpQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1693015099; v=1; b=B5mKjX2O/ILgrya3pLeZ5e+CyLY4PPdt1vC5frE94CQcRVYFdys2poZguQ1R9fbBqFdsFc0m 0k3xAbI923xHy05qtEf2wZc89cEa8NrRM2O1OLGuwqacfnjHpEzYbOWfSFUhj5D2xk37rWYU2UB AM5ZUkjBrC2pWXFuGMGW8RE0= X-Received: by 127.0.0.2 with SMTP id h8WQYY7687511xseM0ioNiyB; Fri, 25 Aug 2023 18:58:19 -0700 X-Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by mx.groups.io with SMTP id smtpd.web10.1692.1693015098206580141 for ; Fri, 25 Aug 2023 18:58:18 -0700 X-Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-50043cf2e29so2229595e87.2 for ; Fri, 25 Aug 2023 18:58:17 -0700 (PDT) X-Gm-Message-State: cY2ZRxOGaLzeBYyhQ9VNv4Bkx7686176AA= X-Google-Smtp-Source: AGHT+IFALut+4ojY2fWXayRbsL1SbMmPMqnU7ypqkG5J4Zs4BVeALFld6COnU2kc0uKebwA3/CEFYw== X-Received: by 2002:a05:6512:2524:b0:4fe:5a4b:911d with SMTP id be36-20020a056512252400b004fe5a4b911dmr15128797lfb.64.1693015096058; Fri, 25 Aug 2023 18:58:16 -0700 (PDT) X-Received: from localhost.localdomain ([79.164.221.98]) by smtp.gmail.com with ESMTPSA id a5-20020a19f805000000b0050078c9b53asm509879lff.231.2023.08.25.18.58.15 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 25 Aug 2023 18:58:15 -0700 (PDT) From: "Mike Maslenkin" To: devel@edk2.groups.io Cc: richardho@ami.com, rebecca@bsdio.com, Mike Maslenkin Subject: [edk2-devel] [PATCH 1/2] MdeModulePkg: UsbNetwork: fix Ethernet functional descriptor processing Date: Sat, 26 Aug 2023 04:57:59 +0300 Message-Id: <20230826015800.74524-2-mike.maslenkin@gmail.com> In-Reply-To: <20230826015800.74524-1-mike.maslenkin@gmail.com> References: <20230826015800.74524-1-mike.maslenkin@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mike.maslenkin@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=B5mKjX2O; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io This patch fixes wrong condition because of UINT16 value to integer promotion. NumberMcFilters is UINT16 value, so when bitwise shift operator applied to small integer type, the operation is preceded by integral promotion. This is described in MISRA-C:2004 guideline as Rule 10.5: "If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand." A simple fix for this issue would be the following: if ((UINT16)(UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) But this patch proposes to use bitwise AND operation with a proper bit mask rather than shifting to prevent similar mistakes in future. Cc: Richard Ho Cc: Rebecca Cran Signed-off-by: Mike Maslenkin --- MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c | 2 +- MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c | 2 +- MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c | 2 +- MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c | 4 ++-- MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h | 2 ++ 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c b/= MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c index daa30f081500..62df4e92ea01 100644 --- a/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c +++ b/MdeModulePkg/Bus/Usb/UsbNetwork/NetworkCommon/PxeFunction.c @@ -829,7 +829,7 @@ SetFilter ( }=0D =0D Nic->UsbEth->UsbEthFunDescriptor (Nic->UsbEth, &UsbEthFunDescriptor);= =0D - if ((UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) {=0D + if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) =3D=3D 0)= {=0D Nic->RxFilter |=3D PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST;=0D Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);=0D } else {=0D diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c b/M= deModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c index 63003e07ff52..29f4508a38ce 100644 --- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c +++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcEcm/UsbEcmFunction.c @@ -628,7 +628,7 @@ SetUsbEthMcastFilter ( return Status;=0D }=0D =0D - if ((UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) {=0D + if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) =3D=3D 0) {= =0D return EFI_UNSUPPORTED;=0D }=0D =0D diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c b/M= deModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c index 2a2454f466f7..baa2225bf8a8 100644 --- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c +++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbCdcNcm/UsbNcmFunction.c @@ -714,7 +714,7 @@ SetUsbEthMcastFilter ( return Status;=0D }=0D =0D - if ((UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) {=0D + if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) =3D=3D 0) {= =0D return EFI_UNSUPPORTED;=0D }=0D =0D diff --git a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c b/= MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c index b3632233add1..2c0dcae4cf96 100644 --- a/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c +++ b/MdeModulePkg/Bus/Usb/UsbNetwork/UsbRndis/UsbRndisFunction.c @@ -661,7 +661,7 @@ SetUsbRndisMcastFilter ( return Status;=0D }=0D =0D - if ((UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) {=0D + if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) =3D=3D 0) {= =0D return EFI_UNSUPPORTED;=0D }=0D =0D @@ -856,7 +856,7 @@ RndisUndiReceiveFilter ( }=0D =0D Nic->UsbEth->UsbEthFunDescriptor (Nic->UsbEth, &UsbEthFunDescriptor);= =0D - if ((UsbEthFunDescriptor.NumberMcFilters << 1) =3D=3D 0) {=0D + if ((UsbEthFunDescriptor.NumberMcFilters & MAC_FILTERS_MASK) =3D=3D 0)= {=0D Nic->RxFilter |=3D PXE_OPFLAGS_RECEIVE_FILTER_ALL_MULTICAST;=0D DEBUG ((DEBUG_INFO, "SetUsbEthPacketFilter Nic %lx Nic->UsbEth %lx "= , Nic, Nic->UsbEth));=0D Nic->UsbEth->SetUsbEthPacketFilter (Nic->UsbEth, Nic->RxFilter);=0D diff --git a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h b/MdeModul= ePkg/Include/Protocol/UsbEthernetProtocol.h index 800945d4b397..4cc2cee1167d 100644 --- a/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h +++ b/MdeModulePkg/Include/Protocol/UsbEthernetProtocol.h @@ -42,6 +42,8 @@ typedef struct _EDKII_USB_ETHERNET_PROTOCOL EDKII_USB_ETH= ERNET_PROTOCOL; #define NETWORK_CONNECTED 0x01=0D #define NETWORK_DISCONNECT 0x00=0D =0D +#define MAC_FILTERS_MASK 0x7FFF=0D +=0D // USB Header functional Descriptor=0D typedef struct {=0D UINT8 FunctionLength;=0D --=20 2.32.0 (Apple Git-132) -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#108040): https://edk2.groups.io/g/devel/message/108040 Mute This Topic: https://groups.io/mt/100968487/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-