Skip to content

Commit 1af2b91

Browse files
cvinayaknashif
authored andcommitted
Bluetooth: controller: Fix Tx Buffer Overflow
Fix Tx Buffer Overflow caused by uninitialized node_tx memory being used by ULL ISR context due to Compiler Instructions Reordering in the use of MFIFO_ENQUEUE. The MFIFO last index was committed before the data element was stored in the MFIFO due to Compiler Instructions Reordering. This is fixed now by adding a Data Memory Barrier instruction alongwith a compiler memory clobber. Fixes #30378. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
1 parent 1a14f8b commit 1af2b91

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99
#include <stddef.h>
1010

1111
#include <toolchain.h>
12+
#include <soc.h>
1213

1314
#include <sys/util.h>
1415

16+
#include "hal/cpu.h"
17+
#include "hal/ccm.h"
18+
#include "hal/radio.h"
19+
1520
#include "util/mem.h"
1621
#include "util/memq.h"
1722
#include "util/mfifo.h"
1823

19-
#include "hal/ccm.h"
20-
#include "hal/radio.h"
21-
2224
#include "pdu.h"
2325

2426
#include "lll.h"
@@ -32,7 +34,6 @@
3234
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
3335
#define LOG_MODULE_NAME bt_ctlr_lll_conn
3436
#include "common/log.h"
35-
#include <soc.h>
3637
#include "hal/debug.h"
3738

3839
static int init_reset(void);

subsys/bluetooth/controller/ll_sw/ull_conn.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
#include <stddef.h>
88
#include <zephyr.h>
9+
#include <soc.h>
910
#include <device.h>
1011
#include <bluetooth/bluetooth.h>
1112
#include <sys/byteorder.h>
1213

14+
#include "hal/cpu.h"
1315
#include "hal/ecb.h"
1416
#include "hal/ccm.h"
1517
#include "hal/ticker.h"
@@ -44,7 +46,6 @@
4446
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
4547
#define LOG_MODULE_NAME bt_ctlr_ull_conn
4648
#include "common/log.h"
47-
#include <soc.h>
4849
#include "hal/debug.h"
4950

5051
#if defined(CONFIG_BT_CTLR_USER_EXT)

subsys/bluetooth/controller/util/memq.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@
3232
* where A[b] means the A'th link-element, whose mem pointer is b.
3333
*/
3434

35-
#include <zephyr/types.h>
3635
#include <stddef.h>
3736

37+
#include <soc.h>
38+
39+
#include "hal/cpu.h"
40+
3841
#include "memq.h"
3942

4043
/**
@@ -97,7 +100,8 @@ memq_link_t *memq_enqueue(memq_link_t *link, void *mem, memq_link_t **tail)
97100
/* Update the tail-pointer to point to the new tail element.
98101
* The new tail-element is not expected to point to anything sensible
99102
*/
100-
*tail = link;
103+
cpu_dmb(); /* Ensure data accesses are synchronized */
104+
*tail = link; /* Commit: enqueue of memq node */
101105

102106
return link;
103107
}

subsys/bluetooth/controller/util/mfifo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ static inline void mfifo_by_idx_enqueue(uint8_t *fifo, uint8_t size, uint8_t idx
123123
void **p = (void **)(fifo + (*last) * size); /* buffer preceding idx */
124124
*p = mem; /* store the payload which for API 2 is only a void-ptr */
125125

126+
cpu_dmb(); /* Ensure data accesses are synchronized */
126127
*last = idx; /* Commit: Update write index */
127128
}
128129

@@ -189,6 +190,7 @@ static inline uint8_t mfifo_enqueue_get(uint8_t *fifo, uint8_t size, uint8_t cou
189190
*/
190191
static inline void mfifo_enqueue(uint8_t idx, uint8_t *last)
191192
{
193+
cpu_dmb(); /* Ensure data accesses are synchronized */
192194
*last = idx; /* Commit: Update write index */
193195
}
194196

0 commit comments

Comments
 (0)