Skip to content

Missing regression tests for SOCK_RAW support in standard library #115159

Description

@ncoghlan

As identified in #114887 , asyncio's support for SocketCAN regressed for a long time when datagram endpoint creation was limited specifically to SOCK_DGRAM, thus incorrectly excluding SOCK_RAW.

The other untested-but-not-deprecated-at-the-OS-level socket types (SOCK_RDM, SOCK_SEQPACKET) aren't part of any standard internet protocol, but SOCK_RAW is actively used for hardware CAN bus access, so it seems reasonable to figure out a way to cover it in the regression test suite.

The part that makes this tricky is that raw sockets are also used to craft malicious attack packets in malware, so modern operating systems restrict access to them by default. Simply attempting to create a couple of SOCK_RAW endpoints in the test suite and run some of the existing SOCK_DGRAM tests over them would routinely fail with OS permission errors.

I don't have a clear solution in mind for that problem, but the ideas I've had so far are:

  • define a new test resource for netraw (named after CAP_NET_RAW in Linux), gate SOCK_RAW tests for socket and asyncio behind that
  • for asyncio, test with an instance of a socket subclass that is SOCK_DGRAM under the hood (so no elevated permissions needed), but claims SOCK_RAW as its socket type (so it would still flush out incorrect asyncio level assumptions like create_datagram_endpoint() no longer compatible with CAN bus raw sockets  #114887 )
  • combine the two, with the latter used as a fallback testing option when the netraw resource isn't available

I don't know a clean cross-platform way to test for raw socket permissions that doesn't risk getting the test suite flagged as potential malware by behaviour monitoring systems, so the test resource seems like the best bet as a way of determining whether or not to even try creating any raw sockets.

Whether to try to test SOCK_RAW on GitHub actions and the buildbot fleet would be separate questions, but they'd need to be running in at least some locations to be useful.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtopic-socketRelated to the socket, socketserver and selectors modulestriagedThe issue has been accepted as valid by a triager.type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions