From nobody Tue Dec 12 21:04:30 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 4SqWML4w1Xz53GVw; Tue, 12 Dec 2023 21:04:30 +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 4SqWML4QD4z3Jg5; Tue, 12 Dec 2023 21:04:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702415070; 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=fmYm6LJ3pl13d0SkqtOyy74/S45DSqQxaMhAb2TgDDA=; b=chkjZkRNLopz/CUupCQiI+XHDjqyRtwOHX5ERIIaN5m/0wNHQGbwi66trNNT9Q5Lp2KLkG 9ofYGE4ZT3HqiLQ8kXGFH9KwQjKLkmIoaPCFZykSJDVnpQ/Wg296jlf+nWx/vvA/KA2FOM 1DqB4KlI7Vvujnxs7NHclwJNhrc3g3Rwk8EWr80WkbpJE4WSvjwXVVps+LaKD/TOtKSuFf DVQY8/3xeOxEFnVf2l5xfUPhP0J9egjeznB3hVmX7Dh87Z2WcThf6FhZBQViF6qRRM1TBJ u66S1TnUxhrnRdovktyfWgVZfm48AjTu//ddzSy0i1H6J4Btm4btADQCUt44aw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702415070; a=rsa-sha256; cv=none; b=ZTjAYIulUOj4oet88Ayw7OJHCTaJmVfUqAe4A0lGuLoDeyGh4FXMZl+PDpfXJ9pD55cNB7 125LU+MwHy/WPf3+c/8jsYrAfPjDcWFs6K3JPyrxQqS0oYoqxpYMSIZNXvBr19hcj7pySj uLpWe4zMC13Fgq5NCWjE4kTYeqLBaoFAX6EJr/k2EjHtTFTTHBuldT3A+2rfEWT8TfTFAl cNe1yZNI/iEVnSxxyD/9ahYEld8ozZCkol621bmM6OiEp2YsgV6AGItcN3zAqHcBzadT+4 63H5w5525Sjjn+k1463gG5cxIXbC/92jkqEPXozWsE4UQojSp5jEAl4QyLMDYA== 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=1702415070; 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=fmYm6LJ3pl13d0SkqtOyy74/S45DSqQxaMhAb2TgDDA=; b=WjZaVF/qJWw4TXnT8XQL5G2/ZXCYd3VNgpkpDOk4KZwvFGR++xVYBsgqFg+1BGnOGw6Dtj C6ux2d1BSCZWBYSzxMS8VZDaz4im/jYQZMYgkB7Rki0dmuVeefxyt3NkuQPKJvSvX4dkXO jTfB1SAnrWu95uFGhq7kwTxEYkz7tyzr9wuLAWJ+0YJQ7zmV1gFBUUqLsZfuOhQ/Hx3aC6 QPg5wmkmKixV3DQ1GJWYVt1Y7OZGwXqlRqN3Yw1JiPUn2DrXKwfDSEMDnrW1DYnJdGHPuD JT4Tmeo/9VsKK2ZXqDu86sFAZVicmrYTdyUfGa3tN5UCXFMiAAwCCCWYIzt9hw== 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 4SqWML3MY2zWH4; Tue, 12 Dec 2023 21:04:30 +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 3BCL4U5Z072184; Tue, 12 Dec 2023 21:04:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BCL4Ujo072181; Tue, 12 Dec 2023 21:04:30 GMT (envelope-from git) Date: Tue, 12 Dec 2023 21:04:30 GMT Message-Id: <202312122104.3BCL4Ujo072181@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 0c511bafdd5b - main - 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/main X-Git-Reftype: branch X-Git-Commit: 0c511bafdd5b309505c13c8dc7c6816686d1e103 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=0c511bafdd5b309505c13c8dc7c6816686d1e103 commit 0c511bafdd5b309505c13c8dc7c6816686d1e103 Author: Igor Ostapenko AuthorDate: 2023-12-12 18:26:21 +0000 Commit: Kristof Provost CommitDate: 2023-12-12 20:49:14 +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 --- 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); }