Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call pbuf_free when ethernet_input is Ok #2828

Open
1 task done
Slion opened this issue Oct 4, 2024 · 3 comments
Open
1 task done

Don't call pbuf_free when ethernet_input is Ok #2828

Slion opened this issue Oct 4, 2024 · 3 comments
Labels

Comments

@Slion
Copy link
Contributor

Slion commented Oct 4, 2024

Operating System

Others

Board

Raspberry Pi Pico WH

Firmware

net_lwip_webserver

What happened ?

If you call pbuf_free on the frame when ethernet_input returns ERR_OK you will get either panic with assert pbuf_free: p->ref > 0 or worst steal the buffer ownership from the HTTP server.

How to reproduce ?

Try run net_lwip_webserver on Pico.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

Sorry won't bother, description is good enough.

Screenshots

lwIP ticket: https://savannah.nongnu.org/patch/index.php?10121
See example of how it should be done: https://github.com/lwip-tcpip/lwip/blob/master/contrib/examples/ethernetif/ethernetif.c
Here is the faulty code:

pbuf_free(received_frame);

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@Slion Slion added the Bug 🐞 label Oct 4, 2024
@HiFiPhile
Copy link
Collaborator

Hi, only few of mainteners are good at lwip, do you any suggestion how to fix it ?

@Slion
Copy link
Contributor Author

Slion commented Oct 4, 2024

Hi, only few of mainteners are good at lwip, do you any suggestion how to fix it ?

/// @brief Perform network tasks, process packets
/// @param
void service_traffic(void)
{
    /* handle any packet received by tud_network_recv_cb() */
    if (received_frame)
    {
        // Surrender ownership of our pbuf unless there was an error
        // Only call pbuf_free if not Ok else it will panic with "pbuf_free: p->ref > 0" 
        // or steal it from whatever took ownership of it with undefined consequences.
        // See: https://savannah.nongnu.org/patch/index.php?10121
        if (ethernet_input(received_frame, &netif_data)!=ERR_OK) {
            pbuf_free(received_frame);
        }
        received_frame = NULL;
        tud_network_recv_renew();
    }

    sys_check_timeouts();
}

@HiFiPhile
Copy link
Collaborator

Thank you , PR is on: #2829

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants