From nobody Wed Dec 27 21:06:17 2023 X-Original-To: dev-commits-src-branches@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 4T0khT5fmMz56KNw; Wed, 27 Dec 2023 21:06:17 +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 4T0khT3m4Rz4Z14; Wed, 27 Dec 2023 21:06:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703711177; 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=C/Ac3IRKWd8YKwqig8S3VyEi2JB/L//bPbcpSnSpH6U=; b=gkoYxDq/mm5aU4YAotx3RbONCzbXS6dGXY+76dfM/oVriNw2c6nDy8EtxXJ/2CDUg8405P UFuRchIdVPApg5oPNFS8n8ARAmZJs8GyByuA1Pyvw84edLQLQdv89GOBltvgzqNU7epj1o GSvPE1Jmxqk4KjNVXDyiI0I7I8nnbPLwsouBvv5t0JaPmpD2efkw6yJofuufbYHeNK47Wg +nMS6qehADSq2BaeiOtzwKXRmUbIr8l3x9JHUutIlpLEYlL0cr01Iiw9mnlgzC0QvE07rI 6b3JvgzQyYWLb+efP/jLR0yuMk2O6Ic+fKqP7nLCOw8eikZMi4IDTIb+r1PLew== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703711177; a=rsa-sha256; cv=none; b=nJlWE5QW/G5/2IKNdTOrxl04F/14WFE9ZPE5qkKdLkXx6iQRp/Y9N2BZIzaRda9Gl57PQl z+GMmhHvdQXzJe5+sWjBpNhyYxZwU+ABpD1mffJBOhKop//Ljm0bVbAUK4zNZih3AH7J/D yJOiLztuvb0w/hyTne9IDv4eXeXC5VopWX4R4TlQQRn4ZfBdctY02c5blsPcoHfv1MjkL3 73X22V0k1Tsce0dW55sAAMTPb1o+HwTwW23AZJgOSrUNOjePz7WAAQV9KDrI/AU21LxZpl AEAou+qHMSdnI2+n5ia0wahCkEbOi3tvVIswHXL5TE9MEbKiCY3RU2bsCmDoKw== 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=1703711177; 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=C/Ac3IRKWd8YKwqig8S3VyEi2JB/L//bPbcpSnSpH6U=; b=YOG2zmYEv1p+cgE1qAARwoyhRb0H3Nswl6zF2d25h22519PxyACLH3TtjqGR1mG6NXB83C 6F5Iv11/VMtE1S60uuGO57DwIMMKqBT20BvZf1QbtasMzx+8XSsKjA/v9YXFokqwHFCZt5 NhZ0hWbu5L0DNRmX9T3HwEWEaolmcnwm4a0GJtpgd5PAIgk6dqa0sgek52IRzWONWhbkiz hCmGyJFvZzXoobE1LgUuW9jkv84VdjILn0TMMAQIfxy5DqIU7aBsgHdEvF90y2wNCFLM/C wHrjtYpjaPmWRnrFIKFsZKiIFPvQ2gDjhP/JmhxotmSNNRLTJjT+1TeR/aRwJw== 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 4T0khT2jXQzv7C; 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 3BRL6Hk5036291; 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 3BRL6Hmt036288; Wed, 27 Dec 2023 21:06:17 GMT (envelope-from git) Date: Wed, 27 Dec 2023 21:06:17 GMT Message-Id: <202312272106.3BRL6Hmt036288@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: 18fb9174cda5 - stable/14 - netlink: fix snl_writer and linear_buffer re-allocation logic List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 18fb9174cda527f107c072fb87aef72be4939da7 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=18fb9174cda527f107c072fb87aef72be4939da7 commit 18fb9174cda527f107c072fb87aef72be4939da7 Author: Igor Ostapenko AuthorDate: 2023-12-12 18:26:21 +0000 Commit: Kristof Provost CommitDate: 2023-12-27 21:01:38 +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 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 8bb7b076b7b7..7bdf5424ddf3 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -1036,19 +1036,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; + 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 = new_base; } - nw->base = new_base; return (true); }