Bug 208121 - IPsec AH ICV Padding for IPv4
Summary: IPsec AH ICV Padding for IPv4
Status: RESOLVED PATCH_ALREADY_AVAILABLE
Alias: None
Product: Networking
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Stephen Hemminger
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-10 09:32 UTC by Markus Gasser
Modified: 2020-06-15 13:04 UTC (History)
2 users (show)

See Also:
Kernel Version: 5.4.0.37.40
Subsystem:
Regression: No
Bisected commit-id:


Attachments
packet capture (2.12 KB, application/octet-stream)
2020-06-10 09:32 UTC, Markus Gasser
Details

Description Markus Gasser 2020-06-10 09:32:26 UTC
Created attachment 289597 [details]
packet capture

According to RFC 4302[1]:

> As mentioned in Section 2.6, the ICV field may include explicit
> padding if required to ensure that the AH header is a multiple of 32
> bits (IPv4) or 64 bits (IPv6).  If padding is required, its length is
> determined by two factors:
> 
>            - the length of the ICV
>            - the IP protocol version (v4 or v6)
[...]
>    Inclusion of padding in excess of the minimum amount required to
>    satisfy IPv4/IPv6 alignment requirements is prohibited.

However, in the Linux implementation padding is always added (and expected) so that the Authentication Header (AH) is a multiple of 64 bits, independent of the IP version used. This is an issue when the IPsec AH with IPv4 is used with HMAC authentication e.g. HMAC-sha256-128. In this case the ICV field is 128 bits long, which results in an AH length of 96 + 128 = 224 bits. Even though this is a multiple of 32 bits, Linux adds an additional 32 bits of padding. Additionally, Linux drops incoming packets that do not have this padding.

In the attached file the outgoing packets, that are wrongfully padded can be seen.

[1] https://tools.ietf.org/html/rfc4302#section-3.3.3.2.1
Comment 1 Tobias Brunner 2020-06-11 08:21:18 UTC
To avoid the incorrect padding/alignment, IPv4 AH states have to be marked with the XFRM_STATE_ALIGN4 flag.
Comment 2 Herbert Xu 2020-06-15 07:23:18 UTC
Yes this was fixed years ago, please use XFRM_STATE_ALIGN4:

commit fa9921e46fd52b78070dc67ce0d27ec301a90410
Author: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date:   Wed Feb 2 06:29:02 2011 +0000

    ipsec: allow to align IPv4 AH on 32 bits
Comment 3 Markus Gasser 2020-06-15 13:04:31 UTC
Thank you for your replies, using the align4 flag indeed solves the problem.

Note You need to log in before you can comment on or make changes to this bug.