From nobody Fri Aug 22 16:24:08 2025 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 4c7lr93RPvz64Yk8; Fri, 22 Aug 2025 16:24:09 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4c7lr919w1z3d3l; Fri, 22 Aug 2025 16:24:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755879849; 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=smAdmSzgwyuGnW+LVS9Q1EHjASjOCvmIVpheTVjlQMM=; b=v9XsBLVvIYGTxqzaVXsMylKDYrIahhg5kXxrkWBoisD3GszxHDaUd0/fk0JC8zeHQYL3Tu TFcZJwa3Ec9DdA6VaLZ9+4mRFXJVZ60kuykN45+gLlwV81WurCzPEkDrMU8XtP//g97U+5 J85CulKncT1a1pGG/8GadFzu4U2qKhVTwAi26Xm4tn/QIM7dywph7bWM3Axb3HI6hdGjKu 7vZAnL5cDP1wB39VxKoCA+bvHQ+R+mSB0eEniH7HqbCBZjiiYNKRsm64xqbDlZRAy/mqb0 eVZpsFVnw1wxLbNir90EHVEzeO9VW9HfATeT3pdYzAzCpocPdEIrQTU80z85xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1755879849; 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=smAdmSzgwyuGnW+LVS9Q1EHjASjOCvmIVpheTVjlQMM=; b=VcvjOYr5akxvDv/XhYmf57RcMGvyv3+zB3DYsanbw3LuooNutzNv0+xrcQ8itFBCYkNY4t ago18YmzJ3baeu55K57FjqJ1mqqwDTAugEY2pXevqmoPdZfLSalmFZgkaY7b/HOqyOivhE rTmGi3yIRY9kUS/YR8dLgl9/4DHlj1rmT53Ico5ipSZxu4GzNm9pgbaUG28oNaCnZ4DRQN gcOS329DqOifiqo+YzzTvyG8e9rSYHpPzX5NS3TsBWb567WweDrlCpxH5oHZUpfl4XTKnt v2XoFbEgrFATL+JEBy/MUQQ/Nv/CZGD3+6GtZK2iG5G0kaBacSLgl/0YIQ/eag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1755879849; a=rsa-sha256; cv=none; b=HwFYHvd55meWI6R8UpuT2GTxQD3Y1Awd3jshDpTuPEI83VA9zlqbP1B8dsBMkDH4rpOWhv aqG+kcZhvoGUWOpAZbSD0r6ob/7dHte3WoET6E6Z1NTb4aHIP17Z8fMxFiFw5i47ezV6FO 1aYp5k4DJOtI2ziBjjH6eq9IJWW1C+5uLW+xQkS2m0xEePvKzAyhIPauVyvqHih+f959H0 GdAw0RRgKbAIYEQ261QhWwfMuy3jd9PVcOAvglXMi02Hcv+R8UYQMJYju6Yy2KYFp+oUV/ MxLp4rY2v1fq2bn/PyVbl2vN5aeH+6p6Av/y9F0Mh+hM0B4qGAxgS5GdPUsNlA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4c7lr90dS0zstY; Fri, 22 Aug 2025 16:24:09 +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 57MGO8mN022432; Fri, 22 Aug 2025 16:24:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 57MGO8od022429; Fri, 22 Aug 2025 16:24:08 GMT (envelope-from git) Date: Fri, 22 Aug 2025 16:24:08 GMT Message-Id: <202508221624.57MGO8od022429@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: 0d9ef08e099f - main - netlink: do not pass writer to the Linux translation layer 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 0d9ef08e099f6837de5a40fd582d9ffb01fd31a4 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=0d9ef08e099f6837de5a40fd582d9ffb01fd31a4 commit 0d9ef08e099f6837de5a40fd582d9ffb01fd31a4 Author: Gleb Smirnoff AuthorDate: 2025-08-22 16:23:38 +0000 Commit: Gleb Smirnoff CommitDate: 2025-08-22 16:23:38 +0000 netlink: do not pass writer to the Linux translation layer Another flaw in the KPI between Netlink and Linuxulator is that we pass the on-stack writer structure. This structure belongs to someone, that we can't even identify inside nl_send() and we shall not tamper it. The Linux translation layer needs a writer, because it actually composes a new message. Instead of reusing someone's writer and trying to repair it in all possible cases where translation process tampers the writer, just let Linuxulator use its own writer. See also b977dd1ea5fb. PR: 288892 Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D51928 --- sys/compat/linux/linux_netlink.c | 37 +++++++++++++------------------------ sys/netlink/netlink_io.c | 13 +++++++------ sys/netlink/netlink_linux.h | 2 +- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/sys/compat/linux/linux_netlink.c b/sys/compat/linux/linux_netlink.c index d414fad375c0..927f3689e2b6 100644 --- a/sys/compat/linux/linux_netlink.c +++ b/sys/compat/linux/linux_netlink.c @@ -550,22 +550,15 @@ nlmsg_to_linux(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_writer *nw) } } -static bool -nlmsgs_to_linux(struct nl_writer *nw, struct nlpcb *nlp) +static struct nl_buf * +nlmsgs_to_linux(struct nl_buf *orig, struct nlpcb *nlp) { - struct nl_buf *nb, *orig; - u_int offset, msglen, orig_messages; - - RT_LOG(LOG_DEBUG3, "%p: in %u bytes %u messages", __func__, - nw->buf->datalen, nw->num_messages); + struct nl_writer nw; + u_int offset, msglen; - orig = nw->buf; - nb = nl_buf_alloc(orig->datalen + SCRATCH_BUFFER_SIZE, M_NOWAIT); - if (__predict_false(nb == NULL)) - return (false); - nw->buf = nb; - orig_messages = nw->num_messages; - nw->num_messages = 0; + if (__predict_false(!nl_writer_unicast(&nw, + orig->datalen + SCRATCH_BUFFER_SIZE, nlp, false))) + return (NULL); /* Assume correct headers. Buffer IS mutable */ for (offset = 0; @@ -574,22 +567,18 @@ nlmsgs_to_linux(struct nl_writer *nw, struct nlpcb *nlp) struct nlmsghdr *hdr = (struct nlmsghdr *)&orig->data[offset]; msglen = NLMSG_ALIGN(hdr->nlmsg_len); - if (!nlmsg_to_linux(hdr, nlp, nw)) { + if (!nlmsg_to_linux(hdr, nlp, &nw)) { RT_LOG(LOG_DEBUG, "failed to process msg type %d", hdr->nlmsg_type); - nl_buf_free(nb); - nw->buf = orig; - nw->num_messages = orig_messages; - return (false); + nl_buf_free(nw.buf); + return (NULL); } } - MPASS(nw->num_messages == orig_messages); - MPASS(nw->buf == nb); - nl_buf_free(orig); - RT_LOG(LOG_DEBUG3, "%p: out %u bytes", __func__, offset); + RT_LOG(LOG_DEBUG3, "%p: in %u bytes %u messages", __func__, + nw.buf->datalen, nw.num_messages); - return (true); + return (nw.buf); } static struct linux_netlink_provider linux_netlink_v1 = { diff --git a/sys/netlink/netlink_io.c b/sys/netlink/netlink_io.c index e7908d6f3a44..2391d8ea752c 100644 --- a/sys/netlink/netlink_io.c +++ b/sys/netlink/netlink_io.c @@ -216,16 +216,17 @@ nl_send(struct nl_writer *nw, struct nlpcb *nlp) hdr->nlmsg_len); } - if (nlp->nl_linux && linux_netlink_p != NULL && - __predict_false(!linux_netlink_p->msgs_to_linux(nw, nlp))) { + if (nlp->nl_linux && linux_netlink_p != NULL) { + nb = linux_netlink_p->msgs_to_linux(nw->buf, nlp); nl_buf_free(nw->buf); nw->buf = NULL; - return (false); + if (nb == NULL) + return (false); + } else { + nb = nw->buf; + nw->buf = NULL; } - nb = nw->buf; - nw->buf = NULL; - SOCK_RECVBUF_LOCK(so); if (!nw->ignore_limit && __predict_false(sb->sb_hiwat <= sb->sb_ccc)) { SOCK_RECVBUF_UNLOCK(so); diff --git a/sys/netlink/netlink_linux.h b/sys/netlink/netlink_linux.h index d4c451d470b2..794065692901 100644 --- a/sys/netlink/netlink_linux.h +++ b/sys/netlink/netlink_linux.h @@ -37,7 +37,7 @@ struct nlpcb; struct nl_pstate; struct nl_writer; -typedef bool msgs_to_linux_cb_t(struct nl_writer *nw, struct nlpcb *nlp); +typedef struct nl_buf * msgs_to_linux_cb_t(struct nl_buf *, struct nlpcb *); typedef int msg_from_linux_cb_t(int netlink_family, struct nlmsghdr **hdr, struct nl_pstate *npt);