isakmp: validate item_len before subtracting sizeof(ikev2_auth)#1440
Open
vmihalis wants to merge 1 commit into
Open
isakmp: validate item_len before subtracting sizeof(ikev2_auth)#1440vmihalis wants to merge 1 commit into
vmihalis wants to merge 1 commit into
Conversation
In ikev2_auth_print(), item_len is read from the packet and used
directly in the subtraction:
item_len - sizeof(struct ikev2_auth)
The caller only guarantees item_len > 4, but sizeof(struct ikev2_auth)
is 8. When item_len is 5, 6 or 7, the subtraction underflows and
produces a large value that is then passed as the length argument to
rawprint().
This is the same issue that was fixed in the sibling function
ikev2_ID_print() by commit 06db083 ("isakmp: validate item_len
before subtracting sizeof(ikev2_id)"); ikev2_auth_print() has the
identical construct and was left unchanged.
Add an explicit bounds check before the subtraction and print
'[payload too short]' when item_len is less than
sizeof(struct ikev2_auth), mirroring the ikev2_ID_print() fix.
Add regression tests for both the normal and the underflow cases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ikev2_auth_print()inprint-isakmp.csubtractssizeof(struct ikev2_auth)(8 bytes) from the packet-supplied
item_lenwithout first checking thatitem_lenis large enough:The caller only guarantees
item_len > 4. Whenitem_lenis 5, 6 or 7,item_len - sizeof(struct ikev2_auth)underflows to a large unsigned valuethat is then passed as the length argument to
rawprint().This is the same pattern that commit 06db083 ("isakmp: validate item_len
before subtracting sizeof(ikev2_id)") fixed in the sibling function
ikev2_ID_print().ikev2_auth_print()has the identical construct and wasleft unchanged.
Impact
This is a defense-in-depth / consistency fix, not a crash fix. The underflowed
length reaches only
rawprint(), whose first action isND_TCHECK_LEN(); thatbounds check fails closed on the oversized value and longjmps to the truncation
handler, so no out-of-bounds read occurs today. The change makes the bounds
check explicit at the subtraction site and brings
ikev2_auth_print()in linewith the fix already applied to
ikev2_ID_print().Fix
Add an explicit lower-bound check before the subtraction, mirroring
ikev2_ID_print():Testing
./autogen.sh && ./configure && makebuilds cleanly.ikev2-id-{normal,short}testsfrom commit 06db083:
ikev2-auth-normal-- a valid IKEv2 AUTH payload; output unchanged.ikev2-auth-short-- an AUTH payload withitem_len= 5; output is now[payload too short].existing test result, and both new tests pass.