Skip to content

Commit 1208406

Browse files
omkar3141nordicjm
authored andcommitted
[nrf fromtree] Bluetooth: Mesh: Make net msg cache netkey aware
Improve the network message cache to be aware of network keys to prevent false duplicate detection across different subnets. This ensures that messages with the same source address and sequence number but from different network keys are not incorrectly identified as duplicates, as it can happen in certain cases. See ES-26350. Signed-off-by: Omkar Kulkarni <[email protected]> (cherry picked from commit 22e3798) Signed-off-by: Pavel Vasilyev <[email protected]>
1 parent 7ab8719 commit 1208406

File tree

1 file changed

+10
-7
lines changed
  • subsys/bluetooth/mesh

1 file changed

+10
-7
lines changed

subsys/bluetooth/mesh/net.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ struct iv_val {
8282

8383
static struct {
8484
uint32_t src : 15, /* MSb of source is always 0 */
85-
seq : 17;
85+
seq : 17;
86+
uint16_t net_idx;
8687
} msg_cache[CONFIG_BT_MESH_MSG_CACHE_SIZE];
8788
static uint16_t msg_cache_next;
8889

@@ -145,20 +146,22 @@ static bool check_dup(struct net_buf_simple *data)
145146
return false;
146147
}
147148

148-
static bool msg_cache_match(struct net_buf_simple *pdu)
149+
static bool msg_cache_match(struct net_buf_simple *pdu, uint16_t net_idx)
149150
{
150151
uint16_t i;
151152

152153
for (i = msg_cache_next; i > 0U;) {
153154
if (msg_cache[--i].src == SRC(pdu->data) &&
154-
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) {
155+
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17)) &&
156+
msg_cache[i].net_idx == net_idx) {
155157
return true;
156158
}
157159
}
158160

159161
for (i = ARRAY_SIZE(msg_cache); i > msg_cache_next;) {
160162
if (msg_cache[--i].src == SRC(pdu->data) &&
161-
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) {
163+
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17)) &&
164+
msg_cache[i].net_idx == net_idx) {
162165
return true;
163166
}
164167
}
@@ -171,6 +174,7 @@ static void msg_cache_add(struct bt_mesh_net_rx *rx)
171174
msg_cache_next %= ARRAY_SIZE(msg_cache);
172175
msg_cache[msg_cache_next].src = rx->ctx.addr;
173176
msg_cache[msg_cache_next].seq = rx->seq;
177+
msg_cache[msg_cache_next].net_idx = rx->sub->net_idx;
174178
msg_cache_next++;
175179
}
176180

@@ -653,15 +657,14 @@ static bool net_decrypt(struct bt_mesh_net_rx *rx, struct net_buf_simple *in,
653657
return false;
654658
}
655659

656-
if (rx->net_if == BT_MESH_NET_IF_ADV && msg_cache_match(out)) {
660+
if (rx->net_if == BT_MESH_NET_IF_ADV && msg_cache_match(out, rx->sub->net_idx)) {
657661
LOG_DBG("Duplicate found in Network Message Cache");
658662
return false;
659663
}
660664

661665
LOG_DBG("src 0x%04x", rx->ctx.addr);
662666

663-
return bt_mesh_net_decrypt(&cred->enc, out, BT_MESH_NET_IVI_RX(rx),
664-
proxy) == 0;
667+
return bt_mesh_net_decrypt(&cred->enc, out, BT_MESH_NET_IVI_RX(rx), proxy) == 0;
665668
}
666669

667670
/* Relaying from advertising to the advertising bearer should only happen

0 commit comments

Comments
 (0)