Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2024 05:24:32 +0000
From:      bugzilla-noreply@freebsd.org
To:        bugs@FreeBSD.org
Subject:   [Bug 276363] if_wg: Fix a code bug in calculate_padding() although impossible to hit
Message-ID:  <bug-276363-227@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D276363

            Bug ID: 276363
           Summary: if_wg: Fix a code bug in calculate_padding() although
                    impossible to hit
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: aly@aaronly.me

The padding length calculation in calculate_padding() is wrong for the spec=
ial
case of 'p_mtu =3D 0'.  It's calculating the padded length instead of the l=
ength
to pad.  So it should be:

if (__predict_false(!pkt->p_mtu))
        return ((last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDING - 1))=
 -
last_unit;

However, it's impossible for 'p_mtu' to be zero.  So I'd propose the follow=
ing
fix:

@@ -1461,8 +1461,7 @@ calculate_padding(struct wg_packet *pkt)
 {
        unsigned int padded_size, last_unit =3D pkt->p_mbuf->m_pkthdr.len;

-       if (__predict_false(!pkt->p_mtu))
-               return (last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDIN=
G -
1);
+       KASSERT(pkt->p_mtu !=3D 0, ("%s: packet %p has p_mtu =3D 0", __func=
__, m));

        if (__predict_false(last_unit > pkt->p_mtu))
                last_unit %=3D pkt->p_mtu;

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-276363-227>