net: pkt: Fix fixed buffer allocation with headroom bug

The size calculation for the first buffer, in case extra headroom is
requested, had a bug which could result in a size variable underflow
followed by net_buf exhaustion.

In case the net_buf size was larger than requested size, but smaller
than requested size + headroom, the whole buffer size was subtracted
from the requested size. This however did not take the extra headroom
into account and in effect could result in underflow.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2025-01-21 14:48:50 +01:00 committed by Benjamin Cabé
parent 14a00f259f
commit ea191bddaf

View file

@ -970,7 +970,7 @@ static struct net_buf *pkt_alloc_buffer(struct net_pkt *pkt,
size = 0U; size = 0U;
} else { } else {
size -= current->size; size -= current->size - headroom;
} }
} else { } else {
if (current->size > size) { if (current->size > size) {