From nobody Sun Feb 8 23:41:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1646643860; cv=none; d=zohomail.com; s=zohoarc; b=bWFyYngITctveiIepP44+D8bbRT7yvM7wDWOau9CqBrlr0YjZ3W/S9il9089H9gob5NUCpcmjFJWGoJYT3APX/xrndxaTh+heYT8XWyoPk97JTYKv23XfwIt3023OX6CmVPGTHeUT3fw0JNoVUjZ6B76p9U5nI162L1+1dQi6p0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646643860; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iQQaVY36MOs12hMsgS6tAS4tuSwsxvNqg475S9Ye+jw=; b=iSWMVnqKknLllYeUhAPhl6Ej5mmbaIIk9eYzxz9h6b7ranBxaGiWjpQPjwpTVFZWt0a6Ii2yW8FMydOB+qVHqbSgp13C+EByrZ6V/fdR0DIq2bn8OGVvA0OfNJMPnEOeS60Du0LUoyv88lpEieIsrvllh+fyY0YzpcxZpnX2u30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646643860757588.7186616858661; Mon, 7 Mar 2022 01:04:20 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-nNaSngt9OdycjXm3H5kUhw-1; Mon, 07 Mar 2022 04:04:17 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A358518E6C54; Mon, 7 Mar 2022 09:04:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F6B957ECC5; Mon, 7 Mar 2022 09:04:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 02BEF193059E; Mon, 7 Mar 2022 09:04:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D17EC1931BD6 for ; Mon, 7 Mar 2022 09:04:12 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A3D54401E40; Mon, 7 Mar 2022 09:04:12 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FA1F401E39 for ; Mon, 7 Mar 2022 09:04:12 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85BDB811E76 for ; Mon, 7 Mar 2022 09:04:12 +0000 (UTC) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-479-0lP_jvs4Oiu7YK7oXMaCrg-1; Mon, 07 Mar 2022 04:04:09 -0500 Received: by mail-ej1-f69.google.com with SMTP id x2-20020a1709065ac200b006d9b316257fso6701968ejs.12 for ; Mon, 07 Mar 2022 01:04:09 -0800 (PST) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id d4-20020a1709067a0400b006d6e3ca9f71sm4554836ejo.198.2022.03.07.01.04.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 01:04:07 -0800 (PST) Received: from wheatley.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id B5F454F8448C for ; Mon, 7 Mar 2022 10:04:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646643860; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=iQQaVY36MOs12hMsgS6tAS4tuSwsxvNqg475S9Ye+jw=; b=AlF5jL8x3Kkhsm4D5CVljtU/euouS6PGoA9bD+CkJXkaa2dDjtHnjtIZhYxks1uFYac3AL 3FXzZKNJOkhw4zFSJHaGzGvAb9B0VzQZ4p+Lo3j0UA4Bx7QodcpfAvKwOCQ6t3mkKZmdPM nmFZtOOElYcDw/tyL3cBLxh6I0J1Ubo= X-MC-Unique: nNaSngt9OdycjXm3H5kUhw-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: 0lP_jvs4Oiu7YK7oXMaCrg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iQQaVY36MOs12hMsgS6tAS4tuSwsxvNqg475S9Ye+jw=; b=cRGyIKnpJtiiYQOoZhHP7lW2SaNHxPtzlZBEyHOr/W1ueqdgesSM3ruq+//KqMRrr1 23TOaRxdtZTeNaeXD8N/9OXloes5lUtEHdQDCdGa3RQF8pSuuYNUhuzoXw25jvPOlDDB 0wqbo4usxpBzgzzdWx7+VDuo0QhjG79smVE/EEXWrXi0yLBrYkr2qP60FqIU3Ed84Zub IMBYhZAtcI9fFOrb5sAJjK6/Xaad9bnORJSNPfh/qkmGgOGzfEYhoa78MJRRyn5+x4tV sYLLiCk0+yVydKiDd/zYye7bkpjcke0UDDg36Wnzmx7ytjA9FZbXMJd/RQKadug1gx8D Wdww== X-Gm-Message-State: AOAM530osI4l1/7ki9J2OwbKUmk85WkuisHC25lRYIBS0U90mheozOXK hD4xKqNG58Iw8z6ikstke6JUl6P2j4i6P5oiZxqouoi1Ey+5gcJR25XoGNjUBIletXMp1Qcvglc rJFMVqSpgBJk+q+vBjd8K0xqVL2PjWCaCSTQ2vbUeTxILnVYh4gl0bP8aYED+UDhcUpcNRHg= X-Received: by 2002:a17:906:8488:b0:6da:bebf:98b with SMTP id m8-20020a170906848800b006dabebf098bmr8280610ejx.587.1646643848056; Mon, 07 Mar 2022 01:04:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzb7KYeHO5pfEQvO5iSI/nnkJyGNL1rCK2YGeOsBDHGoXu9QU5rbsEA8+h2FnT1aOD+I1i8Uw== X-Received: by 2002:a17:906:8488:b0:6da:bebf:98b with SMTP id m8-20020a170906848800b006dabebf098bmr8280595ejx.587.1646643847834; Mon, 07 Mar 2022 01:04:07 -0800 (PST) From: Martin Kletzander To: libvir-list@redhat.com Subject: [libvirt PATCH 4/5] nwfilter: Avoid memory alignment issues Date: Mon, 7 Mar 2022 10:04:05 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646643872052100001 Content-Type: text/plain; charset="utf-8" The returned packet can have less strict alignment (u_char) than the struct (ether_header) we are casting it to, so to avoid alignment issues just copy= the header into the struct on the stack. Signed-off-by: Martin Kletzander --- src/nwfilter/nwfilter_learnipaddr.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_le= arnipaddr.c index fb552bd1e60e..99bffdc4fbdb 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -384,7 +384,7 @@ learnIPAddressThread(void *arg) struct bpf_program fp; struct pcap_pkthdr header; const u_char *packet; - struct ether_header *ether_hdr; + struct ether_header ether_hdr; struct ether_vlan_header *vlan_hdr; virNWFilterIPAddrLearnReq *req =3D arg; uint32_t vmaddr =3D 0, bcastaddr =3D 0; @@ -506,13 +506,14 @@ learnIPAddressThread(void *arg) } =20 if (header.len >=3D sizeof(struct ether_header)) { - ether_hdr =3D (struct ether_header*)packet; + /* Avoid alignment issues */ + memcpy(ðer_hdr, packet, sizeof(struct ether_header)); =20 - switch (ntohs(ether_hdr->ether_type)) { + switch (ntohs(ether_hdr.ether_type)) { =20 case ETHERTYPE_IP: ethHdrSize =3D sizeof(struct ether_header); - etherType =3D ntohs(ether_hdr->ether_type); + etherType =3D ntohs(ether_hdr.ether_type); break; =20 case ETHERTYPE_VLAN: @@ -528,7 +529,7 @@ learnIPAddressThread(void *arg) continue; } =20 - if (virMacAddrCmpRaw(&req->binding->mac, ether_hdr->ether_shos= t) =3D=3D 0) { + if (virMacAddrCmpRaw(&req->binding->mac, ether_hdr.ether_shost= ) =3D=3D 0) { /* packets from the VM */ =20 if (etherType =3D=3D ETHERTYPE_IP && @@ -568,9 +569,9 @@ learnIPAddressThread(void *arg) } } } else if (virMacAddrCmpRaw(&req->binding->mac, - ether_hdr->ether_dhost) =3D=3D 0 || + ether_hdr.ether_dhost) =3D=3D 0 || /* allow Broadcast replies from DHCP server */ - virMacAddrIsBroadcastRaw(ether_hdr->ether_dhost)) { + virMacAddrIsBroadcastRaw(ether_hdr.ether_dhost)) { /* packets to the VM */ if (etherType =3D=3D ETHERTYPE_IP && (header.len >=3D ethHdrSize + --=20 2.35.1