From nobody Wed Dec 27 21:06:17 2023 X-Original-To: dev-commits-src-all@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 4T0khV4xPQz56KLY; Wed, 27 Dec 2023 21:06:18 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4T0khV00jDz4Z3P; Wed, 27 Dec 2023 21:06:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703711178; 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=1UXOfmRX4jiSe4JYeOzft46ZD75CKYzcqo/6h+CXyF0=; b=HTfhWUFfV8mRwFa3Kw/aeayKgj205B+8H/oRP9MpG/oyWm0KmRy1Qcsv/AAhTthiAD8dr4 2CqtyWQInqth4yraWEC8Tm+j+g3yOzTiqFEquqZJN2PkRYnV9nIr3hrS90PLph10XcedYG KJLH3J5pkNTNLC1Cv03gSQcSUloIBzWOW8tgrtu92CAIll0huoTupw3KprmC1oORC1VnHl tReBGs0u6qi/Y+/wjD9h6L7/7HuV5G6UcSyA52epEvQ1YFmrhdyRP5kKhCzWY10Nl17xb1 D9cyjjuZeuR0RieNRtzAXX6IZXRb+kv5vR2eJ2P4rl1OTtCsnVIQ1bYFW6nQsg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703711178; a=rsa-sha256; cv=none; b=WBmt8/hl+dUaPd38WuHfmt2YMtcaaKXSrBEKLtlrnT8anTi62F6VQRGA2kBX0bwzBebhGH JmQxZYTDiduOD9Io1uPYZriT7wYTqYj8mzbBZuZDBdUVNAVz68JPv/V2V3HL0VSSyviP5v tDgDY3rp1KE+6QybpLgG+KpG9VxLc9qyESW4cy375eWIiIOwmQhLObs1OhGef7PzzQzrWM ax2rFDXFIYTffeq6Kb/69BsaMaXOlWFuAZu6IGS9EFnQChhknQrH8DVbuEPn+MqIZjCfLh 4n95VUOO3Mny9Q2JF+RGcaar/IFV8hl1iwbhU44Q5Ifm+27VHHBisUp+qZyeag== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703711178; 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=1UXOfmRX4jiSe4JYeOzft46ZD75CKYzcqo/6h+CXyF0=; b=tBk8IKXbiCVkww/DvDLw13opCmiRjkJFJyHpODdc/WHr310JLt+kYN5btDsaWBE0xtWxHY FD6oc0gIblQvI0aMldWLuMMCJELTLkbCAlFZoo50r4cUXUKqAl+Lc7iHKAxzPtE2A6Do+O peL5fO2uwEZg6S1JOi7BGVxr1uCLlV+ee25pygbPfa4qkUMeRRE6T6VWJfZa6tf2AvTj4P rARG/NxxoOdc7jlV+5t4f518VIESm7o8G3t3Tv6Gvy7tyICP+3cj6LJJPesfuJgqU5evq7 7Y/vX7V3jJL/I/gmYMqH+QenkGHw3LyhRkdRNIlzCoQGPtnDXk9WQcTTzj/wGw== 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 4T0khT6BJwztwv; Wed, 27 Dec 2023 21:06:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BRL6H94036394; Wed, 27 Dec 2023 21:06:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BRL6Hf4036391; Wed, 27 Dec 2023 21:06:17 GMT (envelope-from git) Date: Wed, 27 Dec 2023 21:06:17 GMT Message-Id: <202312272106.3BRL6Hf4036391@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: c92ac2c311c6 - stable/13 - netlink: fix snl_writer and linear_buffer re-allocation logic List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: c92ac2c311c6fe18d57dd4395c75686f0e053a87 Auto-Submitted: auto-generated The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c92ac2c311c6fe18d57dd4395c75686f0e053a87 commit c92ac2c311c6fe18d57dd4395c75686f0e053a87 Author: Igor Ostapenko AuthorDate: 2023-12-12 18:26:21 +0000 Commit: Kristof Provost CommitDate: 2023-12-27 20:53:21 +0000 netlink: fix snl_writer and linear_buffer re-allocation logic - Use the correct base pointer after re-allocation to avoid buffer overflows. - Maintain correct snl_writer.size, which avoids redundant memory allocation, e.g. a need for ~1k bytes may end up with ~32k linear_buffer actually allocated. This fixes a pfctl regression at least for armv7 after the addrule logic migration to netlink: ffbf25951e7b ("pf: convert rule addition to netlink") The add rule command creates a bigger than default size netlink requests which triggers the re-allocation logic. Reviewed by: kp MFC after: 2 weeks Differnetial Revision: https://reviews.freebsd.org/D43003 (cherry picked from commit 0c511bafdd5b309505c13c8dc7c6816686d1e103) --- sys/netlink/netlink_snl.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 78d0f75333e3..8c31c5d31671 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -714,18 +714,23 @@ snl_realloc_msg_buffer(struct snl_writer *nw, size_t sz) if (nw->error) return (false); - void *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; - 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); + 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->base = new_base; } - nw->base = new_base; return (true); }