🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.bugs.dist
Article #3059

Bug#1153009: pxelinux: delayed TFTP replies can abort a later file request

#3059
From: Gianluigi Tiesi
Date: Wed, 04 Nov 2026 11:50
128 lines
6130 bytes
This is a multi-part MIME message sent by reportbug.


--===============5518260027136427384==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Package: syslinux
Version: 3:6.04~git20190206.bf6db5b4+dfsg1-3.2
Severity: normal
Tags: patch upstream
X-Debbugs-Cc: sherpya@gmail.com

lpxelinux's UDP allocator immediately reuses a closed socket's port.
A delayed TFTP error for a missing config can then reach a later request,
causing an existing config to be treated as missing.

Reproduced in QEMU by delaying a missing-file error until the request for
pxelinux.cfg/default. Keeping an allocator cursor avoids the collision;
the same test then loads default successfully. Allocation also handles
occupied ports, wraparound and exhaustion.

Patch: 0022-lpxelinux-rotate-udp-ports.patch
AI assistance was used for debugging, the patch and this report.


-- System Information:
Debian Release: forky/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 7.2.15+deb14-amd64 (SMP w/12 CPU threads; PREEMPT)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_USER, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages syslinux depends on:
ii  libc6   2.43-7
ii  mtools  4.0.49-1

Versions of packages syslinux recommends:
ii  syslinux-common  3:6.04~git20190206.bf6db5b4+dfsg1-3.2

Versions of packages syslinux suggests:
ii  dosfstools  4.2-1.2

-- no debconf information

--===============5518260027136427384==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="0022-lpxelinux-rotate-udp-ports.patch"

Description: lpxelinux: avoid immediate reuse of ephemeral UDP ports
 Keep an allocator cursor so delayed TFTP replies do not reach the next
 file request after its predecessor closes. Check occupied ports and wrap
 within the configured range.
Origin: other, local debugging with AI assistance
Forwarded: no
Last-Update: 2026-11-03

--- a/core/lwip/src/core/udp.c
+++ b/core/lwip/src/core/udp.c
@@ -685,7 +685,7 @@
  * @param ipaddr local IP address to bind with. Use IP_ADDR_ANY to
  * bind to all local interfaces.
  * @param port local UDP port to bind with. Use 0 to automatically bind
- * to a random port between UDP_LOCAL_PORT_RANGE_START and
+ * to an available port between UDP_LOCAL_PORT_RANGE_START and
  * UDP_LOCAL_PORT_RANGE_END.
  *
  * ipaddr & port are expected to be in the same byte order as in the pcb.
@@ -751,24 +751,30 @@
 #define UDP_LOCAL_PORT_RANGE_START  0xc000
 #define UDP_LOCAL_PORT_RANGE_END    0xffff
 #endif
-    port = UDP_LOCAL_PORT_RANGE_START;
-    ipcb = udp_pcbs;
-    while ((ipcb != NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
-      if (ipcb->local_port == port) {
-        /* port is already used by another udp_pcb */
-        port++;
-        /* restart scanning all udp pcbs */
-        ipcb = udp_pcbs;
-      } else {
-        /* go on with next udp pcb */
-        ipcb = ipcb->next;
-      }
-    }
-    if (ipcb != NULL) {
-      /* no more ports available in local range */
-      LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
-      return ERR_USE;
-    }
+    static u16_t next_port = UDP_LOCAL_PORT_RANGE_START;
+    u16_t first_port = next_port;
+
+    /* Do not immediately reuse a closed socket's port: delayed TFTP
+       replies must not be delivered to the next file request. */
+    port = first_port;
+    for (;;) {
+      for (ipcb = udp_pcbs; ipcb != NULL; ipcb = ipcb->next) {
+        if (ipcb->local_port == port)
+          break;
+      }
+      if (ipcb == NULL)
+        break;
+
+      port = port == UDP_LOCAL_PORT_RANGE_END ?
+        UDP_LOCAL_PORT_RANGE_START : port + 1;
+      if (port == first_port) {
+        /* no more ports available in local range */
+        LWIP_DEBUGF(UDP_DEBUG, ("udp_bind: out of free UDP ports\n"));
+        return ERR_USE;
+      }
+    }
+    next_port = port == UDP_LOCAL_PORT_RANGE_END ?
+      UDP_LOCAL_PORT_RANGE_START : port + 1;
   }
   pcb->local_port = port;
   snmp_insert_udpidx_tree(pcb);

--===============5518260027136427384==--
Technical Details
Message-ID: <NVHF8-9N8v-11@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.datentrampelpfad.de!news.imp.ch!news.corradoroberto.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.datentrampelpfad.de!news.imp.ch!news.corradoroberto.it!bofh.it!news.nic.it!robomod
From: Gianluigi Tiesi <sherpya@gmail.com>
Newsgroups: linux.debian.bugs.dist,linux.debian.devel.cd
Subject: Bug#1153009: pxelinux: delayed TFTP replies can abort a later file request
Date: Wed, 04 Nov 2026 12:50:02 +0100
Message-ID: <NVHF8-9N8v-11@gated-at.bofh.it>
X-Mailbox-Line: From debian-bugs-dist-request@lists.debian.org  Wed Nov  4 11:45:07 2026
Old-Return-Path: <debbugs@buxtehude.debian.org>
X-Spam-Flag: NO
X-Spam-Score: 3.5
Reply-To: Gianluigi Tiesi <sherpya@gmail.com>, 1153009@bugs.debian.org
Resent-To: debian-bugs-dist@lists.debian.org
Resent-Cc: sherpya@gmail.com, debian-cd@lists.debian.org
X-Debian-Pr-Message: report 1153009
X-Debian-Pr-Package: syslinux
X-Debian-Pr-Keywords: patch upstream
X-Debian-Pr-Source: syslinux
Content-Type: multipart/mixed; boundary="===============5518260027136427384=="
MIME-Version: 1.0
X-Mailer: reportbug 13.2.0+nmu1
X-Debian-Message: from BTS
X-Mailing-List: <debian-bugs-dist@lists.debian.org> archive/latest/2000596
List-ID: <debian-bugs-dist.lists.debian.org>
List-URL: <https://lists.debian.org/debian-bugs-dist/>
Approved: robomod@news.nic.it
Lines: 128
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Wed, 04 Nov 2026 12:43:20 +0100
X-Original-Message-ID: <179379260040.17987.11475128929438018397.reportbug@esperia.localdomain>