Page MenuHomeFreeBSD

ipsec: Use the same keysize values for HMAC as prior to r324017
ClosedPublic

Authored by cem on Oct 23 2017, 7:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Nov 7, 11:48 PM
Unknown Object (File)
Sun, Nov 3, 6:05 AM
Unknown Object (File)
Oct 4 2024, 8:16 PM
Unknown Object (File)
Oct 2 2024, 4:56 PM
Unknown Object (File)
Oct 2 2024, 2:04 AM
Unknown Object (File)
Oct 1 2024, 4:18 AM
Unknown Object (File)
Sep 29 2024, 8:22 PM
Unknown Object (File)
Sep 28 2024, 7:51 PM
Subscribers

Details

Summary

The HMAC construction natively permits any key size between 0 and the input
block length. Before r324017, the auth_hash 'keysize' member was the hash
output length, which was used by ipsec for key sizes. (Non-ipsec consumers
need the ability to use other keysizes, hence, r324017.)

The ipsec SADB code blindly uses the auth_hash 'keysize' member for both
minimum and maximum key size, which is wrong (from an HMAC perspective).
For now, just switch it to 'hashsize', which matches the existing
expectations.

Instead it should probably use the range [0, keysize]. But there may be
other broken code in ipsec that rejects hashes with too small a minimum
key size.

Reported by: olivier@

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 12308
Build 12597: arc lint + arc unit

Event Timeline

This comment was removed by olivier.
This revision is now accepted and ready to land.Oct 25 2017, 1:10 PM

After more test there is still a problem somewhere: I'm digging it and will add more information.

After more test there is still a problem somewhere: I'm digging it and will add more information.

Thanks, let me know what you find! The alternative patch should restore the prior behavior for key_getsizes_ah exactly:

-*min = *max = ah->keysize;
+*min = *max = ah->hashsize;

But maybe the issue is somewhere else? Let me know if I can help.

After more test: Your patch correctly fix aes-cbc key length.

I was confuse because I hit a new regression between r324017 and r324972 regarding aes-gcm not related to this review.

Config set aes-cbc:

flush;
spdflush;
spdadd 198.18.0.0/16 198.19.0.0/16 any -P out ipsec esp/tunnel/198.18.1.208-198.18.1.210/require;
spdadd 198.19.0.0/16 198.18.0.0/16 any -P in ipsec esp/tunnel/198.18.1.210-198.18.1.208/require;
add 198.18.1.208 198.18.1.210 esp 0x1000 -E rijndael-cbc "1234567890123456" -A hmac-sha1 "12345678901234567890";
add 198.18.1.210 198.18.1.208 esp 0x1001 -E rijndael-cbc "1234567890123456" -A hmac-sha1 "12345678901234567890";

Config set aes-gcm:

flush;
spdflush;
spdadd 198.18.0.0/16 198.19.0.0/16 any -P out ipsec esp/tunnel/198.18.1.208-198.18.1.210/require;
spdadd 198.19.0.0/16 198.18.0.0/16 any -P in ipsec esp/tunnel/198.18.1.210-198.18.1.208/require;
add 198.18.1.208 198.18.1.210 esp 0x1000 -E aes-gcm-16 "12345678901234567890";
add 198.18.1.210 198.18.1.208 esp 0x1001 -E aes-gcm-16 "12345678901234567890";

Test results: Configuration load and packet encryption.

SourceDestinationConfig set aes-cbc resultConfig set aes-gcm result
fbsd 11.1fbsd 11.1OKOK
r324016fbsd 11.1OKOK
r324016r324016OKOK
r324017fbsd 11.1Invalid key length on sourceOK
r324017 with D12770fbsd 11.1OKOK
r324972 with D12770fbsd 11.1OKNOK: netstat display "packets dropped; no transform" on destination
r324972 with D12770fbsd 11.1OKNOK: netstat display "packets dropped; no transform" on destination

Did you try without aesni module loaded?

In D12770#265548, @ae wrote:
r324972 with D12770fbsd 11.1OKNOK: netstat display "packets dropped; no transform" on destination

Did you try without aesni module loaded?

Here are the result:

source: head r324972destination: 11.1Result regarding aes-gcm
aesniaesniAll packets refused at destination: netstat display "packets dropped; no transform" on destination
no aesnino aesniVery few packets accepted, almost ALL packets are corrupted once decrypted

Without aesni loaded on both side, netstat on destination display this:

esp:
        55 packets dropped; no TDB
        1504160 packets dropped; bad encryption detected
        1516933 packets in
        806979096 bytes in
        ESP output histogram:
                aes-gcm-16: 1516878

I've found the commit that broke AES-GCM: r324037 "aesni(4): Add support for x86 SHA intrinsics".
But how is possible that I'm impacted without loading aesni module ?!?

[root@SM1]~# kldstat -v | grep aesni
=> Nothing displayed

@ae , is this change ok? Or would you prefer we set min/max to the exact same values as before (now ah->hashsize)?

sys/netipsec/key.c
6316

If we set minsize to zero, will this check now become functional and will reject all algorithms?

sys/netipsec/key.c
6316

I think this may affect IKE daemons, Olivier seems does his tests without IKE.

I confirm: I'm using static key only on my tests.

And about my (unrelated) aes-gcm problem without aesni… It seems my old bug (July 2015) resurfaced and if it's the same, this impact even all FreeBSD 11.X branch: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=201447

sys/netipsec/key.c
6316

Shouldn't this check be if (_BITS(maxkeysize) < V_ipsec_ah_keymin) instead?

I am happy to make the more conservative change for now, though.

Switch to the more conservative change (just use hashsize)

This revision now requires review to proceed.Oct 30 2017, 4:26 PM
cem retitled this revision from ipsec: Allow a range of keysizes supported by HMAC to ipsec: Use the same keysize values for HMAC as prior to r324017.Oct 30 2017, 4:27 PM
cem edited the summary of this revision. (Show Details)
cem edited the test plan for this revision. (Show Details)

If this is consensus, I'd like to go ahead and commit this change. Any objection?

If it restores the old behavior, I have no objection

This revision is now accepted and ready to land.Nov 15 2017, 8:35 PM
This revision was automatically updated to reflect the committed changes.