Date: Tue, 09 Dec 2025 19:59:12 +0000 From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 12165ac8407c - main - Revert "netlink: Fix overallocation of netlink message buffers" Message-ID: <69387f90.2e589.323f82c3@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=12165ac8407cef2c0b96035a1a956e3a7fe48cec commit 12165ac8407cef2c0b96035a1a956e3a7fe48cec Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-12-09 19:55:46 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-12-09 19:55:46 +0000 Revert "netlink: Fix overallocation of netlink message buffers" This patch was based on an incorrect assumption that the linear buffer chain for an snl_writer only contained the netlink message body. This reverts commit 828df4d36d9d5a6ca0dcc294d65572b4a0474142. Sponsored by: AFRL, DARPA --- sys/netlink/netlink_snl.h | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 1e560e029718..57f7e1e29d08 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -1082,7 +1082,6 @@ snl_init_writer(struct snl_state *ss, struct snl_writer *nw) static inline bool snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz) { - void *new_base; uint32_t new_size = nw->size * 2; while (new_size < nw->size + sz) @@ -1091,27 +1090,23 @@ snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz) if (nw->error) return (false); - new_base = snl_allocz(nw->ss, new_size); - if (new_base == NULL) { + if (snl_allocz(nw->ss, new_size) == NULL) { nw->error = true; return (false); } + nw->size = new_size; - if (new_base == nw->ss->lb->base) { - /* Claim the entire linear buffer. */ - nw->size = nw->ss->lb->size; - nw->ss->lb->offset = nw->ss->lb->size; - } else - nw->size = new_size; - - memcpy(new_base, nw->base, nw->offset); - if (nw->hdr != NULL) { - int hdr_off = (char *)(nw->hdr) - nw->base; + void *new_base = nw->ss->lb->base; + if (new_base != nw->base) { + memcpy(new_base, nw->base, nw->offset); + if (nw->hdr != NULL) { + int hdr_off = (char *)(nw->hdr) - nw->base; - nw->hdr = (struct nlmsghdr *) - (void *)((char *)new_base + hdr_off); + nw->hdr = (struct nlmsghdr *) + (void *)((char *)new_base + hdr_off); + } + nw->base = (char *)new_base; } - nw->base = (char *)new_base; return (true); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69387f90.2e589.323f82c3>
