Skip to contentSkip to conversation

l4_packet returning NF_DROP

PATCH In review Christoph Paasch 3 participants 9 messages Mar 12, 2009 – Mar 13, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

I have a question regarding the call to l4_packet, in nf_conntrack_in(...) from nf_conntrack_core.c

When a module like TCP returns -NF_DROP in tcp_packet(...), the packet won't get dropped, because NF_DROP = 0, and in nf_conntrack_in the return of the call to l4_packet is checked:

if (ret < 0) {
	...
}

So, there is no way to drop packets after l4_packet.

Why does this is implemented that way?

There are several points in tcp_packet where the function returns -NF_DROP and the comments in this function say that the packet will get blocked.

For example (from tcp_packet):

	if (index == TCP_SYNACK_SET
		    && ct->proto.tcp.last_index == TCP_SYN_SET
		    && ct->proto.tcp.last_dir != dir
		    && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
			/* b) This SYN/ACK acknowledges a SYN that we earlier
			 * ignored as invalid. This means that the client and
			 * the server are both in sync, while the firewall is
			 * not. We kill this session and block the SYN/ACK so
			 * that the client cannot but retransmit its SYN and
			 * thus initiate a clean new session.
			 */
			write_unlock_bh(&tcp_lock);
			if (LOG_INVALID(net, IPPROTO_TCP))
				nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
					  "nf_ct_tcp: killing out of sync session ");
			nf_ct_kill(ct);
			return -NF_DROP;
		}

I hope, that I was clear.
Could someone please explain this to me?
And how can I block packets after the call to l4_packet?

Thanks

--
Christoph Paasch

www.rollerbulls.be
--

#1 lore raw

Well, I have seen, that in one of the previous patches from pablo, he adds if (ret == -NF_DROP)

inside the if (ret < 0)

but as NF_DROP is 0, it won't ever enter in if(ret == -NF_DROP)

I will make a patch...

On Thu March 12 2009 wrote Christoph Paasch:

Quoted 44 lines

Hi,

I have a question regarding the call to l4_packet, in nf_conntrack_in(...) from nf_conntrack_core.c

When a module like TCP returns -NF_DROP in tcp_packet(...), the packet won't get dropped, because NF_DROP = 0, and in nf_conntrack_in the return of the call to l4_packet is checked:

if (ret < 0) {
	...
}

So, there is no way to drop packets after l4_packet.

Why does this is implemented that way?

There are several points in tcp_packet where the function returns -NF_DROP and the comments in this function say that the packet will get blocked.

For example (from tcp_packet):

	if (index == TCP_SYNACK_SET
		    && ct->proto.tcp.last_index == TCP_SYN_SET
		    && ct->proto.tcp.last_dir != dir
		    && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
			/* b) This SYN/ACK acknowledges a SYN that we earlier
			 * ignored as invalid. This means that the client and
			 * the server are both in sync, while the firewall is
			 * not. We kill this session and block the SYN/ACK so
			 * that the client cannot but retransmit its SYN and
			 * thus initiate a clean new session.
			 */
			write_unlock_bh(&tcp_lock);
			if (LOG_INVALID(net, IPPROTO_TCP))
				nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
					  "nf_ct_tcp: killing out of sync session ");
			nf_ct_kill(ct);
			return -NF_DROP;
		}

I hope, that I was clear.
Could someone please explain this to me?
And how can I block packets after the call to l4_packet?

Quoted 7 lines

Thanks

--
Christoph Paasch

www.rollerbulls.be
--

--
Christoph Paasch

www.rollerbulls.be
--

#2 lore raw

PATCH 1/1 netfilter: Allow dropping packet after call to l4proto->packet

As NF_DROP = 0, no packets would ever have been dropped.

---
 net/netfilter/nf_conntrack_core.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/netfilter/nf_conntrack_core.c +1 -1
index ebc2756..452db52 100644
@@ -727,7 +727,7 @@ nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
 	NF_CT_ASSERT(skb->nfct);
 
 	ret = l4proto->packet(ct, skb, dataoff, ctinfo, pf, hooknum);
-	if (ret < 0) {
+	if (ret <= 0) {
 		/* Invalid: inverse of the return code tells
 		 * the netfilter core what to do */
 		pr_debug("nf_conntrack_in: Can't track with proto module\n");
Signature · 1 line
1.5.6.3
#3 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

Quoted 1 line · Christoph Paasch

As NF_DROP = 0, no packets would ever have been dropped.

Mh would not it be safer to actually give NF_DROP a real value so that -NF_DROP also makes sense?
(Might need checking places where NF_DROP is used.)

#4 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

On Thu March 12 2009 wrote Jan Engelhardt:

Quoted 5 lines · Christoph Paasch
Quoted 1 line

As NF_DROP = 0, no packets would ever have been dropped.

Mh would not it be safer to actually give NF_DROP a real value so that -NF_DROP also makes sense?

Yes, why not...

Quoted 1 line

(Might need checking places where NF_DROP is used.)

NF_DROP is used only in tcp_packet (as far as I can see, no other l4 proto uses it in *_packet)

--
Christoph Paasch

www.rollerbulls.be
--

#5 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

Quoted 11 lines · Christoph Paasch

On Thu March 12 2009 wrote Jan Engelhardt:

Quoted 5 lines · Christoph Paasch
Quoted 1 line

As NF_DROP = 0, no packets would ever have been dropped.

Mh would not it be safer to actually give NF_DROP a real value so that -NF_DROP also makes sense?

Yes, why not...

Quoted 1 line

(Might need checking places where NF_DROP is used.)

NF_DROP is used only in tcp_packet (as far as I can see, no other l4 proto uses it in *_packet)

NF_DROP is also used in net/netfilter/x_tables.c - that's what I meant.

#7 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

In reply to Christoph Paasch
Quoted 1 line · Christoph Paasch

As NF_DROP = 0, no packets would ever have been dropped.

Good catch. I'll also change -NF_DROP by NF_DROP in nf_conntrack_proto_tcp.c. No need to resend the patch. Thanks.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#6 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

In reply to Jan Engelhardt
Quoted 7 lines · Jan Engelhardt
Quoted 1 line · Christoph Paasch

As NF_DROP = 0, no packets would ever have been dropped.

Mh would not it be safer to actually give NF_DROP a real value so that -NF_DROP also makes sense?
(Might need checking places where NF_DROP is used.)

We cannot change the current value of NF_DROP. This is exposed to userspace in libnetfilter_queue. Changing the value would break backward compatibility of existing applications.

Signature · 1 line
"Los honestos son inadaptados sociales" -- Les Luthiers
#8 lore raw

Re: [PATCH] netfilter: Allow dropping packet after call to l4proto->packet

In reply to Pablo Neira Ayuso

On Thu March 12 2009 wrote Pablo Neira Ayuso:

Quoted 5 lines
Quoted 1 line · Christoph Paasch

As NF_DROP = 0, no packets would ever have been dropped.

Good catch. I'll also change -NF_DROP by NF_DROP in nf_conntrack_proto_tcp.c. No need to resend the patch. Thanks.

OK, then change also -NF_DROP to NF_DROP in nf_conntrack_in(...), at if (ret == -NF_DROP)

--
Christoph Paasch

www.rollerbulls.be
--