Skip to content

Commit 6d52cf0

Browse files
Flickdmjgarver
authored andcommitted
NetworkPkg: Ip6Dxe: SECURITY PATCH CVE-2023-45231 Unit Tests
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4536 Validates that the patch for... Out-of-bounds read when handling a ND Redirect message with truncated options .. has been fixed Tests the following function to ensure that an out of bounds read does not occur Ip6OptionValidation Cc: Saloni Kasbekar <[email protected]> Cc: Zachary Clark-williams <[email protected]> Signed-off-by: Doug Flick [MSFT] <[email protected]> Reviewed-by: Saloni Kasbekar <[email protected]> Reviewed-by: Jeff Brasen <[email protected]> Tested-by: Jeff Brasen <[email protected]>
1 parent 1fafcd5 commit 6d52cf0

File tree

4 files changed

+192
-0
lines changed

4 files changed

+192
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @file
2+
Acts as the main entry point for the tests for the Ip6Dxe module.
3+
4+
Copyright (c) Microsoft Corporation
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
#include <gtest/gtest.h>
8+
9+
////////////////////////////////////////////////////////////////////////////////
10+
// Run the tests
11+
////////////////////////////////////////////////////////////////////////////////
12+
int
13+
main (
14+
int argc,
15+
char *argv[]
16+
)
17+
{
18+
testing::InitGoogleTest (&argc, argv);
19+
return RUN_ALL_TESTS ();
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## @file
2+
# Unit test suite for the Ip6Dxe using Google Test
3+
#
4+
# Copyright (c) Microsoft Corporation.<BR>
5+
# SPDX-License-Identifier: BSD-2-Clause-Patent
6+
##
7+
[Defines]
8+
INF_VERSION = 0x00010017
9+
BASE_NAME = Ip6DxeUnitTest
10+
FILE_GUID = 4F05D17D-D3E7-4AAE-820C-576D46D2D34A
11+
VERSION_STRING = 1.0
12+
MODULE_TYPE = HOST_APPLICATION
13+
#
14+
# The following information is for reference only and not required by the build tools.
15+
#
16+
# VALID_ARCHITECTURES = IA32 X64 AARCH64
17+
#
18+
[Sources]
19+
Ip6DxeGoogleTest.cpp
20+
Ip6OptionGoogleTest.cpp
21+
../Ip6Option.c
22+
23+
[Packages]
24+
MdePkg/MdePkg.dec
25+
MdeModulePkg/MdeModulePkg.dec
26+
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
27+
NetworkPkg/NetworkPkg.dec
28+
29+
[LibraryClasses]
30+
GoogleTestLib
31+
DebugLib
32+
NetLib
33+
PcdLib
34+
35+
[Protocols]
36+
gEfiDhcp6ServiceBindingProtocolGuid
37+
38+
[Pcd]
39+
gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType
40+
41+
[Guids]
42+
gZeroGuid
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/** @file
2+
Tests for Ip6Option.c.
3+
4+
Copyright (c) Microsoft Corporation
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
**/
7+
#include <gtest/gtest.h>
8+
9+
extern "C" {
10+
#include <Uefi.h>
11+
#include <Library/BaseLib.h>
12+
#include <Library/DebugLib.h>
13+
#include "../Ip6Impl.h"
14+
#include "../Ip6Option.h"
15+
}
16+
17+
/////////////////////////////////////////////////////////////////////////
18+
// Defines
19+
///////////////////////////////////////////////////////////////////////
20+
21+
#define IP6_PREFIX_INFO_OPTION_DATA_LEN 32
22+
#define OPTION_HEADER_IP6_PREFIX_DATA_LEN (sizeof (IP6_OPTION_HEADER) + IP6_PREFIX_INFO_OPTION_DATA_LEN)
23+
24+
////////////////////////////////////////////////////////////////////////
25+
// Symbol Definitions
26+
// These functions are not directly under test - but required to compile
27+
////////////////////////////////////////////////////////////////////////
28+
UINT32 mIp6Id;
29+
30+
EFI_STATUS
31+
Ip6SendIcmpError (
32+
IN IP6_SERVICE *IpSb,
33+
IN NET_BUF *Packet,
34+
IN EFI_IPv6_ADDRESS *SourceAddress OPTIONAL,
35+
IN EFI_IPv6_ADDRESS *DestinationAddress,
36+
IN UINT8 Type,
37+
IN UINT8 Code,
38+
IN UINT32 *Pointer OPTIONAL
39+
)
40+
{
41+
// ..
42+
return EFI_SUCCESS;
43+
}
44+
45+
////////////////////////////////////////////////////////////////////////
46+
// Ip6OptionValidation Tests
47+
////////////////////////////////////////////////////////////////////////
48+
49+
// Define a fixture for your tests if needed
50+
class Ip6OptionValidationTest : public ::testing::Test {
51+
protected:
52+
// Add any setup code if needed
53+
virtual void
54+
SetUp (
55+
)
56+
{
57+
// Initialize any resources or variables
58+
}
59+
60+
// Add any cleanup code if needed
61+
virtual void
62+
TearDown (
63+
)
64+
{
65+
// Clean up any resources or variables
66+
}
67+
};
68+
69+
// Test Description:
70+
// Null option should return false
71+
TEST_F (Ip6OptionValidationTest, NullOptionShouldReturnFalse) {
72+
UINT8 *option = nullptr;
73+
UINT16 optionLen = 10; // Provide a suitable length
74+
75+
EXPECT_FALSE (Ip6IsNDOptionValid (option, optionLen));
76+
}
77+
78+
// Test Description:
79+
// Truncated option should return false
80+
TEST_F (Ip6OptionValidationTest, TruncatedOptionShouldReturnFalse) {
81+
UINT8 option[] = { 0x01 }; // Provide a truncated option
82+
UINT16 optionLen = 1;
83+
84+
EXPECT_FALSE (Ip6IsNDOptionValid (option, optionLen));
85+
}
86+
87+
// Test Description:
88+
// Ip6OptionPrefixInfo Option with zero length should return false
89+
TEST_F (Ip6OptionValidationTest, OptionWithZeroLengthShouldReturnFalse) {
90+
IP6_OPTION_HEADER optionHeader;
91+
92+
optionHeader.Type = Ip6OptionPrefixInfo;
93+
optionHeader.Length = 0;
94+
UINT8 option[sizeof (IP6_OPTION_HEADER)];
95+
96+
CopyMem (option, &optionHeader, sizeof (IP6_OPTION_HEADER));
97+
UINT16 optionLen = sizeof (IP6_OPTION_HEADER);
98+
99+
EXPECT_FALSE (Ip6IsNDOptionValid (option, optionLen));
100+
}
101+
102+
// Test Description:
103+
// Ip6OptionPrefixInfo Option with valid length should return true
104+
TEST_F (Ip6OptionValidationTest, ValidPrefixInfoOptionShouldReturnTrue) {
105+
IP6_OPTION_HEADER optionHeader;
106+
107+
optionHeader.Type = Ip6OptionPrefixInfo;
108+
optionHeader.Length = 4; // Length 4 * 8 = 32
109+
UINT8 option[OPTION_HEADER_IP6_PREFIX_DATA_LEN];
110+
111+
CopyMem (option, &optionHeader, sizeof (IP6_OPTION_HEADER));
112+
113+
EXPECT_TRUE (Ip6IsNDOptionValid (option, IP6_PREFIX_INFO_OPTION_DATA_LEN));
114+
}
115+
116+
// Test Description:
117+
// Ip6OptionPrefixInfo Option with invalid length should return false
118+
TEST_F (Ip6OptionValidationTest, InvalidPrefixInfoOptionLengthShouldReturnFalse) {
119+
IP6_OPTION_HEADER optionHeader;
120+
121+
optionHeader.Type = Ip6OptionPrefixInfo;
122+
optionHeader.Length = 3; // Length 3 * 8 = 24 (Invalid)
123+
UINT8 option[sizeof (IP6_OPTION_HEADER)];
124+
125+
CopyMem (option, &optionHeader, sizeof (IP6_OPTION_HEADER));
126+
UINT16 optionLen = sizeof (IP6_OPTION_HEADER);
127+
128+
EXPECT_FALSE (Ip6IsNDOptionValid (option, optionLen));
129+
}

NetworkPkg/Test/NetworkPkgHostTest.dsc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# Build HOST_APPLICATION that tests NetworkPkg
2727
#
2828
NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf
29+
NetworkPkg/Ip6Dxe/GoogleTest/Ip6DxeGoogleTest.inf
2930

3031
# Despite these library classes being listed in [LibraryClasses] below, they are not needed for the host-based unit tests.
3132
[LibraryClasses]

0 commit comments

Comments
 (0)