[Bug 276363] if_wg: Fix a code bug in calculate_padding() although impossible to hit
Date: Tue, 16 Jan 2024 14:29:19 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=276363 --- Comment #1 from Aaron LI <aly@aaronly.me> --- Well, after testing, I found 'pkt->p_mtu' is actually 0 for keepalive packets; however, those packets also have a zero length, so calculate_padding() didn't cause any real problems. I suggest the following new patch: --- if_wg.c.orig 2023-10-12 09:06:16.983637264 +0800 +++ if_wg.c 2024-01-16 22:25:04.878629478 +0800 @@ -1461,8 +1461,11 @@ calculate_padding(struct wg_packet *pkt) { unsigned int padded_size, last_unit = pkt->p_mbuf->m_pkthdr.len; - if (__predict_false(!pkt->p_mtu)) - return (last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDING - 1); + /* Keepalive packets don't set p_mtu, but also have a zreo length. */ + if (__predict_false(pkt->p_mtu == 0)) { + padded_size = (last_unit + (WG_PKT_PADDING - 1)) & ~(WG_PKT_PADDING - 1); + return padded_size - last_unit; + } if (__predict_false(last_unit > pkt->p_mtu)) last_unit %= pkt->p_mtu; -- You are receiving this mail because: You are the assignee for the bug.