Skip to contentSkip to conversation

netfilter: nft_exthdr: Fix for unsafe packet data read

PATCH Superseded Phil Sutter 2 participants 2 messages Jun 8, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 netfilter: nft_exthdr: Fix for unsafe packet data read

While iterating through an SCTP packet's chunks, skb_header_pointer() is called for the minimum expected chunk header size. If (that part of) the skbuff is non-linear, the following memcpy() may read data past temporary buffer '_sch'. Use skb_copy_bits() instead which does the right thing in this situation.

Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")
---
 net/netfilter/nft_exthdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_exthdr.c +2 -1
index 1b0579cb62d08..2b976687510d8 100644
@@ -327,7 +327,8 @@ static void nft_exthdr_sctp_eval(const struct nft_expr *expr,
 				break;
 
 			dest[priv->len / NFT_REG32_SIZE] = 0;
-			memcpy(dest, (char *)sch + priv->offset, priv->len);
+			skb_copy_bits(pkt->skb, offset + priv->offset,
+				      dest, priv->len);
 			return;
 		}
 		offset += SCTP_PAD4(ntohs(sch->length));
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 18 lines · Phil Sutter

While iterating through an SCTP packet's chunks, skb_header_pointer() is called for the minimum expected chunk header size. If (that part of) the skbuff is non-linear, the following memcpy() may read data past temporary buffer '_sch'. Use skb_copy_bits() instead which does the right thing in this situation.

Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")
---
 net/netfilter/nft_exthdr.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nft_exthdr.c +0 -0
index 1b0579cb62d08..2b976687510d8 100644

net/netfilter/nft_exthdr.c static void nft_exthdr_sctp_eval(const struct nft_expr *expr, · line 331

Quoted 6 lines
net/netfilter/nft_exthdr.c +2 -1
@@ -327,7 +327,8 @@ static void nft_exthdr_sctp_eval(const struct nft_expr *expr,
 				break;
 
 			dest[priv->len / NFT_REG32_SIZE] = 0;
-			memcpy(dest, (char *)sch + priv->offset, priv->len);
+			skb_copy_bits(pkt->skb, offset + priv->offset,
+				      dest, priv->len);

can you 'goto err' when this fails just like other callers in the same file?

Thanks!