From nobody Sat Nov 23 15:15:20 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 1723812354676497.97093286921915; Fri, 16 Aug 2024 05:45:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9C1FE1384; Fri, 16 Aug 2024 08:45:53 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 1DE0B1377; Fri, 16 Aug 2024 08:45:16 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 82092136C; 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 12718126F for ; Fri, 16 Aug 2024 08:45:12 -0400 (EDT) Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-SYJoFg1_MPWVjry3qU499A-1; Fri, 16 Aug 2024 08:45:10 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3718d9d9267so741570f8f.0 for ; Fri, 16 Aug 2024 05:45:09 -0700 (PDT) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3718985a7d3sm3588828f8f.61.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 53DC21C16EA4 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=pLDl88P5c0hLXdcIG3xInGLDg4dxwj2L0v21w3WLlSA=; b=AKEjYM2U1LsXsV91ShFjDLvysuf73sJfozxCZ1cSe9pYrd9WSp8g+0shPjnmCoA77eFQUo c3e4m9zOR1qgjVqvPG+iM1ig8gBKUSIAswPmIYMnWzfOq9HQvbi6TZjzvSDex+GVOVfzgW OowGs6t/LJsVLFTTfWZT3n+Hp8s30ks= X-MC-Unique: SYJoFg1_MPWVjry3qU499A-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=pLDl88P5c0hLXdcIG3xInGLDg4dxwj2L0v21w3WLlSA=; b=IZLRDQHh4d4C89XsCwBqslc8rIOuTkM9kwC6nbVdzByWBbbhfgZ6n1Zg/6IZ90b9e1 /AGKcqjwINvuMfdhhdalVIcS+l4vHImvDvOPlX39SRoJMkgPMhBmzqSxSPMtu0P5HLc2 odemaQMQPK9/Zu+4XLYpTjgapm2Oizcnufb1mAVU3rmsJpczm9ko2oC1yAb9jjswmOpS qdJrydw6bFtuwFcW8+XLyYQY2651KvpUs8oGHUg3GiclEjL6PhQZ1LHBA+JKrDEBcu2I qx/C252X8wMvCH2m7eyVukdgzCmnyfTjnBNIyyZy1299VkC4SSlViJMrKldQkMBb+LEm 8KiA== X-Gm-Message-State: AOJu0Yy9bURuYKUakA1URIOE3Tl96xUfkFqmgDLFvWGMILIb4z+R0jUS dim2asKkyBGy0IizVE/LJRX8xHU1lSXKtB42OHWFqY72Z6QAlE/CYyvmad7kltZfJB99Ixacbmt pxcChMXhaSv9N+1LjShRo6PMQvlBl8I3CroPr9brR/obRp+ec18k5jVcASjGX7JT3ZCNBM9Rlvo G3n03tLtkXe5peVSRPO9NM1FXhfJUY78Yeei85oVo= X-Received: by 2002:a5d:6742:0:b0:371:86b2:a7e4 with SMTP id ffacd0b85a97d-37194659619mr1841229f8f.37.1723812308833; Fri, 16 Aug 2024 05:45:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGO+6bEKMuA53QEggKYDYTY5iZCr/BwUcoLrqIXLaD0VYCiGrLXjB+hbm2JDcMs7+guSjJGSg== X-Received: by 2002:a5d:6742:0:b0:371:86b2:a7e4 with SMTP id ffacd0b85a97d-37194659619mr1841203f8f.37.1723812308332; Fri, 16 Aug 2024 05:45:08 -0700 (PDT) From: Martin Kletzander To: devel@lists.libvirt.org Subject: [PATCH 1/3] virarptable: Properly calculate rtattr length Date: Fri, 16 Aug 2024 14:45:02 +0200 Message-ID: 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: ULHFIWQ6QW4CIP2FHSVHCMQ4SXXAYINE X-Message-ID-Hash: ULHFIWQ6QW4CIP2FHSVHCMQ4SXXAYINE 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: 1723812356690116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Use convenience macro from libnl3 which does almost the same thing we were doing, but also aligns the payload length. Signed-off-by: Martin Kletzander Reviewed-by: Laine Stump --- src/util/virarptable.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index 299dddd664ab..d8e41c5a8668 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -102,8 +102,7 @@ virArpTableGet(void) return table; =20 VIR_WARNINGS_NO_CAST_ALIGN - parse_rtattr(tb, NDA_MAX, NDA_RTA(r), - nh->nlmsg_len - NLMSG_LENGTH(sizeof(*r))); + parse_rtattr(tb, NDA_MAX, NDA_RTA(r), NLMSG_PAYLOAD(nh, sizeof(*r)= )); VIR_WARNINGS_RESET =20 if (tb[NDA_DST] =3D=3D NULL || tb[NDA_LLADDR] =3D=3D NULL) --=20 2.46.0 From nobody Sat Nov 23 15:15:20 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 172381240110139.160759496452215; Fri, 16 Aug 2024 05:46:41 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 16F4B1373; Fri, 16 Aug 2024 08:46:40 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D14891599; Fri, 16 Aug 2024 08:45:19 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EE35F1310; 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.133.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 7C96D1358 for ; Fri, 16 Aug 2024 08:45:12 -0400 (EDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-422-nWhMjwCPN-u10w4She2cNg-1; Fri, 16 Aug 2024 08:45:10 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-427ffa0c9c7so20520495e9.1 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 ffacd0b85a97d-37189896c50sm3597037f8f.85.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 60DD31C16EA5 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_H4,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=1723812312; 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=XZ55D+VFOI/n85uDqOVP7Oh+zm0NVHf5rYyZoymlg00=; b=MCIuOsuaBIxE697g1F0vRpNO5u7TzJaEm8vM4KGgh5bKY9v+5eK5FWupcnzWVgOh+S6Wsm HfCg6OfOd3hqC81QdEwFdorikt3Gib1Z3QGl65zjuj76Ohb/S/uPzap51V7vyyM6e8z56C xCeS162Pr8OWxXdWKYNWK5GouBOPgL0= X-MC-Unique: nWhMjwCPN-u10w4She2cNg-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=XZ55D+VFOI/n85uDqOVP7Oh+zm0NVHf5rYyZoymlg00=; b=p4aPhzyytI1pt//x4GHKoh8wYXRrrXACBTWoXdjk0nlydQDgqxdzepVF+J8dbOOTjO mS7geAZtworpOhpOgQr5ONZ6ZosFRmbLM0vZAK0bj7kDLRdNZuMm4oWVyOn2za4eK9u/ 1B0hZdV6bw4bq/f6o359fkvrvcPxds7qlFTV45PqiR4hWU4/0VLKgMOBqjMWLXCq4xFQ +sDPqnqSBDz4wOBrpQ8qy7hU6cU2wvBKlLrF//LCE1RfpyqC4By1ASB7qwHL9TFa78C0 Jsnbkb/8lyoFBOeB6iIzdHa3ZZCYS6awIDWRByxPqzfZh7SEJZpnk/WvI22aec6daw1r /oIg== X-Gm-Message-State: AOJu0YwLBROPKu/kc/qRtVsadV0SfbkEzr5pl+Oe1wI5+yeY9VMH34W7 Z7vwJl++nNAvgcaEI0yrPPDzfFQSo0MaudoD6NbPdIg0u7Oaq7ZrIG12E3UpMVF+jMuEwT4cMvJ xM014zTQIHE63BDF/sPrQr825UmmkMhCG6KIsgdHihtsRcb4k7eu0FxclwGcdp0sgJEhzCsF6Q5 JTagg5rHHEof1jA2O8CDtmtGgD3Kw/jS7dkjV/J98= X-Received: by 2002:a05:6000:b51:b0:371:869b:4e5e with SMTP id ffacd0b85a97d-37194315752mr2172513f8f.1.1723812309314; Fri, 16 Aug 2024 05:45:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2X/Ju9S4bv7L4Kjp3KOIu7aUzVNrLVDd6JkQ/iNYu5icxGaDOyLqPigop9xiZL6tOLViYuQ== X-Received: by 2002:a05:6000:b51:b0:371:869b:4e5e with SMTP id ffacd0b85a97d-37194315752mr2172486f8f.1.1723812308750; Fri, 16 Aug 2024 05:45:08 -0700 (PDT) From: Martin Kletzander To: devel@lists.libvirt.org Subject: [PATCH 2/3] virarptable: Fix check for message length Date: Fri, 16 Aug 2024 14:45:03 +0200 Message-ID: <2fb405691bc7805c56c701b93ca3801ce6a08daf.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: CU5FOMP3YDYOUUIGNUPETQETU257UACW X-Message-ID-Hash: CU5FOMP3YDYOUUIGNUPETQETU257UACW 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: 1723812402911116600 Content-Type: text/plain; charset="utf-8"; x-default="true" The previous check was all wrong since it calculated the how long would the netlink message be if the netlink header was the payload and then subtracted that from the whole message length, a variable that was not used later in the code. This check can fail if there are no additional payloads, struct rtattr in particular, which we are parsing later, however the RTA_OK macro would've caught that anyway. Signed-off-by: Martin Kletzander Reviewed-by: Laine Stump --- src/util/virarptable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virarptable.c b/src/util/virarptable.c index d8e41c5a8668..8e805fb35332 100644 --- a/src/util/virarptable.c +++ b/src/util/virarptable.c @@ -84,7 +84,7 @@ virArpTableGet(void) int len =3D nh->nlmsg_len; void *addr; =20 - if ((len -=3D NLMSG_LENGTH(sizeof(*nh))) < 0) { + if (len < NLMSG_SPACE(sizeof(*r))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("wrong nlmsg len")); goto cleanup; --=20 2.46.0 From nobody Sat Nov 23 15:15:20 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