Repository navigation
esp32: Drain PPP input before destroying the netif - #2471
Open
gabrielmancini wants to merge 1 commit into
Open
gabrielmancini wants to merge 1 commit into
gabrielmancini wants to merge 1 commit into
Conversation
When a PPP session is freed, the RX task has stopped, but input it queued for the TCP/IP task may still point at the netif. With CONFIG_LWIP_TCPIP_CORE_LOCKING enabled, esp_netif_destroy runs at once rather than behind that input, which then reaches a freed netif. free_ppp now posts a callback through the TCP/IP mailbox, which is FIFO, and waits for it before destroying the netif. Not esp_netif_tcpip_exec or tcpip_callback_wait: under core locking both run inline. If the callback cannot be posted, the session is left allocated rather than freed under queued input, and the late-close log line no longer says "freed". Signed-off-by: Gabriel Mancini <gabriel.mancini@gmail.com>
bettio
approved these changes
Nov 11, 2026
Collaborator
|
This PR has been approved and merged locally, do not make changed, do not push here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2461, for the P2 in @petermm's review (#2461 (comment)). That PR was merged as approved, so the fix comes separately.
When a PPP session is freed, the RX task has already stopped, but input it queued for the TCP/IP task may still point at the netif. With
CONFIG_LWIP_TCPIP_CORE_LOCKING=y(and_INPUT=n),esp_netif_destroyruns at once instead of behind that input, which then reaches a freed netif.free_pppnow posts a callback through the TCP/IP mailbox, which is FIFO, and waits for it before destroying the netif. It reuses thestoppedsemaphore.esp_netif_tcpip_execandtcpip_callback_waitwould not work here: under core locking both run inline. None offree_ppp's callers (network:stop/0, a failed start, the late-close teardown task) runs on the TCP/IP task, so the wait cannot deadlock. If the callback cannot be posted, the session is left allocated rather than freed under queued input.Tested on a T-Vending (ESP32-S3, SIM7600 on LTE). Each of 20 cycles dials, brings PPP up, starts an HTTP download and calls
network:stop/0in the middle of it, with UART input still queued:stopmax / meanNo
CORRUPT HEAP, assert, Guru Meditation or reboot. The first build is the configuration in which the use-after-free would show.These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later