From 0bb073b9e2cc58149b41a709c1f78db6c0f9a963 Mon Sep 17 00:00:00 2001 From: Zhang Lubo Date: Wed, 24 Feb 2016 11:54:53 +0800 Subject: MdeModulePkg:Fix a robustness issue of Mnp Driver v3: * When there exists duplicate items in VLAN variable , save the correct variable content back to the variable storage after duplicate items are removed Duplicate items in VLAN variable will cause MNP driver binding start function fall into infinite loop,so we should check it's content before using it. Cc: Fu Siyuan Cc: Ye Ting Cc: Wu Jiaxin Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zhang Lubo Reviewed-by: Ye Ting Reviewed-by: Fu Siyuan Reviewed-by: Wu Jiaxin --- MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c | 64 +++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 4 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c index 6e14c1f..98cbc2e 100644 --- a/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c +++ b/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c @@ -1,7 +1,7 @@ /** @file VLAN Config Protocol implementation and VLAN packet process routine. -Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full @@ -230,6 +230,59 @@ MnpInsertVlanTag ( VlanTci->Uint16 = HTONS (VlanTci->Uint16); } +/** + Check VLAN configuration variable and delete the duplicative content if has identical Vlan ID. + + @param[in] MnpDeviceData Pointer to the MNP device context data. + @param[in] Buffer Pointer to the buffer contains the array of VLAN_TCI. + @param[in] NumberOfVlan Pointer to number of VLAN. + @param[out] NewNumberOfVlan Pointer to number of unique VLAN. + + @retval EFI_SUCCESS The VLAN variable is successfully checked. + @retval EFI_OUT_OF_RESOURCES There is not enough resource to set the configuration. + +**/ +EFI_STATUS +MnpCheckVlanVariable ( + IN MNP_DEVICE_DATA *MnpDeviceData, + IN VLAN_TCI *Buffer, + IN UINTN NumberOfVlan, + OUT UINTN *NewNumberOfVlan + ) +{ + UINTN Index; + UINTN Index2; + UINTN Count; + BOOLEAN FoundDuplicateItem; + EFI_STATUS Status; + + Count = 0; + FoundDuplicateItem = FALSE; + Status = EFI_SUCCESS; + + for (Index = 0; Index < NumberOfVlan; Index++) { + for (Index2 = Index + 1; Index2 < NumberOfVlan; Index2++) { + if (Buffer[Index].Bits.Vid == Buffer[Index2].Bits.Vid) { + FoundDuplicateItem = TRUE; + Count++; + break; + } + } + if (FoundDuplicateItem) { + for (Index2 = Index +1; Index2 < NumberOfVlan; Index++, Index2++) { + CopyMem (Buffer + Index, Buffer + Index2, sizeof (VLAN_TCI)); + } + } + FoundDuplicateItem = FALSE; + } + + *NewNumberOfVlan = NumberOfVlan - Count; + if (Count != 0) { + Status = MnpSetVlanVariable (MnpDeviceData, *NewNumberOfVlan, Buffer); + } + + return Status; +} /** Get VLAN configuration variable. @@ -255,6 +308,7 @@ MnpGetVlanVariable ( UINTN BufferSize; EFI_STATUS Status; VLAN_TCI *Buffer; + UINTN NewNumberOfVlan; // // Get VLAN configuration from EFI Variable @@ -292,13 +346,15 @@ MnpGetVlanVariable ( return Status; } - *NumberOfVlan = BufferSize / sizeof (VLAN_TCI); - *VlanVariable = Buffer; + Status = MnpCheckVlanVariable (MnpDeviceData, Buffer, BufferSize / sizeof (VLAN_TCI), &NewNumberOfVlan); + if (!EFI_ERROR (Status)) { + *NumberOfVlan = NewNumberOfVlan; + *VlanVariable = Buffer; + } return Status; } - /** Set VLAN configuration variable. -- cgit v1.1