summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYi Zhao <yi.zhao@windriver.com>2025-02-21 16:12:07 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-02-25 12:17:22 +0000
commitcf8b4459a52d0952bceb91dabad09ff2fff55ea0 (patch)
tree46f8670db6d95849d22bdf395db7170a18a291e3
parent131163d59d668ad29217a62dbc112a18b5701573 (diff)
downloadpoky-cf8b4459a52d0952bceb91dabad09ff2fff55ea0.tar.gz
kea: avoid assertion on empty DHCPDISCOVER packet
When kea is built with "-D_GLIBCXX_ASSERTIONS " set in SECURITY_CFLAGS, an assertion occurs if the kea server receives an empty DHCPDISCOVER packet: kea-dhcp4[596]: /usr/include/c++/13.3.0/bits/stl_vector.h:1128: std::vector<Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = unsigned char; _Alloc = std::allocator<unsigned char>; reference = unsigned char&; size_type = long unsigned int]: Assertion '_n < this->size()' failed. Backport patches to fix this issue[1]. [1] https://gitlab.isc.org/isc-projects/kea/-/commit/0b98eae16d9b6ecdf57005624712b9b26fa05bc0 https://gitlab.isc.org/isc-projects/kea/-/commit/16306026e37b32a2ce4b16fb5b78561ae153d570 (From OE-Core rev: 17c67a47ec9c6e90a339f32c35f80ca4c908a254) Signed-off-by: Yi Zhao <yi.zhao@windriver.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-connectivity/kea/files/0001-Avoid-assert-on-empty-packet.patch148
-rw-r--r--meta/recipes-connectivity/kea/kea_2.6.1.bb1
2 files changed, 149 insertions, 0 deletions
diff --git a/meta/recipes-connectivity/kea/files/0001-Avoid-assert-on-empty-packet.patch b/meta/recipes-connectivity/kea/files/0001-Avoid-assert-on-empty-packet.patch
new file mode 100644
index 0000000000..14f3424570
--- /dev/null
+++ b/meta/recipes-connectivity/kea/files/0001-Avoid-assert-on-empty-packet.patch
@@ -0,0 +1,148 @@
1From 9cf3b6e8d705957927c2fbc9928318f4eda265c8 Mon Sep 17 00:00:00 2001
2From: Thomas Markwalder <tmark@isc.org>
3Date: Tue, 11 Feb 2025 18:52:41 +0000
4Subject: [PATCH 1/2] Avoid assert on empty packet
5
6/src/lib/dhcp/pkt_filter_lpf.cc
7 PktFilterLPF::receive() - throw if packet has no data
8
9/src/lib/util/buffer.h
10 InputBuffer::readVecotr() - avoid peek if read request length is 0
11
12/src/lib/util/tests/buffer_unittest.cc
13 Updated test
14
15Upstream-Status: Backport
16[https://gitlab.isc.org/isc-projects/kea/-/commit/0b98eae16d9b6ecdf57005624712b9b26fa05bc0]
17[https://gitlab.isc.org/isc-projects/kea/-/commit/16306026e37b32a2ce4b16fb5b78561ae153d570]
18
19Signed-off-by: Yi Zhao <yi.zhao@windriver.com>
20---
21 src/lib/dhcp/pkt_filter_lpf.cc | 10 +++++++---
22 src/lib/util/buffer.h | 9 ++++++---
23 src/lib/util/tests/buffer_unittest.cc | 8 +++++++-
24 3 files changed, 20 insertions(+), 7 deletions(-)
25
26diff --git a/src/lib/dhcp/pkt_filter_lpf.cc b/src/lib/dhcp/pkt_filter_lpf.cc
27index 69bdecc0e1..b0c8f108d3 100644
28--- a/src/lib/dhcp/pkt_filter_lpf.cc
29+++ b/src/lib/dhcp/pkt_filter_lpf.cc
30@@ -318,9 +318,14 @@ PktFilterLPF::receive(Iface& iface, const SocketInfo& socket_info) {
31 decodeEthernetHeader(buf, dummy_pkt);
32 decodeIpUdpHeader(buf, dummy_pkt);
33
34+ auto v4_len = buf.getLength() - buf.getPosition();
35+ if (v4_len <= 0) {
36+ isc_throw(SocketReadError, "Pkt4FilterLpf:: packet has no DHCPv4 data");
37+ }
38+
39 // Read the DHCP data.
40 std::vector<uint8_t> dhcp_buf;
41- buf.readVector(dhcp_buf, buf.getLength() - buf.getPosition());
42+ buf.readVector(dhcp_buf, v4_len);
43
44 // Decode DHCP data into the Pkt4 object.
45 Pkt4Ptr pkt = Pkt4Ptr(new Pkt4(&dhcp_buf[0], dhcp_buf.size()));
46@@ -344,8 +349,7 @@ PktFilterLPF::receive(Iface& iface, const SocketInfo& socket_info) {
47
48 struct timeval cmsg_time;
49 memcpy(&cmsg_time, CMSG_DATA(cmsg), sizeof(cmsg_time));
50- pkt->addPktEvent(PktEvent::SOCKET_RECEIVED, cmsg_time);
51- break;
52+ pkt->addPktEvent(PktEvent::SOCKET_RECEIVED, cmsg_time); break;
53 }
54
55 cmsg = CMSG_NXTHDR(&m, cmsg);
56diff --git a/src/lib/util/buffer.h b/src/lib/util/buffer.h
57index 41ecdf3375..c426a14495 100644
58--- a/src/lib/util/buffer.h
59+++ b/src/lib/util/buffer.h
60@@ -1,4 +1,4 @@
61-// Copyright (C) 2009-2024 Internet Systems Consortium, Inc. ("ISC")
62+// Copyright (C) 2009-2025 Internet Systems Consortium, Inc. ("ISC")
63 //
64 // This Source Code Form is subject to the terms of the Mozilla Public
65 // License, v. 2.0. If a copy of the MPL was not distributed with this
66@@ -233,7 +233,8 @@ public:
67 /// @details If specified buffer is too short, it will be expanded using
68 /// vector::resize() method. If the remaining length of the buffer
69 /// is smaller than the specified length, an exception of class
70- /// @c isc::OutOfRange will be thrown.
71+ /// @c isc::OutOfRange will be thrown. Read length zero results
72+ /// in an empty vector.
73 ///
74 /// @param data Reference to a buffer (data will be stored there).
75 /// @param len Size specified number of bytes to read in a vector.
76@@ -244,7 +245,9 @@ public:
77 }
78
79 data.resize(len);
80- peekData(&data[0], len);
81+ if (len) {
82+ peekData(&data[0], len);
83+ }
84 }
85
86 /// @brief Read specified number of bytes as a vector.
87diff --git a/src/lib/util/tests/buffer_unittest.cc b/src/lib/util/tests/buffer_unittest.cc
88index 66c43e8f21..bae051dd16 100644
89--- a/src/lib/util/tests/buffer_unittest.cc
90+++ b/src/lib/util/tests/buffer_unittest.cc
91@@ -1,4 +1,4 @@
92-// Copyright (C) 2009-2024 Internet Systems Consortium, Inc. ("ISC")
93+// Copyright (C) 2009-2025 Internet Systems Consortium, Inc. ("ISC")
94 //
95 // This Source Code Form is subject to the terms of the Mozilla Public
96 // License, v. 2.0. If a copy of the MPL was not distributed with this
97@@ -197,6 +197,12 @@ TEST_F(BufferTest, inputBufferRead) {
98 ASSERT_EQ(sizeof(vdata), datav.size());
99 ASSERT_EQ(0, memcmp(&vdata[0], testdata, sizeof(testdata)));
100 ASSERT_EQ(sizeof(vdata), ibuffer.getPosition());
101+
102+ // Verify that read len of zero results in an empty
103+ // vector without throwing.
104+ datav.resize(8);
105+ ASSERT_NO_THROW(ibuffer.readVector(datav, 0));
106+ ASSERT_EQ(datav.size(), 0);
107 }
108
109 TEST_F(BufferTest, outputBufferReadAt) {
110--
1112.25.1
112
113From 614a6c136fc20ee428b1c880889ef61253657499 Mon Sep 17 00:00:00 2001
114From: Thomas Markwalder <tmark@isc.org>
115Date: Tue, 18 Feb 2025 15:03:12 +0000
116Subject: [PATCH 2/2] Addressed review comments
117
118Couple of typos fixed.
119---
120 src/lib/dhcp/pkt_filter_lpf.cc | 5 +++--
121 1 file changed, 3 insertions(+), 2 deletions(-)
122
123diff --git a/src/lib/dhcp/pkt_filter_lpf.cc b/src/lib/dhcp/pkt_filter_lpf.cc
124index b0c8f108d3..3642915cc1 100644
125--- a/src/lib/dhcp/pkt_filter_lpf.cc
126+++ b/src/lib/dhcp/pkt_filter_lpf.cc
127@@ -320,7 +320,7 @@ PktFilterLPF::receive(Iface& iface, const SocketInfo& socket_info) {
128
129 auto v4_len = buf.getLength() - buf.getPosition();
130 if (v4_len <= 0) {
131- isc_throw(SocketReadError, "Pkt4FilterLpf:: packet has no DHCPv4 data");
132+ isc_throw(SocketReadError, "Pkt4FilterLpf packet has no DHCPv4 data");
133 }
134
135 // Read the DHCP data.
136@@ -349,7 +349,8 @@ PktFilterLPF::receive(Iface& iface, const SocketInfo& socket_info) {
137
138 struct timeval cmsg_time;
139 memcpy(&cmsg_time, CMSG_DATA(cmsg), sizeof(cmsg_time));
140- pkt->addPktEvent(PktEvent::SOCKET_RECEIVED, cmsg_time); break;
141+ pkt->addPktEvent(PktEvent::SOCKET_RECEIVED, cmsg_time);
142+ break;
143 }
144
145 cmsg = CMSG_NXTHDR(&m, cmsg);
146--
1472.25.1
148
diff --git a/meta/recipes-connectivity/kea/kea_2.6.1.bb b/meta/recipes-connectivity/kea/kea_2.6.1.bb
index c2818c3386..ff7fb51fe0 100644
--- a/meta/recipes-connectivity/kea/kea_2.6.1.bb
+++ b/meta/recipes-connectivity/kea/kea_2.6.1.bb
@@ -21,6 +21,7 @@ SRC_URI = "http://ftp.isc.org/isc/kea/${PV}/${BP}.tar.gz \
21 file://0002-Fix-unittests-Typo-in-Name-Name-append-to-ndata_-not.patch \ 21 file://0002-Fix-unittests-Typo-in-Name-Name-append-to-ndata_-not.patch \
22 file://0001-Update-asiolink-for-boost-1.87.patch \ 22 file://0001-Update-asiolink-for-boost-1.87.patch \
23 file://0001-make-kea-environment-available-to-lfc.patch \ 23 file://0001-make-kea-environment-available-to-lfc.patch \
24 file://0001-Avoid-assert-on-empty-packet.patch \
24 " 25 "
25SRC_URI[sha256sum] = "d2ce14a91c2e248ad2876e29152d647bcc5e433bc68dafad0ee96ec166fcfad1" 26SRC_URI[sha256sum] = "d2ce14a91c2e248ad2876e29152d647bcc5e433bc68dafad0ee96ec166fcfad1"
26 27