All of lore.kernel.org
 help / color / mirror / Atom feed
* [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
@ 2021-06-08  9:40 Phil Sutter
  2021-06-08  9:43 ` Florian Westphal
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Phil Sutter @ 2021-06-08  9:40 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, Florian Westphal

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")
Suggested-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- skb_copy_bits() call error handling added
---
 net/netfilter/nft_exthdr.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
index 1b0579cb62d08..7f705b5c09de8 100644
--- a/net/netfilter/nft_exthdr.c
+++ b/net/netfilter/nft_exthdr.c
@@ -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));
-- 
2.31.1


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

* Re: [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
  2021-06-08  9:40 [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read Phil Sutter
@ 2021-06-08  9:43 ` Florian Westphal
  2021-06-08  9:56 ` Pablo Neira Ayuso
  2021-06-08 10:38 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 6+ messages in thread
From: Florian Westphal @ 2021-06-08  9:43 UTC (permalink / raw)
  To: Phil Sutter; +Cc: Pablo Neira Ayuso, netfilter-devel, Florian Westphal

Phil Sutter <phil@nwl.cc> wrote:
> 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")
> Suggested-by: Florian Westphal <fw@strlen.de>
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Reviewed-by: Florian Westphal <fw@strlen.de>

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

* Re: [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
  2021-06-08  9:40 [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read Phil Sutter
  2021-06-08  9:43 ` Florian Westphal
@ 2021-06-08  9:56 ` Pablo Neira Ayuso
  2021-06-08 10:07   ` Florian Westphal
  2021-06-08 10:38 ` Pablo Neira Ayuso
  2 siblings, 1 reply; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-06-08  9:56 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel, Florian Westphal

On Tue, Jun 08, 2021 at 11:40:57AM +0200, Phil Sutter wrote:
> 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")
> Suggested-by: Florian Westphal <fw@strlen.de>
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> Changes since v1:
> - skb_copy_bits() call error handling added
> ---
>  net/netfilter/nft_exthdr.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
> index 1b0579cb62d08..7f705b5c09de8 100644
> --- a/net/netfilter/nft_exthdr.c
> +++ b/net/netfilter/nft_exthdr.c
> @@ -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?

>  			return;
>  		}
>  		offset += SCTP_PAD4(ntohs(sch->length));
> -- 
> 2.31.1
> 

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

* Re: [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
  2021-06-08  9:56 ` Pablo Neira Ayuso
@ 2021-06-08 10:07   ` Florian Westphal
  2021-06-08 10:16     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Westphal @ 2021-06-08 10:07 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: Phil Sutter, netfilter-devel, Florian Westphal

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Tue, Jun 08, 2021 at 11:40:57AM +0200, Phil Sutter wrote:
> > 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")
> > Suggested-by: Florian Westphal <fw@strlen.de>
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > Changes since v1:
> > - skb_copy_bits() call error handling added
> > ---
> >  net/netfilter/nft_exthdr.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
> > index 1b0579cb62d08..7f705b5c09de8 100644
> > --- a/net/netfilter/nft_exthdr.c
> > +++ b/net/netfilter/nft_exthdr.c
> > @@ -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?

Tcp exthdr either copies from skb linear area or a on-stack scratch space,
it looks ok to me.

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

* Re: [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
  2021-06-08 10:07   ` Florian Westphal
@ 2021-06-08 10:16     ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-06-08 10:16 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Phil Sutter, netfilter-devel

On Tue, Jun 08, 2021 at 12:07:54PM +0200, Florian Westphal wrote:
> Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> > On Tue, Jun 08, 2021 at 11:40:57AM +0200, Phil Sutter wrote:
> > > 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")
> > > Suggested-by: Florian Westphal <fw@strlen.de>
> > > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > > ---
> > > Changes since v1:
> > > - skb_copy_bits() call error handling added
> > > ---
> > >  net/netfilter/nft_exthdr.c | 4 +++-
> > >  1 file changed, 3 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
> > > index 1b0579cb62d08..7f705b5c09de8 100644
> > > --- a/net/netfilter/nft_exthdr.c
> > > +++ b/net/netfilter/nft_exthdr.c
> > > @@ -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?
> 
> 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.

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

* Re: [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read
  2021-06-08  9:40 [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read Phil Sutter
  2021-06-08  9:43 ` Florian Westphal
  2021-06-08  9:56 ` Pablo Neira Ayuso
@ 2021-06-08 10:38 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2021-06-08 10:38 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel, Florian Westphal

On Tue, Jun 08, 2021 at 11:40:57AM +0200, Phil Sutter wrote:
> 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.

Applied, thanks.

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

end of thread, other threads:[~2021-06-08 10:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08  9:40 [nf-next PATCH v2] netfilter: nft_exthdr: Fix for unsafe packet data read Phil Sutter
2021-06-08  9:43 ` Florian Westphal
2021-06-08  9:56 ` Pablo Neira Ayuso
2021-06-08 10:07   ` Florian Westphal
2021-06-08 10:16     ` Pablo Neira Ayuso
2021-06-08 10:38 ` Pablo Neira Ayuso

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.