generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Valid IPv6 input may cause 'ipsubnet' filter to attempt to create 2 ^ 128 values #132
Comments
This was referenced Jan 24, 2022
This was referenced Nov 3, 2022
Closed
Closed
ghost
mentioned this issue
Nov 5, 2022
1 task
1 task
This was referenced Nov 5, 2022
Merged
This was referenced Nov 16, 2022
Closed
Closed
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SUMMARY
The
"2600:1f1c:1b3:8f00::/56" | ipsubnet(120, 0)
filter never returns. Internally, the filter invokes thenetaddr.subnet
function, which attempts to create 18446744073709551616 values.The
ipsubnet
filter creates a IPNetwork with "2600:1f1c:1b3:8f00::/56" and prefix length 120.The
ipsubnet
filter invokes thenetaddr.subnet
function at https://github.com/ansible-collections/ansible.utils/blob/main/plugins/filter/ipsubnet.py#L283)
In the
netaddr
module, the subnet() function calculates the max number of subnets:If the network prefix is /56 and the prefix length is /120, then max_subnets = 18446744073709551616.
In the worst case, the network address is /0 and the prefix length is 128, then max_subnets = 2 ^ 128 // 2 ^ 0, which is 2 ^ 128. If the
count
argument is set to 0, this will cause unbounded CPU usage and memory allocation.So
netaddr.subnet
never returns.ISSUE TYPE
COMPONENT NAME
ipsubnet filter
ANSIBLE VERSION
I have pasted the output below, but the problem is reproduced when running unit tests in the
main
branch ofansible.utils
module as of 01/24/2022.COLLECTION VERSION
Because the problem is exposed when running the test_ipsubnet.py unit tests inside a docker image, the applicable collections and configuration is what's inside the docker container. I'm not sure how to get that information. But see summary, I think the problem can be root caused to a specific line in the
ipsubnet
function in the main branch.CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
Checkout the code from #131, then run the following command:
The following filter never completes:
"2600:1f1c:1b3:8f00::/56" | ipsubnet(120, 0)
The problem gets worse when the network prefix has a smaller value and the first argument of
ipsubnet
has a higher value. In the worst case, this would cause 2 ^ 128 iterations.EXPECTED RESULTS
"2600:1f1c:1b3:8f00::/56" | ipsubnet(120, 0)
should return2600:1f1c:1b3:8f00::/120
"2600:1f1c:1b3:8f00::/56" | ipsubnet(120, 4)
should return2600:1f1c:1b3:8f00::400/120
This could be calculated in constant time. Instead, the
ipsubnet
filter attempts to create all possible subnets, then get the subnet at index X. However, the list of all subnets could be 2 ^ 128 in the worst case.ACTUAL RESULTS
The
ipsubnet
filter never returns. It iterates through a very large number of elements and never returns.The text was updated successfully, but these errors were encountered: