All of lore.kernel.org
 help / color / mirror / Atom feed
* [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
@ 2016-06-20 13:26 Liping Zhang
  2016-06-20 15:48 ` Marcelo Ricardo Leitner
  2016-06-23 17:33 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 6+ messages in thread
From: Liping Zhang @ 2016-06-20 13:26 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, Liping Zhang

From: Liping Zhang <liping.zhang@spreadtrum.com>

In iptables, if the user add a rule to send tcp RST and specify the
non-TCP protocol, such as UDP, kernel will reject this request. But
in nftables, this validity check only occurs in nft tool, i.e. only
in userspace.

This means that user can add such a rule like follows via nfnetlink:
  "nft add rule filter forward ip protocol udp reject with tcp reset"

This will generate some confusing tcp RST packets. So we should send
tcp RST only when it is TCP packet.

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
---
 net/ipv4/netfilter/nf_reject_ipv4.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
index b6ea57e..fd82202 100644
--- a/net/ipv4/netfilter/nf_reject_ipv4.c
+++ b/net/ipv4/netfilter/nf_reject_ipv4.c
@@ -24,6 +24,9 @@ const struct tcphdr *nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,
 	if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
 		return NULL;
 
+	if (ip_hdr(oldskb)->protocol != IPPROTO_TCP)
+		return NULL;
+
 	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
 				 sizeof(struct tcphdr), _oth);
 	if (oth == NULL)
-- 
1.7.9.5



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

* Re: [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
  2016-06-20 13:26 [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP Liping Zhang
@ 2016-06-20 15:48 ` Marcelo Ricardo Leitner
  2016-06-21  1:35   ` Liping Zhang
  2016-06-23 17:33 ` Pablo Neira Ayuso
  1 sibling, 1 reply; 6+ messages in thread
From: Marcelo Ricardo Leitner @ 2016-06-20 15:48 UTC (permalink / raw)
  To: Liping Zhang; +Cc: pablo, netfilter-devel, Liping Zhang

Hi Liping,

On Mon, Jun 20, 2016 at 09:26:28PM +0800, Liping Zhang wrote:
> From: Liping Zhang <liping.zhang@spreadtrum.com>
> 
> In iptables, if the user add a rule to send tcp RST and specify the
> non-TCP protocol, such as UDP, kernel will reject this request. But
> in nftables, this validity check only occurs in nft tool, i.e. only
> in userspace.
> 
> This means that user can add such a rule like follows via nfnetlink:
>   "nft add rule filter forward ip protocol udp reject with tcp reset"
> 
> This will generate some confusing tcp RST packets. So we should send
> tcp RST only when it is TCP packet.
> 
> Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
> ---
>  net/ipv4/netfilter/nf_reject_ipv4.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/ipv4/netfilter/nf_reject_ipv4.c b/net/ipv4/netfilter/nf_reject_ipv4.c
> index b6ea57e..fd82202 100644
> --- a/net/ipv4/netfilter/nf_reject_ipv4.c
> +++ b/net/ipv4/netfilter/nf_reject_ipv4.c
> @@ -24,6 +24,9 @@ const struct tcphdr *nf_reject_ip_tcphdr_get(struct sk_buff *oldskb,
>  	if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
>  		return NULL;
>  
> +	if (ip_hdr(oldskb)->protocol != IPPROTO_TCP)
> +		return NULL;
> +
>  	oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
>  				 sizeof(struct tcphdr), _oth);
>  	if (oth == NULL)

A different check/log is made for ip6:
nf_reject_ip6_tcphdr_get():
        /* IP header checks: fragment, too short. */
        if (proto != IPPROTO_TCP || *otcplen < sizeof(struct tcphdr)) {
                pr_debug("proto(%d) != IPPROTO_TCP or too short (len = %d)\n",
                         proto, *otcplen);
                return NULL;
        }

Would be nice to have some consistency on this log message as it
increases debug-ability.

  Marcelo


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

* Re: [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
  2016-06-20 15:48 ` Marcelo Ricardo Leitner
@ 2016-06-21  1:35   ` Liping Zhang
  2016-06-21 19:03     ` Marcelo Ricardo Leitner
  0 siblings, 1 reply; 6+ messages in thread
From: Liping Zhang @ 2016-06-21  1:35 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: Liping Zhang, pablo, netfilter-devel, Liping Zhang

Hi Marcelo,

2016-06-20 23:48 GMT+08:00 Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>:
>
> A different check/log is made for ip6:
> nf_reject_ip6_tcphdr_get():
>         /* IP header checks: fragment, too short. */
>         if (proto != IPPROTO_TCP || *otcplen < sizeof(struct tcphdr)) {
>                 pr_debug("proto(%d) != IPPROTO_TCP or too short (len = %d)\n",
>                          proto, *otcplen);
>                 return NULL;
>         }
>
> Would be nice to have some consistency on this log message as it
> increases debug-ability.
>

Thanks for your opinion.

But you can see, there are many inconsistent things between
nf_reject_ip6_tcphdr_get and nf_reject_ip_tcphdr_get.

For example, when tcp->rst is set, reject_ip6 will call
pr_debug("RST is set\n"), while there's nothing in reject_ip4.

IMO, these debug informations are almost useless, so there's
no need to add this debug info only for consistent with nf_reject_ip6.

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

* Re: [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
  2016-06-21  1:35   ` Liping Zhang
@ 2016-06-21 19:03     ` Marcelo Ricardo Leitner
  2016-06-23 11:53       ` Pablo Neira Ayuso
  0 siblings, 1 reply; 6+ messages in thread
From: Marcelo Ricardo Leitner @ 2016-06-21 19:03 UTC (permalink / raw)
  To: Liping Zhang; +Cc: Liping Zhang, pablo, netfilter-devel, Liping Zhang

On Tue, Jun 21, 2016 at 09:35:55AM +0800, Liping Zhang wrote:
> Hi Marcelo,
> 
> 2016-06-20 23:48 GMT+08:00 Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>:
> >
> > A different check/log is made for ip6:
> > nf_reject_ip6_tcphdr_get():
> >         /* IP header checks: fragment, too short. */
> >         if (proto != IPPROTO_TCP || *otcplen < sizeof(struct tcphdr)) {
> >                 pr_debug("proto(%d) != IPPROTO_TCP or too short (len = %d)\n",
> >                          proto, *otcplen);
> >                 return NULL;
> >         }
> >
> > Would be nice to have some consistency on this log message as it
> > increases debug-ability.
> >
> 
> Thanks for your opinion.
> 
> But you can see, there are many inconsistent things between
> nf_reject_ip6_tcphdr_get and nf_reject_ip_tcphdr_get.

That's true, yet sooner or later we can catch up the differences.

> 
> For example, when tcp->rst is set, reject_ip6 will call
> pr_debug("RST is set\n"), while there's nothing in reject_ip4.
> 
> IMO, these debug informations are almost useless, so there's
> no need to add this debug info only for consistent with nf_reject_ip6.

Fair enough. Although I did the comment, I don't have a strong opinion
on this.

Thanks,
Marcelo


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

* Re: [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
  2016-06-21 19:03     ` Marcelo Ricardo Leitner
@ 2016-06-23 11:53       ` Pablo Neira Ayuso
  0 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2016-06-23 11:53 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: Liping Zhang, Liping Zhang, netfilter-devel, Liping Zhang

On Tue, Jun 21, 2016 at 04:03:01PM -0300, Marcelo Ricardo Leitner wrote:
> On Tue, Jun 21, 2016 at 09:35:55AM +0800, Liping Zhang wrote:
> > For example, when tcp->rst is set, reject_ip6 will call
> > pr_debug("RST is set\n"), while there's nothing in reject_ip4.
> > 
> > IMO, these debug informations are almost useless, so there's
> > no need to add this debug info only for consistent with nf_reject_ip6.
> 
> Fair enough. Although I did the comment, I don't have a strong opinion
> on this.

I'd take a patch to get rid of those pr_debug() in nf_reject_ip6.

Thanks.

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

* Re: [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP
  2016-06-20 13:26 [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP Liping Zhang
  2016-06-20 15:48 ` Marcelo Ricardo Leitner
@ 2016-06-23 17:33 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2016-06-23 17:33 UTC (permalink / raw)
  To: Liping Zhang; +Cc: netfilter-devel, Liping Zhang

On Mon, Jun 20, 2016 at 09:26:28PM +0800, Liping Zhang wrote:
> From: Liping Zhang <liping.zhang@spreadtrum.com>
> 
> In iptables, if the user add a rule to send tcp RST and specify the
> non-TCP protocol, such as UDP, kernel will reject this request. But
> in nftables, this validity check only occurs in nft tool, i.e. only
> in userspace.
> 
> This means that user can add such a rule like follows via nfnetlink:
>   "nft add rule filter forward ip protocol udp reject with tcp reset"
> 
> This will generate some confusing tcp RST packets. So we should send
> tcp RST only when it is TCP packet.

Applied, thanks.

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

end of thread, other threads:[~2016-06-23 17:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-20 13:26 [PACTH nf-next] netfilter: nf_reject_ipv4: don't send tcp RST if the packet is non-TCP Liping Zhang
2016-06-20 15:48 ` Marcelo Ricardo Leitner
2016-06-21  1:35   ` Liping Zhang
2016-06-21 19:03     ` Marcelo Ricardo Leitner
2016-06-23 11:53       ` Pablo Neira Ayuso
2016-06-23 17:33 ` 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.