From nobody Tue Dec 03 20:04:59 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Y2s7v44XNz5ggZH; Tue, 03 Dec 2024 20:04:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y2s7v38Pbz4lMw; Tue, 3 Dec 2024 20:04:59 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iszp/pnXpDL4oUFHNyNeflGX32NNgG9nvmLWqpg4rJM=; b=MJkigEkTbi+O8FmciXKVBRLdi/riUR8lgYHkWp1GtSA9WAEtjjaX2xz9fp07PO0NbH3UWQ fA3D7C9ABRpggFMvChmfyb3uiwAhvwwDeqSP7x67ie81usy8HGHdmeobEjnehdO/P/AVpS NFoulrr67Sq46WdZLa7j+E064QtSjSiJLjMASoGGhtaFx/jK7yUErNXKm92zUGgJq8DJX7 B0uwsbfeWTzNYMb8Crb7quUZ357VcZIvfngfnfYFpsQLFTWQUD2beAFKybQ7nW3ioZSJdv 3Ti36wGiHlA8DlSQ6yInNGBMKfZPObbPbOUQ6ZeWjlqJ4VSlbE/avdAqejy7fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733256299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iszp/pnXpDL4oUFHNyNeflGX32NNgG9nvmLWqpg4rJM=; b=r/BKKJ1oQdw/ptfK2v9qTP084SVqMH9XFF8tqvYdz4sIjMIAMHt+Hhdb6PB5k3nHC9WPdK gAwbFyLMkUUQRcmh5Xfiitf/5bs80dPx64GBZInun2obCmgnXH19sZYcQ3EA3/fFfWr9nk mRvdkmd86+Z64BQ4Uh2XDNJUQwdmUvIfUANGEZzcg7GcaCQJ/sYvgWCkb+jytwpWC9MqdQ +tV6dcHKGdpIJogjZnbkTAO35kJJ/tzsQMAHg3vdtfEJo1km9iYCVy1s3+jto84hzmNxmv OYviiKe30Q7IrSH9XKFX5+tq+7OGQSMZ8TjYiKsoZ5PW0JccnFfebdF1Ql1UuA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733256299; a=rsa-sha256; cv=none; b=C5Ez4EfMahyxa1pHuuCzLWIEqS0qn5TIo8MXSiWp3KO1wJ6s/vwpn5gghNl/7+HDfqQs9Q S8rDr7iqtHlMCtcaW5E5ymbHFbxXgFqlnvd2SRQ2OuQqox/SELcoJ96H8YltvBvH5HKr68 4fe29d+9gGeh3aWJ++63NxX059xBy3W053vAYsqX1SN5LO9vgCq7UMm8BCMF28Oic9AzAl REvDfZRHkq7imqd/+84dvgf9rfZs60G+r49v1Kk/wUKpkmnzCNpNBo6Liua/qW/CsGWRvi CZeJo0yLzDY8UbpIetciRNpmMx3qJgoArlbMxUvsg4p/WSfvU4CBtWCLo45iRA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Y2s7v2mHyzcLm; Tue, 3 Dec 2024 20:04:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4B3K4xDf061726; Tue, 3 Dec 2024 20:04:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4B3K4xH8061723; Tue, 3 Dec 2024 20:04:59 GMT (envelope-from git) Date: Tue, 3 Dec 2024 20:04:59 GMT Message-Id: <202412032004.4B3K4xH8061723@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: f1c6edba885f - main - netlink: use size_t through the allocation KPI List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f1c6edba885fa53cc87f7252ab09d36ec1984697 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f1c6edba885fa53cc87f7252ab09d36ec1984697 commit f1c6edba885fa53cc87f7252ab09d36ec1984697 Author: Gleb Smirnoff AuthorDate: 2024-12-03 20:04:27 +0000 Commit: Gleb Smirnoff CommitDate: 2024-12-03 20:04:27 +0000 netlink: use size_t through the allocation KPI This fixes some signedness bugs and potential underflows. The length of nl_buf is still limited by UINT_MAX and this is asserted now. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D47551 --- sys/netlink/ktest_netlink_message_writer.h | 4 ++-- sys/netlink/netlink_domain.c | 2 +- sys/netlink/netlink_glue.c | 5 +++-- sys/netlink/netlink_message_writer.c | 14 +++++++------- sys/netlink/netlink_message_writer.h | 14 +++++++------- sys/netlink/netlink_var.h | 2 +- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/sys/netlink/ktest_netlink_message_writer.h b/sys/netlink/ktest_netlink_message_writer.h index 39d2c5e597d6..447593e0e700 100644 --- a/sys/netlink/ktest_netlink_message_writer.h +++ b/sys/netlink/ktest_netlink_message_writer.h @@ -30,12 +30,12 @@ #if defined(_KERNEL) && defined(INVARIANTS) -bool nlmsg_get_buf_wrapper(struct nl_writer *nw, u_int size, bool waitok); +bool nlmsg_get_buf_wrapper(struct nl_writer *nw, size_t size, bool waitok); #ifndef KTEST_CALLER bool -nlmsg_get_buf_wrapper(struct nl_writer *nw, u_int size, bool waitok) +nlmsg_get_buf_wrapper(struct nl_writer *nw, size_t size, bool waitok) { return (nlmsg_get_buf(nw, size, waitok)); } diff --git a/sys/netlink/netlink_domain.c b/sys/netlink/netlink_domain.c index 67ca16d59009..922da32bfb6d 100644 --- a/sys/netlink/netlink_domain.c +++ b/sys/netlink/netlink_domain.c @@ -566,7 +566,7 @@ nl_sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct nlpcb *nlp = sotonlpcb(so); struct sockbuf *sb = &so->so_snd; struct nl_buf *nb; - u_int len; + size_t len; int error; MPASS(m == NULL && uio != NULL); diff --git a/sys/netlink/netlink_glue.c b/sys/netlink/netlink_glue.c index efb99a717b89..e550a6013654 100644 --- a/sys/netlink/netlink_glue.c +++ b/sys/netlink/netlink_glue.c @@ -135,7 +135,8 @@ nlmsg_ignore_limit_stub(struct nl_writer *nw __unused) } static bool -nlmsg_refill_buffer_stub(struct nl_writer *nw __unused, int required_len __unused) +nlmsg_refill_buffer_stub(struct nl_writer *nw __unused, + size_t required_len __unused) { return (false); } @@ -237,7 +238,7 @@ void nlmsg_ignore_limit(struct nl_writer *nw) } bool -nlmsg_refill_buffer(struct nl_writer *nw, int required_len) +nlmsg_refill_buffer(struct nl_writer *nw, size_t required_len) { return (_nl->nlmsg_refill_buffer(nw, required_len)); } diff --git a/sys/netlink/netlink_message_writer.c b/sys/netlink/netlink_message_writer.c index ee1dab42da74..092e3798f8e7 100644 --- a/sys/netlink/netlink_message_writer.c +++ b/sys/netlink/netlink_message_writer.c @@ -45,13 +45,13 @@ _DECLARE_DEBUG(LOG_INFO); static bool -nlmsg_get_buf(struct nl_writer *nw, u_int len, bool waitok) +nlmsg_get_buf(struct nl_writer *nw, size_t len, bool waitok) { const int mflag = waitok ? M_WAITOK : M_NOWAIT; MPASS(nw->buf == NULL); - NL_LOG(LOG_DEBUG3, "Setting up nw %p len %u %s", nw, len, + NL_LOG(LOG_DEBUG3, "Setting up nw %p len %zu %s", nw, len, waitok ? "wait" : "nowait"); nw->buf = nl_buf_alloc(len, mflag); @@ -139,17 +139,17 @@ _nlmsg_flush(struct nl_writer *nw) * Return true on success. */ bool -_nlmsg_refill_buffer(struct nl_writer *nw, u_int required_len) +_nlmsg_refill_buffer(struct nl_writer *nw, size_t required_len) { struct nl_buf *new; - u_int completed_len, new_len, last_len; + size_t completed_len, new_len, last_len; MPASS(nw->buf != NULL); if (nw->enomem) return (false); - NL_LOG(LOG_DEBUG3, "no space at offset %u/%u (want %u), trying to " + NL_LOG(LOG_DEBUG3, "no space at offset %u/%u (want %zu), trying to " "reclaim", nw->buf->datalen, nw->buf->buflen, required_len); /* Calculate new buffer size and allocate it. */ @@ -182,7 +182,7 @@ _nlmsg_refill_buffer(struct nl_writer *nw, u_int required_len) new->datalen = last_len; } - NL_LOG(LOG_DEBUG2, "completed: %u bytes, copied: %u bytes", + NL_LOG(LOG_DEBUG2, "completed: %zu bytes, copied: %zu bytes", completed_len, last_len); if (completed_len > 0) { @@ -204,7 +204,7 @@ _nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, { struct nl_buf *nb = nw->buf; struct nlmsghdr *hdr; - u_int required_len; + size_t required_len; MPASS(nw->hdr == NULL); diff --git a/sys/netlink/netlink_message_writer.h b/sys/netlink/netlink_message_writer.h index 8cf6951df40c..9469883feaa7 100644 --- a/sys/netlink/netlink_message_writer.h +++ b/sys/netlink/netlink_message_writer.h @@ -71,9 +71,9 @@ bool _nl_writer_group(struct nl_writer *, size_t, uint16_t, uint16_t, bool); bool _nlmsg_flush(struct nl_writer *nw); void _nlmsg_ignore_limit(struct nl_writer *nw); -bool _nlmsg_refill_buffer(struct nl_writer *nw, u_int required_len); -bool _nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, - uint16_t flags, uint32_t len); +bool _nlmsg_refill_buffer(struct nl_writer *nw, size_t required_len); +bool _nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, + uint16_t type, uint16_t flags, uint32_t len); bool _nlmsg_end(struct nl_writer *nw); void _nlmsg_abort(struct nl_writer *nw); @@ -107,7 +107,7 @@ nlmsg_ignore_limit(struct nl_writer *nw) } static inline bool -nlmsg_refill_buffer(struct nl_writer *nw, int required_size) +nlmsg_refill_buffer(struct nl_writer *nw, size_t required_size) { return (_nlmsg_refill_buffer(nw, required_size)); } @@ -146,9 +146,9 @@ bool nl_writer_group(struct nl_writer *, size_t, uint16_t, uint16_t, bool nlmsg_flush(struct nl_writer *nw); void nlmsg_ignore_limit(struct nl_writer *nw); -bool nlmsg_refill_buffer(struct nl_writer *nw, int required_size); -bool nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, - uint16_t flags, uint32_t len); +bool nlmsg_refill_buffer(struct nl_writer *nw, size_t required_size); +bool nlmsg_add(struct nl_writer *nw, uint32_t portid, uint32_t seq, + uint16_t type, uint16_t flags, uint32_t len); bool nlmsg_end(struct nl_writer *nw); void nlmsg_abort(struct nl_writer *nw); diff --git a/sys/netlink/netlink_var.h b/sys/netlink/netlink_var.h index c09e279205f0..8efe84e935c3 100644 --- a/sys/netlink/netlink_var.h +++ b/sys/netlink/netlink_var.h @@ -179,7 +179,7 @@ struct nl_pstate; struct nl_function_wrapper { bool (*nlmsg_add)(struct nl_writer *nw, uint32_t portid, uint32_t seq, uint16_t type, uint16_t flags, uint32_t len); - bool (*nlmsg_refill_buffer)(struct nl_writer *nw, int required_len); + bool (*nlmsg_refill_buffer)(struct nl_writer *nw, size_t required_len); bool (*nlmsg_flush)(struct nl_writer *nw); bool (*nlmsg_end)(struct nl_writer *nw); void (*nlmsg_abort)(struct nl_writer *nw);