Skip to content

Commit 62ed153

Browse files
Florian Grandelcarlescufi
authored andcommitted
drivers: ieee802154: don't allocate rx pkt from tx pool
Several IEEE 802154 drivers allocated RX packets from the TX pool. This may seem like a minor problem at first sight but it may become problematic if the pool is used to distinguish package types as is the case in some code paths, e.g. for packet priority or determination of the packet buffer pool. This bug also has the potential of starving the TX pool capacity which even may make devices vulnerable to DoS attacks as sending may be prohibited by addressing enough RX packets to a device to let it run out of TX capacity. Fixes: #51261 Signed-off-by: Florian Grandel <[email protected]>
1 parent 5bc6b15 commit 62ed153

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

drivers/ieee802154/ieee802154_b91.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ static void b91_handle_ack(void)
206206
struct net_pkt *ack_pkt;
207207

208208
/* allocate ack packet */
209-
ack_pkt = net_pkt_alloc_with_buffer(data.iface, B91_ACK_FRAME_LEN,
210-
AF_UNSPEC, 0, K_NO_WAIT);
209+
ack_pkt = net_pkt_rx_alloc_with_buffer(data.iface, B91_ACK_FRAME_LEN,
210+
AF_UNSPEC, 0, K_NO_WAIT);
211211
if (!ack_pkt) {
212212
LOG_ERR("No free packet available.");
213213
return;
@@ -301,7 +301,7 @@ static void b91_rf_rx_isr(void)
301301
}
302302

303303
/* get packet pointer from NET stack */
304-
pkt = net_pkt_alloc_with_buffer(data.iface, length, AF_UNSPEC, 0, K_NO_WAIT);
304+
pkt = net_pkt_rx_alloc_with_buffer(data.iface, length, AF_UNSPEC, 0, K_NO_WAIT);
305305
if (!pkt) {
306306
LOG_ERR("No pkt available");
307307
goto exit;

drivers/ieee802154/ieee802154_cc1200.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ static void cc1200_rx(void *arg)
466466
goto flush;
467467
}
468468

469-
pkt = net_pkt_alloc_with_buffer(cc1200->iface, pkt_len,
470-
AF_UNSPEC, 0, K_NO_WAIT);
469+
pkt = net_pkt_rx_alloc_with_buffer(cc1200->iface, pkt_len,
470+
AF_UNSPEC, 0, K_NO_WAIT);
471471
if (!pkt) {
472472
LOG_ERR("No free pkt available");
473473
goto flush;

drivers/ieee802154/ieee802154_cc2520.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,8 @@ static void cc2520_rx(void *arg)
616616
goto flush;
617617
}
618618

619-
pkt = net_pkt_alloc_with_buffer(cc2520->iface, pkt_len,
620-
AF_UNSPEC, 0, K_NO_WAIT);
619+
pkt = net_pkt_rx_alloc_with_buffer(cc2520->iface, pkt_len,
620+
AF_UNSPEC, 0, K_NO_WAIT);
621621
if (!pkt) {
622622
LOG_ERR("No pkt available");
623623
goto flush;

drivers/ieee802154/ieee802154_dw1000.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ static inline void dwt_irq_handle_rx(const struct device *dev, uint32_t sys_stat
420420
pkt_len -= DWT_FCS_LENGTH;
421421
}
422422

423-
pkt = net_pkt_alloc_with_buffer(ctx->iface, pkt_len,
424-
AF_UNSPEC, 0, K_NO_WAIT);
423+
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len,
424+
AF_UNSPEC, 0, K_NO_WAIT);
425425
if (!pkt) {
426426
LOG_ERR("No buf available");
427427
goto rx_out_enable_rx;

drivers/ieee802154/ieee802154_kw41z.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ static inline void kw41z_rx(struct kw41z_context *kw41z, uint8_t len)
514514
pkt_len = len - KW41Z_FCS_LENGTH;
515515
#endif
516516

517-
pkt = net_pkt_alloc_with_buffer(kw41z->iface, pkt_len,
518-
AF_UNSPEC, 0, K_NO_WAIT);
517+
pkt = net_pkt_rx_alloc_with_buffer(kw41z->iface, pkt_len,
518+
AF_UNSPEC, 0, K_NO_WAIT);
519519
if (!pkt) {
520520
LOG_ERR("No buf available");
521521
goto out;
@@ -582,8 +582,8 @@ static void handle_ack(struct kw41z_context *kw41z, uint8_t seq_number)
582582
struct net_pkt *ack_pkt;
583583
uint8_t ack_psdu[ACK_FRAME_LEN];
584584

585-
ack_pkt = net_pkt_alloc_with_buffer(kw41z->iface, ACK_FRAME_LEN,
586-
AF_UNSPEC, 0, K_NO_WAIT);
585+
ack_pkt = net_pkt_rx_alloc_with_buffer(kw41z->iface, ACK_FRAME_LEN,
586+
AF_UNSPEC, 0, K_NO_WAIT);
587587
if (!ack_pkt) {
588588
LOG_ERR("No free packet available.");
589589
return;

drivers/ieee802154/ieee802154_mcr20a.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ static inline void mcr20a_rx(const struct device *dev, uint8_t len)
557557

558558
pkt_len = len - MCR20A_FCS_LENGTH;
559559

560-
pkt = net_pkt_alloc_with_buffer(mcr20a->iface, pkt_len,
561-
AF_UNSPEC, 0, K_NO_WAIT);
560+
pkt = net_pkt_rx_alloc_with_buffer(mcr20a->iface, pkt_len,
561+
AF_UNSPEC, 0, K_NO_WAIT);
562562
if (!pkt) {
563563
LOG_ERR("No buf available");
564564
goto out;

drivers/ieee802154/ieee802154_nrf5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ static int handle_ack(struct nrf5_802154_data *nrf5_radio)
380380
ack_len = nrf5_radio->ack_frame.psdu[0] - NRF5_FCS_LENGTH;
381381
}
382382

383-
ack_pkt = net_pkt_alloc_with_buffer(nrf5_radio->iface, ack_len,
384-
AF_UNSPEC, 0, K_NO_WAIT);
383+
ack_pkt = net_pkt_rx_alloc_with_buffer(nrf5_radio->iface, ack_len,
384+
AF_UNSPEC, 0, K_NO_WAIT);
385385
if (!ack_pkt) {
386386
LOG_ERR("No free packet available.");
387387
err = -ENOMEM;

drivers/ieee802154/ieee802154_rf2xx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ static void rf2xx_trx_rx(const struct device *dev)
165165

166166
/*
167167
* The rf2xx frame buffer can have length > 128 bytes. The
168-
* net_pkt_alloc_with_buffer allocates max value of 128 bytes.
168+
* net_pkt_rx_alloc_with_buffer allocates max value of 128 bytes.
169169
*
170170
* This obligate the driver to have rx_buf statically allocated with
171171
* RX2XX_MAX_FRAME_SIZE.
@@ -204,8 +204,8 @@ static void rf2xx_trx_rx(const struct device *dev)
204204
pkt_len -= RX2XX_FRAME_FCS_LENGTH;
205205
}
206206

207-
pkt = net_pkt_alloc_with_buffer(ctx->iface, pkt_len,
208-
AF_UNSPEC, 0, K_NO_WAIT);
207+
pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, pkt_len,
208+
AF_UNSPEC, 0, K_NO_WAIT);
209209

210210
if (!pkt) {
211211
LOG_ERR("No buf available");

0 commit comments

Comments
 (0)