Skip to content

Commit 84e9b07

Browse files
authored
[fdborch] fix heap-use-after-free in clearFdbEntry() (#2353)
- What I did using a copy of FDBEntry fields (stored in FDBUpdate) instead of a reference since the reference gets invalidated in the storeFdbEntryState() simplified clearFdbEntry() interface - Why I did it To fix the memory usage issue The issue is that the SWSS_LOG_INFO() uses the mac&, port_alias&, and bv_id& which are invalidated in the storeFdbEntryState(). - How I verified it Run the tests that were used to find the issues and checked the ASAN report Signed-off-by: Yakiv Huryk <[email protected]>
1 parent 1b8bd94 commit 84e9b07

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

orchagent/fdborch.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -177,31 +177,28 @@ bool FdbOrch::storeFdbEntryState(const FdbUpdate& update)
177177
/*
178178
clears stateDb and decrements corresponding internal fdb counters
179179
*/
180-
void FdbOrch::clearFdbEntry(const MacAddress& mac,
181-
const sai_object_id_t& bv_id,
182-
const string& port_alias)
180+
void FdbOrch::clearFdbEntry(const FdbEntry& entry)
183181
{
184182
FdbUpdate update;
185-
update.entry.mac = mac;
186-
update.entry.bv_id = bv_id;
183+
update.entry = entry;
187184
update.add = false;
188185

189186
/* Fetch Vlan and decrement the counter */
190187
Port temp_vlan;
191-
if (m_portsOrch->getPort(bv_id, temp_vlan))
188+
if (m_portsOrch->getPort(entry.bv_id, temp_vlan))
192189
{
193190
m_portsOrch->decrFdbCount(temp_vlan.m_alias, 1);
194191
}
195192

196193
/* Decrement port fdb_counter */
197-
m_portsOrch->decrFdbCount(port_alias, 1);
194+
m_portsOrch->decrFdbCount(entry.port_name, 1);
198195

199196
/* Remove the FdbEntry from the internal cache, update state DB and CRM counter */
200197
storeFdbEntryState(update);
201198
notify(SUBJECT_TYPE_FDB_CHANGE, &update);
202199

203200
SWSS_LOG_INFO("FdbEntry removed from internal cache, MAC: %s , port: %s, BVID: 0x%" PRIx64,
204-
mac.to_string().c_str(), port_alias.c_str(), bv_id);
201+
update.entry.mac.to_string().c_str(), update.entry.port_name.c_str(), update.entry.bv_id);
205202
}
206203

207204
/*
@@ -224,7 +221,7 @@ void FdbOrch::handleSyncdFlushNotif(const sai_object_id_t& bv_id,
224221
auto curr = itr++;
225222
if (curr->second.type != "static" && (curr->first.mac == mac || mac == flush_mac))
226223
{
227-
clearFdbEntry(curr->first.mac, curr->first.bv_id, curr->first.port_name);
224+
clearFdbEntry(curr->first);
228225
}
229226
}
230227
}
@@ -238,7 +235,7 @@ void FdbOrch::handleSyncdFlushNotif(const sai_object_id_t& bv_id,
238235
{
239236
if (curr->second.type != "static" && (curr->first.mac == mac || mac == flush_mac))
240237
{
241-
clearFdbEntry(curr->first.mac, curr->first.bv_id, curr->first.port_name);
238+
clearFdbEntry(curr->first);
242239
}
243240
}
244241
}
@@ -253,7 +250,7 @@ void FdbOrch::handleSyncdFlushNotif(const sai_object_id_t& bv_id,
253250
{
254251
if (curr->second.type != "static" && (curr->first.mac == mac || mac == flush_mac))
255252
{
256-
clearFdbEntry(curr->first.mac, curr->first.bv_id, curr->first.port_name);
253+
clearFdbEntry(curr->first);
257254
}
258255
}
259256
}
@@ -268,7 +265,7 @@ void FdbOrch::handleSyncdFlushNotif(const sai_object_id_t& bv_id,
268265
{
269266
if (curr->second.type != "static" && (curr->first.mac == mac || mac == flush_mac))
270267
{
271-
clearFdbEntry(curr->first.mac, curr->first.bv_id, curr->first.port_name);
268+
clearFdbEntry(curr->first);
272269
}
273270
}
274271
}

orchagent/fdborch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class FdbOrch: public Orch, public Subject, public Observer
123123
bool storeFdbEntryState(const FdbUpdate& update);
124124
void notifyTunnelOrch(Port& port);
125125

126-
void clearFdbEntry(const MacAddress&, const sai_object_id_t&, const string&);
126+
void clearFdbEntry(const FdbEntry&);
127127
void handleSyncdFlushNotif(const sai_object_id_t&, const sai_object_id_t&, const MacAddress& );
128128
};
129129

0 commit comments

Comments
 (0)