git: 0601c0f989f2 - main - netlink: check buffer length fits into u_int

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Tue, 03 Dec 2024 20:04:58 UTC
The branch main has been updated by glebius:

URL: https://cgit.FreeBSD.org/src/commit/?id=0601c0f989f21a935d49818d67e732766ddc3f77

commit 0601c0f989f21a935d49818d67e732766ddc3f77
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-12-03 20:04:22 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-12-03 20:04:22 +0000

    netlink: check buffer length fits into u_int
    
    We may increase it to size_t later, KPI allows that already, but
    doesn't seem to be needed today.
    
    Reviewed by:            melifaro
    Differential Revision:  https://reviews.freebsd.org/D47550
---
 sys/netlink/netlink_io.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sys/netlink/netlink_io.c b/sys/netlink/netlink_io.c
index bc8d2f9fcc3f..d2022a6a2b0d 100644
--- a/sys/netlink/netlink_io.c
+++ b/sys/netlink/netlink_io.c
@@ -58,6 +58,9 @@ nl_buf_alloc(size_t len, int mflag)
 {
 	struct nl_buf *nb;
 
+	KASSERT(len > 0 && len <= UINT_MAX, ("%s: invalid length %zu",
+	    __func__, len));
+
 	nb = malloc(sizeof(struct nl_buf) + len, M_NETLINK, mflag);
 	if (__predict_true(nb != NULL)) {
 		nb->buflen = len;