netfilter: nft_exthdr: Fix for unsafe packet data read
Subsystems (2)
Phil Sutter
reviewerPATCH v2 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.
---
Changes since v1:
- skb_copy_bits() call error handling added
--- net/netfilter/nft_exthdr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/nft_exthdr.c +3 -1
@@ -327,7 +327,9 @@ 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); +if (skb_copy_bits (pkt->skb, offset + priv->offset, + dest, priv->len) <0 ) +break ;return ; } offset +=SCTP_PAD4 (ntohs (sch->length));
Signature · 1 line
2.31.1
Quoted 9 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 followingmemcpy()may read data past temporary buffer '_sch'. Useskb_copy_bits()instead which does the right thing in this situation.Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")Suggested-by Florian Westphal <[email protected]>Signed-off-by Phil Sutter <[email protected]>
Pablo Neira Ayuso
maintainerQuoted 21 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 followingmemcpy()may read data past temporary buffer '_sch'. Useskb_copy_bits()instead which does the right thing in this situation.Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")Suggested-by Florian Westphal <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
-skb_copy_bits()call error handling added--- net/netfilter/nft_exthdr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_exthdr.c +0
-0
net/netfilter/nft_exthdr.c static void nft_exthdr_sctp_eval(const struct nft_expr *expr, · line 332
Quoted 7 lines
net/netfilter/nft_exthdr.c +3
-1@@ -327,7 +327,9 @@ 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); +if (skb_copy_bits (pkt->skb, offset + priv->offset, + dest, priv->len) <0 ) +break ;
Hm, it looks like tcp exthdt matching has the same problem?
Quoted 6 lines
net/netfilter/nft_exthdr.c +0
-0return ; } offset +=SCTP_PAD4 (ntohs (sch->length));Signature · 1 line
2.31.1
Florian Westphal
maintainerQuoted 24 lines · Pablo Neira Ayuso
Quoted 23 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 followingmemcpy()may read data past temporary buffer '_sch'. Useskb_copy_bits()instead which does the right thing in this situation.Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")Suggested-by Florian Westphal <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
-skb_copy_bits()call error handling added--- net/netfilter/nft_exthdr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_exthdr.c +0
-0@@ -327,7 +327,9 @@ static void nft_exthdr_sctp_eval(const struct nft_expr *expr,break ;
Quoted 7 lines
net/netfilter/nft_exthdr.c static void nft_exthdr_sctp_eval(const struct nft_expr *expr, · line 332
Quoted 5 lines
net/netfilter/nft_exthdr.c +3
-1dest[priv->len /NFT_REG32_SIZE ] =0 ; -memcpy (dest, (char *)sch + priv->offset, priv->len); +if (skb_copy_bits (pkt->skb, offset + priv->offset, + dest, priv->len) <0 ) +break ;Hm, it looks like tcp exthdt matching has the same problem?
Tcp exthdr either copies from skb linear area or a on-stack scratch space, it looks ok to me.
Pablo Neira Ayuso
maintainerQuoted 33 lines · Florian Westphal
Quoted 24 lines · Pablo Neira Ayuso
Quoted 23 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 followingmemcpy()may read data past temporary buffer '_sch'. Useskb_copy_bits()instead which does the right thing in this situation.Fixes 133dc203d77df ("netfilter: nft_exthdr: Support SCTP chunks")Suggested-by Florian Westphal <[email protected]>Signed-off-by Phil Sutter <[email protected]>---
Changes since v1:
-skb_copy_bits()call error handling added--- net/netfilter/nft_exthdr.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/nft_exthdr.c +0
-0@@ -327,7 +327,9 @@ static void nft_exthdr_sctp_eval(const struct nft_expr *expr,break ;Quoted 7 lines
net/netfilter/nft_exthdr.c static void nft_exthdr_sctp_eval(const struct nft_expr *expr, · line 332
Quoted 5 lines
net/netfilter/nft_exthdr.c +3
-1dest[priv->len /NFT_REG32_SIZE ] =0 ; -memcpy (dest, (char *)sch + priv->offset, priv->len); +if (skb_copy_bits (pkt->skb, offset + priv->offset, + dest, priv->len) <0 ) +break ;Hm, it looks like tcp exthdt matching has the same problem?
Quoted 2 lines
Tcp exthdr either copies from skb linear area or a on-stack scratch space, it looks ok to me.
Indeed, I overlook the nft_tcp_header_pointer() call a few lines before.
Quoted 5 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 followingmemcpy()may read data past temporary buffer '_sch'. Useskb_copy_bits()instead which does the right thing in this situation.
Applied, thanks.