Skip to content

Commit f6e34f4

Browse files
yunhanw-googlerestyled-commitsbzbarsky-apple
authored
[SVE][ICD] Bump MaxICDMonitoringEntrySize to reasonable size (#35737)
* Fix icd monitor entry size * Restyled by whitespace * Restyled by clang-format * port test from pr 35734 * update documentation * Update src/app/icd/server/ICDMonitoringTable.h Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent 8f80f98 commit f6e34f4

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/app/icd/server/ICDMonitoringTable.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ CHIP_ERROR ICDMonitoringEntry::Serialize(TLV::TLVWriter & writer) const
5353
ReturnErrorOnFailure(writer.Put(TLV::ContextTag(Fields::kClientType), clientType));
5454

5555
ReturnErrorOnFailure(writer.EndContainer(outer));
56+
ReturnErrorOnFailure(writer.Finalize());
5657
return CHIP_NO_ERROR;
5758
}
5859

src/app/icd/server/ICDMonitoringTable.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@ using SymmetricKeystore = SessionKeystore;
3434

3535
namespace chip {
3636

37-
inline constexpr size_t kICDMonitoringBufferSize = 60;
37+
static constexpr size_t MaxICDMonitoringEntrySize()
38+
{
39+
// All the fields added together
40+
return TLV::EstimateStructOverhead(sizeof(NodeId) /*checkInNodeID*/, sizeof(uint64_t) /*monitoredSubject*/,
41+
sizeof(Crypto::Symmetric128BitsKeyByteArray) /*aes_key_handle*/,
42+
sizeof(Crypto::Symmetric128BitsKeyByteArray) /*hmac_key_handle*/,
43+
sizeof(uint8_t) /*client_type*/) *
44+
// Provide 50% extra space to make a firmware upgrade that starts storing
45+
// more data followed by a downgrade work easily and reliably.
46+
// The 50% number is chosen fairly randomly; storage increases larger than that are
47+
// possible but need to be staged carefully.
48+
3 / 2;
49+
}
50+
51+
inline constexpr size_t kICDMonitoringBufferSize = MaxICDMonitoringEntrySize();
3852

3953
struct ICDMonitoringEntry : public PersistentData<kICDMonitoringBufferSize>
4054
{
41-
4255
ICDMonitoringEntry(FabricIndex fabric = kUndefinedFabricIndex, NodeId nodeId = kUndefinedNodeId)
4356
{
4457
this->fabricIndex = fabric;

src/app/icd/server/tests/TestICDMonitoringTable.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ constexpr uint64_t kClientNodeId13 = 0x100003;
4343
constexpr uint64_t kClientNodeId21 = 0x200001;
4444
constexpr uint64_t kClientNodeId22 = 0x200002;
4545

46+
constexpr uint64_t kClientNodeMaxValue = std::numeric_limits<uint64_t>::max();
47+
4648
constexpr uint8_t kKeyBuffer0a[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4749
constexpr uint8_t kKeyBuffer0b[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
4850
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -98,6 +100,20 @@ TEST(TestICDMonitoringTable, TestEntryAssignationOverload)
98100
EXPECT_TRUE(entry2.IsKeyEquivalent(ByteSpan(kKeyBuffer1a)));
99101
}
100102

103+
TEST(TestICDMonitoringTable, TestEntryMaximumSize)
104+
{
105+
TestPersistentStorageDelegate storage;
106+
TestSessionKeystoreImpl keystore;
107+
ICDMonitoringTable table(storage, kTestFabricIndex1, kMaxTestClients1, &keystore);
108+
109+
ICDMonitoringEntry entry(&keystore);
110+
entry.checkInNodeID = kClientNodeMaxValue;
111+
entry.monitoredSubject = kClientNodeMaxValue;
112+
entry.clientType = ClientTypeEnum::kPermanent;
113+
EXPECT_EQ(CHIP_NO_ERROR, entry.SetKey(ByteSpan(kKeyBuffer1a)));
114+
EXPECT_EQ(CHIP_NO_ERROR, table.Set(0, entry));
115+
}
116+
101117
TEST(TestICDMonitoringTable, TestEntryKeyFunctions)
102118
{
103119
TestSessionKeystoreImpl keystore;

0 commit comments

Comments
 (0)