IPComp fixes
Subsystems (4)
v3 cover IPComp fixes
Hi,
This patchset includes bug fix focusing on IPComp mainly, which addresses IPComp Compression Parameter Index(CPI, 16bits of 32bits SPI value) problem.
And other issue is the compression part, undesirable packet will not be compressed, and then send into wire, this packet will be dropped by policy checking in the receiver side.
v2:
Patch1: Clean up align issue from v1.
Patch2: Introduce verify_userspi_info for pkfey and netlink interface
to share code.
Patch3: Add Documentation/networking/ipsec.txt to document known issues.
v3:
Patch2: Fix while space error.
Patch3: Del empty line
Fan Du (3):
xfrm: check user specified spi for IPComp
xfrm: export verify_userspi_info for pkfey and netlink interface
xfrm: Add file to document IPsec corner case
Documentation/networking/ipsec.txt | 38 ++++++++++++++++++++++++++++++++++++ include/net/xfrm.h | 1 + net/key/af_key.c | 6 ++++++ net/xfrm/xfrm_state.c | 24 +++++++++++++++++++++++ net/xfrm/xfrm_user.c | 29 ++++----------------------- 5 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 Documentation/networking/ipsec.txt
Signature · 1 line
1.7.9.5
PATCH v3 1/3 xfrm: check user specified spi for IPComp
IPComp connection between two hosts is broken if given spi bigger than 0xffff.
OUTSPI=0x87
INSPI=0x11112
ip xfrm policy update dst 192.168.1.101 src 192.168.1.109 dir out action allow \
tmpl dst 192.168.1.101 src 192.168.1.109 proto comp spi $OUTSPI
ip xfrm policy update src 192.168.1.101 dst 192.168.1.109 dir in action allow \
tmpl src 192.168.1.101 dst 192.168.1.109 proto comp spi $INSPIip xfrm state add src 192.168.1.101 dst 192.168.1.109 proto comp spi $INSPI \
comp deflate
ip xfrm state add dst 192.168.1.101 src 192.168.1.109 proto comp spi $OUTSPI \
comp deflate
tcpdump can capture outbound ping packet, but inbound packet is dropped with XfrmOutNoStates errors. It looks like spi value used for IPComp is expected to be 16bits wide only.
--- net/xfrm/xfrm_user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_user.c +3 -1
@@ -181,7 +181,9 @@ static int verify_newsa_info(struct xfrm_usersa_info *p, attrs[XFRMA_ALG_AEAD ] || attrs[XFRMA_ALG_CRYPT ] || attrs[XFRMA_ALG_COMP ] || - attrs[XFRMA_TFCPAD]) + attrs[XFRMA_TFCPAD ] || + (ntohl(p->id.spi) >= 0x10000)) + goto out;break ;
Signature · 1 line
1.7.9.5
PATCH v3 2/3 xfrm: export verify_userspi_info for pkfey and netlink interface
In reply to Fan DuIn order to check against valid IPcomp spi range, export verify_userspi_info for both pfkey and netlink interface.
--- include/net/xfrm.h | 1 + net/key/af_key.c | 6 ++++++ net/xfrm/xfrm_state.c | 24 ++++++++++++++++++++++++ net/xfrm/xfrm_user.c | 25 +------------------------ 4 files changed, 32 insertions(+), 24 deletions(-)
include/net/xfrm.h +1 -0
@@ -1564,6 +1564,7 @@ struct xfrm_policy *xfrm_policy_byid(struct net *net, u32 mark, u8, int dir, u32 id, int delete, int *err);int xfrm_policy_flush (struct net *net,u8 type,struct xfrm_audit *audit_info);u32 xfrm_get_acqseq (void ); +int verify_spi_info (u8 proto,u32 min,u32 max);int xfrm_alloc_spi (struct xfrm_state *x,u32 minspi,u32 maxspi); struct xfrm_state *xfrm_find_acq(struct net *net, const struct xfrm_mark *mark, u8 mode, u32 reqid, u8 proto,
net/key/af_key.c +6 -0
@@ -1340,6 +1340,12 @@ static int pfkey_getspi(struct sock *sk, struct sk_buff *skb, const struct sadb_ max_spi = range->sadb_spirange_max; } + err =verify_spi_info (x->id.proto, min_spi, max_spi); +if (err) { +xfrm_state_put (x); +return err; + } + err =xfrm_alloc_spi (x, min_spi, max_spi); resp_skb = err ?ERR_PTR (err) :pfkey_xfrm_state2msg (x);
net/xfrm/xfrm_state.c +24 -0
@@ -1496,6 +1496,30 @@ u32 xfrm_get_acqseq(void) }EXPORT_SYMBOL (xfrm_get_acqseq); +int verify_spi_info (u8 proto,u32 min,u32 max) +{ +switch (proto) { +case IPPROTO_AH : +case IPPROTO_ESP : +break ; + +case IPPROTO_COMP : +/* IPCOMP spi is 16-bits. */ +if (max >=0x10000 ) +return -EINVAL ; +break ; + +default : +return -EINVAL ; + } + +if (min > max) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL (verify_spi_info); +int xfrm_alloc_spi (struct xfrm_state *x,u32 low,u32 high) {struct net *net =xs_net (x);
net/xfrm/xfrm_user.c +1 -24
@@ -1076,29 +1076,6 @@ out_noput:return err; } -static int verify_userspi_info (struct xfrm_userspi_info *p) -{ -switch (p->info.id.proto) { -case IPPROTO_AH : -case IPPROTO_ESP : -break ; - -case IPPROTO_COMP : -/* IPCOMP spi is 16-bits. */ -if (p->max >=0x10000 ) -return -EINVAL ; -break ; - -default : -return -EINVAL ; - } - -if (p->min > p->max) -return -EINVAL ; - -return 0 ; -} -static int xfrm_alloc_userspi (struct sk_buff *skb,struct nlmsghdr *nlh,struct nlattr **attrs) {
@@ -1113,7 +1090,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,struct xfrm_mark m; p =nlmsg_data (nlh); - err =verify_userspi_info (p); + err =verify_spi_info (p->info.id.proto, p->min, p->max);if (err) goto out_noput;
Signature · 1 line
1.7.9.5
PATCH v3 3/3 xfrm: Add file to document IPsec corner case
In reply to Fan DuCreate Documentation/networking/ipsec.txt to document IPsec corner issues and other info, which will be useful when user deploying IPsec.
--- Documentation/networking/ipsec.txt | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/networking/ipsec.txt
Documentation/networking/ipsec.txt new file +38 -0
@@ -0,0 +1,38 @@ + +Here documents known IPsec corner cases which need to be keep in mind when +deploy various IPsec configuration in real world production environment. + +1. IPcomp: Small IP packet won't get compressed at sender, and failed on + policy check on receiver. + +Quote from RFC3173: +2.2. Non-Expansion Policy + + If the total size of a compressed payload and the IPComp header, as + defined in section 3, is not smaller than the size of the original + payload, the IP datagram MUST be sent in the original non-compressed + form. To clarify: If an IP datagram is sent non-compressed, no + + IPComp header is added to the datagram. This policy ensures saving + the decompression processing cycles and avoiding incurring IP + datagram fragmentation when the expanded datagram is larger than the + MTU. + + Small IP datagrams are likely to expand as a result of compression. + Therefore, a numeric threshold should be applied before compression, + where IP datagrams of size smaller than the threshold are sent in the + original form without attempting compression. The numeric threshold + is implementation dependent. + +Current IPComp implementation is indeed by the book, while as in practice +when sending non-compressed packet to the peer(whether or not packet len +is smaller than the threshold or the compressed len is large than original +packet len), the packet is dropped when checking the policy as this packet +matches the selector but not coming from any XFRM layer, i.e., with no +security path. Such naked packet will not eventually make it to upper layer. +The result is much more wired to the user when ping peer with different +payload length. + +One workaround is try to set "level use" for each policy if user observed +above scenario. The consequence of doing so is small packet(uncompressed) +will skip policy checking on receiver side.
Signature · 1 line
1.7.9.5
Steffen Klassert
maintainerQuoted 15 lines · Fan Du
Hi,
This patchset includes bug fix focusing on IPComp mainly, which addresses IPComp Compression Parameter
Index(CPI, 16bits of 32bits SPI value)problem.And other issue is the compression part, undesirable packet will not be compressed, and then send into wire, this packet will be dropped by policy checking in the receiver side.
v2:
Patch1: Clean up align issue from v1.
Patch2: Introduceverify_userspi_infofor pkfey and netlink interface
to share code.
Patch3: AddDocumentation/networking/ipsec.txtto document known issues.
Quoted 9 lines
v3:
Patch2: Fix while space error.
Patch3: Del empty lineFan Du (3):
xfrm: check user specified spi for IPComp
xfrm: exportverify_userspi_infofor pkfey and netlink interface
xfrm: Add file to document IPsec corner case
All applied to ipsec-next, thanks Fan!