All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket
@ 2020-07-29 16:38 Sabrina Dubroca
  2020-07-29 16:38 ` [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv Sabrina Dubroca
  2020-07-31  7:02 ` [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Steffen Klassert
  0 siblings, 2 replies; 4+ messages in thread
From: Sabrina Dubroca @ 2020-07-29 16:38 UTC (permalink / raw)
  To: netdev; +Cc: steffen.klassert, cagney, Sabrina Dubroca

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: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
Reported-by: Andrew Cagney <cagney@libreswan.org>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/xfrm/espintcp.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index cb83e3664680..0a91b07f2b43 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -49,9 +49,32 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
 	struct espintcp_ctx *ctx = container_of(strp, struct espintcp_ctx,
 						strp);
 	struct strp_msg *rxm = strp_msg(skb);
+	int len = rxm->full_len - 2;
 	u32 nonesp_marker;
 	int err;
 
+	/* keepalive packet? */
+	if (unlikely(len == 1)) {
+		u8 data;
+
+		err = skb_copy_bits(skb, rxm->offset + 2, &data, 1);
+		if (err < 0) {
+			kfree_skb(skb);
+			return;
+		}
+
+		if (data == 0xff) {
+			kfree_skb(skb);
+			return;
+		}
+	}
+
+	/* drop other short messages */
+	if (unlikely(len <= sizeof(nonesp_marker))) {
+		kfree_skb(skb);
+		return;
+	}
+
 	err = skb_copy_bits(skb, rxm->offset + 2, &nonesp_marker,
 			    sizeof(nonesp_marker));
 	if (err < 0) {
@@ -91,7 +114,7 @@ static int espintcp_parse(struct strparser *strp, struct sk_buff *skb)
 		return err;
 
 	len = be16_to_cpu(blen);
-	if (len < 6)
+	if (len < 2)
 		return -EINVAL;
 
 	return len;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv
  2020-07-29 16:38 [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Sabrina Dubroca
@ 2020-07-29 16:38 ` Sabrina Dubroca
  2020-07-31  7:02   ` Steffen Klassert
  2020-07-31  7:02 ` [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Steffen Klassert
  1 sibling, 1 reply; 4+ messages in thread
From: Sabrina Dubroca @ 2020-07-29 16:38 UTC (permalink / raw)
  To: netdev; +Cc: steffen.klassert, cagney, Sabrina Dubroca

Currently, espintcp_rcv drops packets silently, which makes debugging
issues difficult. Count packets as either XfrmInHdrError (when the
packet was too short or contained invalid data) or XfrmInError (for
other issues).

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/xfrm/espintcp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/xfrm/espintcp.c b/net/xfrm/espintcp.c
index 0a91b07f2b43..827ccdf2db57 100644
--- a/net/xfrm/espintcp.c
+++ b/net/xfrm/espintcp.c
@@ -15,6 +15,7 @@ static void handle_nonesp(struct espintcp_ctx *ctx, struct sk_buff *skb,
 {
 	if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf ||
 	    !sk_rmem_schedule(sk, skb, skb->truesize)) {
+		XFRM_INC_STATS(sock_net(sk), LINUX_MIB_XFRMINERROR);
 		kfree_skb(skb);
 		return;
 	}
@@ -59,6 +60,7 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
 
 		err = skb_copy_bits(skb, rxm->offset + 2, &data, 1);
 		if (err < 0) {
+			XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINHDRERROR);
 			kfree_skb(skb);
 			return;
 		}
@@ -71,6 +73,7 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
 
 	/* drop other short messages */
 	if (unlikely(len <= sizeof(nonesp_marker))) {
+		XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINHDRERROR);
 		kfree_skb(skb);
 		return;
 	}
@@ -78,17 +81,20 @@ static void espintcp_rcv(struct strparser *strp, struct sk_buff *skb)
 	err = skb_copy_bits(skb, rxm->offset + 2, &nonesp_marker,
 			    sizeof(nonesp_marker));
 	if (err < 0) {
+		XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINHDRERROR);
 		kfree_skb(skb);
 		return;
 	}
 
 	/* remove header, leave non-ESP marker/SPI */
 	if (!__pskb_pull(skb, rxm->offset + 2)) {
+		XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINERROR);
 		kfree_skb(skb);
 		return;
 	}
 
 	if (pskb_trim(skb, rxm->full_len - 2) != 0) {
+		XFRM_INC_STATS(sock_net(strp->sk), LINUX_MIB_XFRMINERROR);
 		kfree_skb(skb);
 		return;
 	}
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket
  2020-07-29 16:38 [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Sabrina Dubroca
  2020-07-29 16:38 ` [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv Sabrina Dubroca
@ 2020-07-31  7:02 ` Steffen Klassert
  1 sibling, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2020-07-31  7:02 UTC (permalink / raw)
  To: Sabrina Dubroca; +Cc: netdev, cagney

On Wed, Jul 29, 2020 at 06:38:42PM +0200, Sabrina Dubroca wrote:
> 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: e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
> Reported-by: Andrew Cagney <cagney@libreswan.org>
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Applied, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv
  2020-07-29 16:38 ` [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv Sabrina Dubroca
@ 2020-07-31  7:02   ` Steffen Klassert
  0 siblings, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2020-07-31  7:02 UTC (permalink / raw)
  To: Sabrina Dubroca; +Cc: netdev, cagney

On Wed, Jul 29, 2020 at 06:38:43PM +0200, Sabrina Dubroca wrote:
> Currently, espintcp_rcv drops packets silently, which makes debugging
> issues difficult. Count packets as either XfrmInHdrError (when the
> packet was too short or contained invalid data) or XfrmInError (for
> other issues).
> 
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>

Also applied, thanks Sabrina!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-31  7:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 16:38 [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Sabrina Dubroca
2020-07-29 16:38 ` [PATCH ipsec 2/2] espintcp: count packets dropped in espintcp_rcv Sabrina Dubroca
2020-07-31  7:02   ` Steffen Klassert
2020-07-31  7:02 ` [PATCH ipsec 1/2] espintcp: handle short messages instead of breaking the encap socket Steffen Klassert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.