CHERIoT-Platform / CHERIoT-Platform/network-stack
UDP host access can be added after socket close
- Dominant language
- C++
- Stars
- 9
- Forks
- 14
- Avg merge
- 6d 17h
- Merged PRs (30d)
- 1
Description
1. Problem
The function first reads the socket type and local port:
```cpp
network_socket_kind(socket, kindPtr);
```
It then runs DNS:
```cpp
int ret =
network_host_resolve(timeout, host->hostname, UseIPv6, addressPtr);
```
After DNS, it adds the firewall rule using the old port, but at this point, the socket might already been freed.
```cpp
firewall_add_udpipv4_endpoint(
address.ipv4, kind.localPort, ntohs(host->port));
```
[[network_socket_udp_authorise_host()](https://github.com/CHERIoT-Platform/network-stack/blob/58425e6a1c65c4357b037aa817ba492e7a8fa70b/lib/netapi/NetAPI.cc#L220-L280)](https://github.com/CHERIoT-Platform/network-stack/blob/58425e6a1c65c4357b037aa817ba492e7a8fa70b/lib/netapi/NetAPI.cc#L220-L280)
2. Why is it bad?
Another thread can close the socket while DNS is running. Close removes the old endpoints, but this function can add a new endpoint after close has finished. If the port is reused, the rule may apply to the wrong socket.
3. Suggested fix
* DNS resolve;
* locks the socket;
* checks that it is still open and has the same port;
* adds the firewall endpoint;
* unlocks the socket.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/netapi/NetAPI.cc at network_socket_udp_authorise_host() around lines 220-280, and trace the DNS resolution, socket state, and firewall endpoint operations. Verify the socket is still open with the same port before the endpoint is added, and confirm the close-then-port-reuse scenario no longer creates an endpoint for the closed socket.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100