diff options
author | Zhang Lubo <lubo.zhang@intel.com> | 2016-02-24 11:54:53 +0800 |
---|---|---|
committer | Jiaxin Wu <jiaxin.wu@intel.com> | 2016-02-29 09:24:58 +0800 |
commit | 0bb073b9e2cc58149b41a709c1f78db6c0f9a963 (patch) | |
tree | dd968ca6b4e0e9e7042e506b2c3c4fcb8dad9579 /MdeModulePkg | |
parent | d2ba6f41e2f8cbc8dffee8bddaebbbd6f3a3b9ab (diff) | |
download | edk2-platforms-0bb073b9e2cc58149b41a709c1f78db6c0f9a963.tar.xz |
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 <siyuan.fu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c b/MdeModulePkg/Universal/Network/MnpDxe/MnpVlan.c index 6e14c1f37f..98cbc2e35d 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.<BR>
+Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
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.
|