buglwIP - A Lightweight TCP/IP stack - Bugs: bug #44032, LWIP_NETCONN_FULLDUPLEX: select...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #44032: LWIP_NETCONN_FULLDUPLEX: select might work on invalid/reused socket

Submitter:  Simon Goldschmidt <goldsimon>
Submitted:  Sat 17 Jan 2015 08:18:08 PM UTC
   
 
Category:  sockets/netconn Severity:  2 - Minor
Item Group:  Feature Request Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  None
lwIP version:  git head

Jump to the original submission

Fri 24 Feb 2017 08:39:03 PM UTC, comment #8: 
Simon Goldschmidt <goldsimon>
Group administrator
Thu 16 Feb 2017 09:00:44 PM UTC, comment #7: 

Working on a reused socket can also happen on close-while-write/read (for LWIP_NETCONN_FULLDUPLEX), so we might need a more generic approach to this:

Every function holding a reference to a socket (via get_socket()) should prevent this socket being reused until it returns.

Simon Goldschmidt <goldsimon>
Group administrator
Thu 09 Feb 2017 07:41:59 PM UTC, comment #6: 

Fixed by not allowing to reallocate a socket that has "select_waiting != 0".

Simon Goldschmidt <goldsimon>
Group administrator
Mon 23 Mar 2015 07:40:48 PM UTC, comment #5: 

Thanks for the explanation Simon.  I'm not opposed to having select() return EBADF or something similar when an FD gets closed.  Just want to make sure we are adhering to the POSIX FD behaviors :)

Joel Cunningham <jcunningham>
Group Member
Tue 17 Mar 2015 07:27:36 PM UTC, comment #4: 

Joel, I understand what you mean. However, this bug is not about improving anything in the "FDs are an array index" thing. It is about not breaking this just because someone happens to call close() on a socket where select() is running. I don't think this should cause problems.

Simon Goldschmidt <goldsimon>
Group administrator
Mon 16 Mar 2015 09:50:24 PM UTC, comment #3: 

Maybe I missed the mailing list discussion of LWIP_NETCONN_FULLDUPLEX, but is that allowing multiple threads to operate on the same socket?

Even if we address the LwIP restriction of multiple threads using the same socket, there is still the long standing limitation of FDs when implemented as a simple index (restriction applies on *nix).

If you have two threads, one blocking on socket A and the other thread issues a close(A), and then a call to socket() (which returns A), now the second thread is operating on the new instance of socket A without ever knowing it was closed.

It is my understanding that best practices for FD programming involves avoiding closing a FD from a different thread than is using the FD (due to this ambiguous FD instance problem).  The select use case seems to be a violation of that best practice.

Joel Cunningham <jcunningham>
Group Member
Mon 16 Mar 2015 09:26:29 PM UTC, comment #2: 

Well, this bug report is for the new very experimental code supporting full duplex sockets only. But in that context, it is valid.

I've changed the summary to reflect this.

Simon Goldschmidt <goldsimon>
Group administrator
Mon 16 Mar 2015 09:03:27 PM UTC, comment #1: 

The use case of a blocking on a socket in select() while another thread issues a close() on that socket seems to violate LwIP's multi-threading requirements (a socket can only be used by a single thread)

Should this be closed?

Joel Cunningham <jcunningham>
Group Member
Sat 17 Jan 2015 08:18:08 PM UTC, original submission:  

When a socket gets closed and reused from another thread while select is waiting on it, 'select_waiting--' can be executed on this socket although it's not the socket where 'select_waiting++' was executed before (this mainly depends on the priorities of the threads using sockets).

To circumvent this, we could either not completely free sockets where select is waiting or add a global 'sockalloc' counter, stored per socket, which select could used to detect newly allocated sockets.

Simon Goldschmidt <goldsimon>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jcunningham (Posted a comment)
  • -email is unavailable- added by goldsimon (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-02-24 goldsimon Item GroupNone Feature Request
        StatusNone Fixed
        Open/ClosedOpen Closed
    2017-02-16 goldsimon StatusFixed None
        Open/ClosedClosed Open
    2017-02-09 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
    2015-03-16 goldsimon Summaryselect might work on invalid/reused socket LWIP_NETCONN_FULLDUPLEX: select might work on invalid/reused socket
    2015-03-04 goldsimon Severity3 - Normal 2 - Minor

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code