From nobody Sat Nov 23 18:08:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1723812381845367.6568332160115; Fri, 16 Aug 2024 05:46:21 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D0B5E1314; Fri, 16 Aug 2024 08:46:20 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id F0CDC13B3; Fri, 16 Aug 2024 08:45:17 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87723126F; Fri, 16 Aug 2024 08:45:12 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 189C01314 for ; Fri, 16 Aug 2024 08:45:12 -0400 (EDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-gS96UkavPd2Zz6LgIoewiA-1; Fri, 16 Aug 2024 08:45:10 -0400 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42820af1106so14001425e9.2 for ; Fri, 16 Aug 2024 05:45:10 -0700 (PDT) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded28cdasm74820115e9.16.2024.08.16.05.45.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 05:45:08 -0700 (PDT) Received: from wheatley.pinto-pinecone.ts.net (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 6DFDF1C16EA6 for ; Fri, 16 Aug 2024 14:45:07 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723812311; 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: in-reply-to:in-reply-to:references:references; bh=Eyfu8n+qki1nw02GO9BqaRtK42uZzUHbZQ5KLLDLQ/A=; b=iR7iCAsaaC96BuSbWHVE3JRqsVLsVBtU8WzPlBeCVhVVcFCFDs1S5F5xJzL57hBX3bVPm7 dBD+SWsMqKVxbL9rwfg5LNqK9LR5ml+MtxGoPUaVu9YcEPSPAhTRAAQ1E6nyeEz8fQGx16 881a/fvHJ8W9nBEcxtkXUQp/XgNkhXc= X-MC-Unique: gS96UkavPd2Zz6LgIoewiA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723812309; x=1724417109; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Eyfu8n+qki1nw02GO9BqaRtK42uZzUHbZQ5KLLDLQ/A=; b=PNXs3AEvBdW0cX6AS4lqUBY5F/xe/pt1CLDN9O9MVxFPvkj9v90q6HSkBhWBk1QNXg njXGtNjZ/Cw78afK87kVsXgrNmDE0eA2M4NznMzku4uofAVE+3RGPgAbwjoKVARoA+g1 L00HF47EtDm5oyvCpdg2sTNcaCvGSj0AQb+27vrqqhYOWCR5EUEinAc6pk0z8ifQnUAn 2hJ1qPiZrJHAYkuIl9t5TASLivZg6WfgxKExh1hpQzCjsoNrJ08CHWlMhtyUImuc+KiB KiKBgyB1S6ALvJhFpgPRXZatRFN4Jb30ohAKrT/d2hq8E4FZ4/zQBE8YwE++2z6VaDtD OfQQ== X-Gm-Message-State: AOJu0Yz2IShMSbl8mU323gFzQZTt5FqassNQQRAXapjDO0USbxdRICqd qrXGI/YWf0E3sbLnMmh5hjWxl97mFGt11yiuUX50lm4oTMYmX0hj1G6/zdXLSip7ZdEN0tvVcgZ 82ET9JhTr7DXuNKD7X4plI+djXIiQYK/tXLYH5hW3AsRjYBt3Ctpa0dent2OKKBU27Hf0HBfXCI 5YVYr08bEkpLUdqEKCS3oes/jMqbo4PVN+CGIRncc= X-Received: by 2002:a05:600c:4449:b0:426:6f27:379a with SMTP id 5b1f17b1804b1-429ed79e6e7mr17030025e9.13.1723812309042; Fri, 16 Aug 2024 05:45:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaE7WA5bCGdsmO8f6uyCvbxU1q2/E88IMO1USYrqylJLHawm94F0qSE2cAbAwZR/Kno32ftQ== X-Received: by 2002:a05:600c:4449:b0:426:6f27:379a with SMTP id 5b1f17b1804b1-429ed79e6e7mr17029765e9.13.1723812308508; Fri, 16 Aug 2024 05:45:08 -0700 (PDT) From: Martin Kletzander To: devel@lists.libvirt.org Subject: [PATCH 3/3] virarptable: End parsing earlier in case of NLMSG_DONE Date: Fri, 16 Aug 2024 14:45:04 +0200 Message-ID: <07b95f52490bcea14fed3d496c3a9771651bda24.1723811504.git.mkletzan@redhat.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 362FM26545OPNL74S2R2UE6SQQUCQAGL X-Message-ID-Hash: 362FM26545OPNL74S2R2UE6SQQUCQAGL X-MailFrom: mkletzan@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1723812383129116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Check for the last multipart message right as the first thing. The presumption probably was that the last message might still contain a payload we want to parse. However that cannot be true since that would have to be a type RTM_NEWNEIGH. This was not caught because older kernels were note sending NLMSG_DONE and probably relied on the fact that the parsing just stops after all the messages are walked through, which the NLMSG_OK macro successfully did. Resolves: https://issues.redhat.com/browse/RHEL-52449 Signed-off-by: Martin Kletzander Reviewed-by: Laine Stump --- So technically this still has some issues, maybe. I could not find if our usage of libnl3 makes it easier for us so that we d= o not have to check for NLMSG_{ERROR,OVERRUN,NOOP} or whether these checks should= be here as well. If yes, then we should add them. And we have (some of) these checks elsewhere in the code, so "maybe". Another thing is that we could avoid such errors by using nl_socket_set_cb(= ), calling nl_recvmsgs_default() and then parsing only the valid messages in a callback. On top of that we could have an abstraction on top this to utili= se in all the netlink dumps we do, ditching our current abstraction which was a b= it hard for me to go through, to be honest. And of course there might be other places in our codebase that expect the s= ame behaviour as this code did and we should fix 'em all. After all the debugg= ing for this piece I did not even check for those, maybe if this gets in I'll h= ave a long think about it. src/util/virarptable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 8e805fb35332..604019c62a37 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -84,6 +84,9 @@ virArpTableGet(void) int len =3D nh->nlmsg_len; void *addr; =20 + if (nh->nlmsg_type =3D=3D NLMSG_DONE) + return table; + if (len < NLMSG_SPACE(sizeof(*r))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("wrong nlmsg len")); @@ -98,9 +101,6 @@ virArpTableGet(void) (!(r->ndm_state =3D=3D NUD_STALE || r->ndm_state =3D=3D NUD_RE= ACHABLE))) continue; =20 - if (nh->nlmsg_type =3D=3D NLMSG_DONE) - return table; - VIR_WARNINGS_NO_CAST_ALIGN parse_rtattr(tb, NDA_MAX, NDA_RTA(r), NLMSG_PAYLOAD(nh, sizeof(*r)= )); VIR_WARNINGS_RESET --=20 2.46.0