Skip to content

Nftables port forwarding rules leak when passing both generic (-p 8080:8080) and IPv6 wildcard (-p '[::]:8080:8080') #1338

@danishprakash

Description

@danishprakash

When using both -p 8080:8080 -p '[::]:8080:8080, netavark doesn't clean up nft chains and leaves them behind, causing problems with subsequent container runs, and port blocking.

The core issues seem to be how netavark handles port forwards when both the generic and IPv6 wildcard options are passed. In this case, duplicate dnat chains are generated for IPv6(first from the generic wildcard, and then from the IPv6 wildcard), but then netavark fails to clean up both IPv[4|6] rules, resulting in a leak. I'd expect on a container removal, all container rules are cleared. Additionally, removing the said network doesn't clear up the leaked rules either.

Reproducer (by ondrej)
podman network create test_net --ipv6
nft list table inet netavark
podman run -d \
    --name netavark-test-container \
    --rm -it \
    --network test_net \
    -p 8080:8080 \
    -p [::]:8080:8080 \
    alpine /bin/sh -c 'sleep 2'
sleep 2
nft list table inet netavark

Noticing the following errors in debug log while removing the container--container cleanup:

internal:0:0-0: Error: Could not process rule: No such file or directory

internal:0:0-0: Error: Could not process rule: No such file or directory

internal:0:0-0: Error: Could not process rule: No such file or directory

internal:0:0-0: Error: Could not process rule: No such file or directory

internal:0:0-0: Error: Could not process rule: No such file or directory

internal:0:0-0: Error: Could not process rule: No such file or directory

I tried deleting all the matching rules and even deduplicating them before processing with limited success. I'm still looking into a potential patch here. Ideally, either do not create the duplicate rules at all in such a situation or consider the IPv6 wildcard a no-op when a dual-stack generic wildcard port forward option is passed.

Environment
openSUSE Tumbleweed (Slowroll)
netavark latest main (and v1.16, and v1.15)
nftables v1.1.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions