🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #496

[Bug 300824] pfsync: valid bulk update end mark rejected as "bad timestamp" when the peers' uptime seconds tick over at differen...

#496
From: bugzilla-noreply
Date: Mon, 16 Nov 2026 19:14
109 lines
7178 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300824

            Bug ID: 300824
           Summary: pfsync: valid bulk update end mark rejected as "bad
                    timestamp" when the peers' uptime seconds tick over at
                    different moments
           Product: Base System
           Version: 16.0-CURRENT
          Hardware: Any
               URL: https://github.com/freebsd/freebsd-src/pull/2545
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: kern
          Assignee: bugs@FreeBSD.org
          Reporter: andrew.luebke@gmail.com
                CC: kp@freebsd.org

A node that requests a pfsync bulk update can reject its peer's end mark
as "bad timestamp" although the update completed. The end mark is sent
once, so the node stays demoted in CARP ("pfsync bulk start", +240) with
syncok: 0 until the bulk fail timeout. On our OPNsense 26.7 CARP pair
(FreeBSD 15.1 base) the rebooted node stayed demoted for just under two
hours, twice in August (hz=100), and it happened again on 2026-11-10.
Since then a workaround script (see the end) has caught the same stuck
state on 2 of the pair's 10 reboots.

Code as of main b3860403a (if_pfsync.c has not changed in main since;
stable/15 has the same code at other line numbers),
sys/netpfil/pf/if_pfsync.c:

- The requester sets sc_ureq_sent = time_uptime when it asks for the
  update (pfsync_kstatus_to_softc, line 3297).
- The sender sets sc_ureq_received = time_uptime when the request arrives
  (pfsync_bulk_start, line 2676) and puts time_uptime - sc_ureq_received
  in the end mark (pfsync_bulk_status, line 2758).
- The requester accepts the end mark only if
  time_uptime - endtime >= sc_ureq_sent (pfsync_in_bus, line 1624).

Each side counts whole seconds of its own uptime, and the two clocks tick
over at different instants. When the sender's second ticks over during
the bulk and the requester's does not, endtime is one more than the
requester's own count and a valid mark is rejected. Example:

  requester asks at its uptime 1000.1          sc_ureq_sent = 1000
  request reaches the sender at its 5000.9     sc_ureq_received = 5000
  bulk takes 0.3 s, ends at the sender's 5001.2  endtime = 1
  end mark arrives at the requester's 1000.4   1000 - 1 = 999 < 1000: rejected

After that, the bulk fail timer armed by the start mark runs out:
4 * hz + limit / ((mtu - PFSYNC_MINPKT) / sizeof(union pfsync_state_union))
ticks. With a 2,097,152 state limit and MTU 1500 that is 703 s at
hz=1000 and 6,994 s at hz=100. pfsync_bulk_fail then asks again without
updating sc_ureq_sent, so the next end mark passes and the node
recovers. While it waits the node already holds the full state table;
only the demotion and syncok are wrong.

How often: with f the fractional part of the bulk's duration in seconds,
the share of rejected requests averaged over clock offsets is f(1 - f),
so at most 25%. For one pair of running clocks it can be up to
min(f, 1 - f). A bulk of 20,000 states took about 0.56 s on our 6-CPU
test sender, close to the worst case.

It needs two machines (two VMs are enough). Two vnet jails on one kernel
share time_uptime, so the existing pfsync tests cannot hit it.

To reproduce:
1. Two hosts with pfsync between them on a dedicated link (syncdev,
   syncpeer). CARP is not needed to see the rejection.
2. On the sender, make about 20,000 states that pfsync syncs, for example
   UDP from many source ports through a keep state rule, with long UDP
   timeouts.
3. On the requester, run "pfctl -x misc" so the verdict is printed, then
   ask for a bulk with "ifconfig pfsync0 syncdev <if> syncpeer <addr>".
   Repeat at least 5 s apart, at different points within the requester's
   uptime second (we waited for a chosen fraction of
   clock_gettime(CLOCK_UPTIME_PRECISE) before running ifconfig).
4. Some requests end with "pfsync: received invalid bulk update end: bad
   timestamp" in dmesg and syncok: 0 in "ifconfig pfsync0".

Our results, two VMs on separate hosts, requests at 20 points spread
across the requester's uptime second:
- main b3860403a (INVARIANTS, WITNESS), 20,000 states: 14 of 40 rejected;
  60,000 states: 6 of 20 rejected.
- stable/15, 20,000 states: 8 of 40 rejected.
- Forged end marks reporting the requester's wait plus 0, 1 and 2
  seconds: accepted, rejected, rejected. Wait plus 1 is what a sender
  reports when its second ticks over during the bulk, so this shows the
  problem whatever the clock offset.
With one second of slack in the comparison the same runs had no rejects,
and the forged marks gave accepted, accepted, rejected.

Our workaround meanwhile is a boot script that, while syncok is 0, asks
for the bulk again at 0.9 s into the requester's uptime second.

As on the pull request: the analysis and this report were done with the
help of an LLM. No code is attached; the numbers come from our own test
machines.

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

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-300824-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!2.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 300824] pfsync: valid bulk update end mark rejected as "bad
 timestamp" when the peers' uptime seconds tick over at different moments
Date: Mon, 16 Nov 2026 19:14:46 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300824-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="49676"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1794856486;
	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;
	bh=53eL5P4NcKpoi2URnwNUqej52xwCOHV0jCv3yZeMM4M=;
	b=xvCWGLcnqd5LLiQyt5YXKTARVRWqZAZfmn23Bh3WFEqBN3qpnJ4Mtx5qcMXAhhfltxFAJM
	Z8G1n7TJXCvDCVHPtlX0xX3jpQdaBVYRbqn/06ABtAcYfYvpROlHeD+tyhawU0J5S0ZL/0
	5c/QRFGRFhrSWKa9ZvVWUOEd/1GDSVfbvZmDogHy2SQil/xcnYuNd/9+ySIhPnodIWQE9M
	6c0hyUGjAnpSx8kFD+OhRPCRylON0oZy3ozQEQmvySG8t/+cob15NwpPDGoIbiLN9QPkQq
	zm/GqsOCZngBz9BSqnu1YJnNFMpS2dewA9blUUmd66jXMli+NesoUB0KR0EX6Q==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes