git: d0076c7a8653 - stable/12 - netinet: re-read IP length after PFIL hook

From: Kristof Provost <>
Date: Wed, 28 Jun 2023 09:16:30 UTC
The branch stable/12 has been updated by kp:


commit d0076c7a86538d295ca2508dddc5d5429a2c4ff7
Author:     Kristof Provost <>
AuthorDate: 2023-06-02 14:38:30 +0000
Commit:     Kristof Provost <>
CommitDate: 2023-06-28 09:15:59 +0000

    netinet: re-read IP length after PFIL hook
    The pfil hook may modify the packet, so before we check its length (to
    decide if it needs to be fragmented or not) we should re-read that
    This is most likely to happen when pf is reassembling packets. In that
    scenario we'd receive the last fragment, which is likely to be a short
    packet, pf would reassemble it (likely exceeding the interface MTU) and
    then we'd transmit it without fragmenting, because we're comparing the
    MTU to the length of the last fragment, not the fully reassembled
    See also:
    Reviewed by:    cy
    MFC after:      3 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:
    (cherry picked from commit 185c1cddd7ef34db82bc3a25b3c92556416a4e55)
 sys/netinet/ip_output.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 93b41376f3c2..a2e4513f1118 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -584,6 +584,7 @@ sendit:
 		case 0: /* Continue normally */
 			ip = mtod(m, struct ip *);
+			ip_len = ntohs(ip->ip_len);
 		case -1: /* Need to try again */