From nobody Mon Jan 16 12:22:09 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 4NwWNy24Vpz2sFxS; Mon, 16 Jan 2023 12:22:10 +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 4NwWNy1cQ4z457x; Mon, 16 Jan 2023 12:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673871730; 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=0DDzgTtU7tmTTkoO6ujOyWWHSY2erLZB3HBBatD+xb4=; b=nKxyfKfM5pM7tsQZNyxW4OwTKbmFkG7L+gbSVfMIrHKd9N5jp1w8NY5LoNL+KNWtvHCR70 11jj271gMwDosOYvy6BBntSEZRgmO3Db5AySsPipKq5qBEvOllENE9dUO/oG3m3BEJUuIY dD+pfabmShAVxxV41Kkie4wZk/j8vzcivLs7X1MXMG2oV6kq80IV/ZfMKwybaKlsRItmqa 6pgQ1fbBtLvJ9iI9kTuD2OlwZwd0VpTHHrkMjHcLD8+syXTSDu224FiqtAgx2hRnTpRpta 4NQ4RtYfOczAkLCrIlOu0dkxgbhrptDU5zOyU8F3w+LZWLaI4rd1mmheXvRUsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673871730; 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=0DDzgTtU7tmTTkoO6ujOyWWHSY2erLZB3HBBatD+xb4=; b=PpX5esJSpHGtn4GNyvnGF8StBnDvvV7mcdanX2zF0eLjJzvyTQ+wCCQz1rnlGM7FiMeV0r qJiLlminWB8+nyQBr2poTEfrXu3pVGXm7ansU2W2spea6Ng45nhpYFHfF5JPWK47KJEXul s+A1agnMAUlfRpsuP5qB9czIQQGmSvWqkCtOLAH45rZB2a05Cxx9LiAXmPMBr+tWu97Nqp XL8GGvWLHSvA5scXnHkxQ0PqWncbKzgfp7xdKkwlgHczhd2sihL5RYRO2wryaXF9D/O9P/ o0osh5IREXiezJbuNTJUHoeN48dbKrYxv9cTdfR8O91eLMmaSFLhEUAi5CYBnQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673871730; a=rsa-sha256; cv=none; b=KcZ3UF45PGwFZ4dTL8MPG+KkUd1OLgw4h2Rgxf7WvhQnZ7x+FvTQ/OUa3gKX3A/W2BqM7M GHBszGOUE1s3a/NgG3cA7rB0bX4d497j8FeNs/97wRfZPGpFN/VfqNKOnZLNG2XN4BGrvg sBMJdQW/a3HTi2efKrDuUgiewwFSFJvn9oKDbTPhGNQCtWNSzaney2HJcqAhJhVezCKyNE BP2IZzqOOzOC2HzuSjJNMihBIXDwOaGNWOHtBDqk6M3Bl/w8UOAj/h5gMwvp/XM7mg43zi /jQPLuarAF7RN6aeD0fWi57lNUpz3ZrFJJ6d8vefIsYuKaixavzQNxVRH40k/g== 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 4NwWNy0fkMz16C5; Mon, 16 Jan 2023 12:22:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30GCM9Xg063275; Mon, 16 Jan 2023 12:22:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30GCM9pm063274; Mon, 16 Jan 2023 12:22:09 GMT (envelope-from git) Date: Mon, 16 Jan 2023 12:22:09 GMT Message-Id: <202301161222.30GCM9pm063274@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 228c632ab3f6 - main - netlink: fix compatibility with older netlink applications. 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: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 228c632ab3f6245df4a08d8692d49c8e12aacc27 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=228c632ab3f6245df4a08d8692d49c8e12aacc27 commit 228c632ab3f6245df4a08d8692d49c8e12aacc27 Author: Alexander V. Chernikov AuthorDate: 2023-01-16 12:14:35 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-16 12:21:40 +0000 netlink: fix compatibility with older netlink applications. Some apps try to provide only the non-zero part of the required message header instead of the full one. It happens when fetching routes or interface addresses, where the first header byte is the family. This behavior is "illegal" under the "strict" Netlink socket option, however there are many applications out there doing things in the "old" way. Support this usecase by copying the provided bytes into the temporary zero-filled header and running the parser on this header instead. Reported by: Goran Mekić --- sys/netlink/netlink_message_parser.h | 16 +++++++++++++--- tests/sys/netlink/test_rtnl_ifaddr.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sys/netlink/netlink_message_parser.h b/sys/netlink/netlink_message_parser.h index 96fd1c7337b7..3f64c1967f09 100644 --- a/sys/netlink/netlink_message_parser.h +++ b/sys/netlink/netlink_message_parser.h @@ -213,9 +213,19 @@ nl_parse_header(void *hdr, int len, const struct nlhdr_parser *parser, int error; if (__predict_false(len < parser->nl_hdr_off)) { - nlmsg_report_err_msg(npt, "header too short: expected %d, got %d", - parser->nl_hdr_off, len); - return (EINVAL); + if (npt->strict) { + nlmsg_report_err_msg(npt, "header too short: expected %d, got %d", + parser->nl_hdr_off, len); + return (EINVAL); + } + + /* Compat with older applications: pretend there's a full header */ + void *tmp_hdr = npt_alloc(npt, parser->nl_hdr_off); + if (tmp_hdr == NULL) + return (EINVAL); + memcpy(tmp_hdr, hdr, len); + hdr = tmp_hdr; + len = parser->nl_hdr_off; } if (npt->strict && parser->sp != NULL && !parser->sp(hdr, npt)) diff --git a/tests/sys/netlink/test_rtnl_ifaddr.py b/tests/sys/netlink/test_rtnl_ifaddr.py index bd1c55e268e7..ec349fcd6fde 100644 --- a/tests/sys/netlink/test_rtnl_ifaddr.py +++ b/tests/sys/netlink/test_rtnl_ifaddr.py @@ -8,6 +8,7 @@ from atf_python.sys.net.netlink import NetlinkTestTemplate from atf_python.sys.net.netlink import NlConst from atf_python.sys.net.netlink import NlHelper from atf_python.sys.net.netlink import NlmBaseFlags +from atf_python.sys.net.netlink import Nlmsghdr from atf_python.sys.net.netlink import NlMsgType from atf_python.sys.net.netlink import NlRtMsgType from atf_python.sys.net.netlink import Nlsock @@ -68,6 +69,25 @@ class TestRtNlIfaddr(NetlinkTestTemplate, SingleVnetTestTemplate): assert len([r for r in ret if r[0] == ifname and r[1] == socket.AF_INET6]) == 2 assert len(ret) == 3 + def test_46_filter_family_compat(self): + """Tests that family filtering works with the stripped header""" + + hdr = Nlmsghdr( + nlmsg_len=17, + nlmsg_type=NlRtMsgType.RTM_GETADDR.value, + nlmsg_flags=NlmBaseFlags.NLM_F_ACK.value | NlmBaseFlags.NLM_F_REQUEST.value, + nlmsg_seq=self.helper.get_seq() + ) + data = bytes(hdr) + struct.pack("@B", socket.AF_INET) + self.nlsock.write_data(data) + + ret = [] + for rx_msg in self.read_msg_list(hdr.nlmsg_seq, NlRtMsgType.RTM_NEWADDR): + ifname = socket.if_indextoname(rx_msg.base_hdr.ifa_index) + family = rx_msg.base_hdr.ifa_family + ret.append((ifname, family, rx_msg)) + assert len(ret) == 2 + def filter_iface_family(self, family, num_items): """Tests that listing outputs IPv4 for the specific interface""" epair_ifname = self.vnet.iface_alias_map["if1"].name