netmap: Use ckdint.h helpers to check for overflow

This addresses a bug in the addition overflow check added in commit
319414a926 ("netmap: Handle overflow when computing ring sizes"): that
overflow wasn't actually caught by the check because "len" is promoted
to size_t.

PR:		297300
Fixes:		319414a926 ("netmap: Handle overflow when computing ring sizes")
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D58896
This commit is contained in:
Mark Johnston committed 2026-08-27 13:33:10 +00:00
1 parent 00a793def7
commit d6f5c6531e
1 file changed
+3 -7
+3 -7
View File
@@ -38,6 +38,7 @@
#ifdef __FreeBSD__
#include <sys/types.h>
#include <sys/ckdint.h>
#include <sys/domainset.h>
#include <sys/limits.h>
#include <sys/malloc.h>
@@ -2013,16 +2014,11 @@ netmap_mem2_rings_create(struct netmap_mem_d *nmd, struct netmap_adapter *na)
if (netmap_debug & NM_DEBUG_MEM)
nm_prinf("creating %s", kring->name);
ndesc = kring->nkr_num_slots;
if (ndesc >= UINT_MAX / sizeof(struct netmap_slot)) {
if (ckd_mul(&len, ndesc, sizeof(struct netmap_slot)) ||
ckd_add(&len, len, sizeof(struct netmap_ring))) {
error = EINVAL;
goto cleanup;
}
len = ndesc * sizeof(struct netmap_slot);
if (len + sizeof(struct netmap_ring) < len) {
error = EINVAL;
goto cleanup;
}
len += sizeof(struct netmap_ring);
ring = netmap_ring_malloc(nmd, len);
if (ring == NULL) {
nm_prerr("Cannot allocate %s_ring", nm_txrx2str(t));