Skip to content

Commit fadd1a6

Browse files
qsnklassert
authored andcommitted
espintcp: handle short messages instead of breaking the encap socket
Currently, short messages (less than 4 bytes after the length header) will break the stream of messages. This is unnecessary, since we can still parse messages even if they're too short to contain any usable data. This is also bogus, as keepalive messages (a single 0xff byte), though not needed with TCP encapsulation, should be allowed. This patch changes the stream parser so that short messages are accepted and dropped in the kernel. Messages that contain a valid SPI or non-ESP header are processed as before. Fixes: e27cca9 ("xfrm: add espintcp (RFC 8229)") Reported-by: Andrew Cagney <[email protected]> Signed-off-by: Sabrina Dubroca <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent d5dba13 commit fadd1a6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

net/xfrm/espintcp.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,32 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
4949
struct espintcp_ctx *ctx = container_of(strp, struct espintcp_ctx,
5050
strp);
5151
struct strp_msg *rxm = strp_msg(skb);
52+
int len = rxm->full_len - 2;
5253
u32 nonesp_marker;
5354
int err;
5455

56+
/* keepalive packet? */
57+
if (unlikely(len == 1)) {
58+
u8 data;
59+
60+
err = skb_copy_bits(skb, rxm->offset + 2, &data, 1);
61+
if (err < 0) {
62+
kfree_skb(skb);
63+
return;
64+
}
65+
66+
if (data == 0xff) {
67+
kfree_skb(skb);
68+
return;
69+
}
70+
}
71+
72+
/* drop other short messages */
73+
if (unlikely(len <= sizeof(nonesp_marker))) {
74+
kfree_skb(skb);
75+
return;
76+
}
77+
5578
err = skb_copy_bits(skb, rxm->offset + 2, &nonesp_marker,
5679
sizeof(nonesp_marker));
5780
if (err < 0) {
@@ -91,7 +114,7 @@ static int espintcp_parse(struct strparser *strp, struct sk_buff *skb)
91114
return err;
92115

93116
len = be16_to_cpu(blen);
94-
if (len < 6)
117+
if (len < 2)
95118
return -EINVAL;
96119

97120
return len;

0 commit comments

Comments
 (0)