Skip to contentSkip to conversation

: Add NetBIOS name service helper

PATCH In review Patrick McHardy 3 participants 8 messages Sep 6, 2005 – Sep 7, 2005

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

PATCH 2/8 : Add NetBIOS name service helper

[NETFILTER]: Add NetBIOS name service helper

---
commit b057eac5e17bda8e06a6f3241a837d415a18be4d
tree fd37ca39beae9fad2e0ce5a652756ebc5f9acaab
parent d6d0e225ee3dd43d2a14fbd0aaded74bc7d45da1
author Patrick McHardy <[email protected]> Sun, 04 Sep 2005 17:50:41 +0200 committer Patrick McHardy <[email protected]> Sun, 04 Sep 2005 17:50:41 +0200

 net/ipv4/netfilter/Kconfig  |   19 +++++++++++++++++++
 net/ipv4/netfilter/Makefile |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)
net/ipv4/netfilter/Kconfig +19 -0
@@ -85,6 +85,25 @@ config IP_NF_IRC
 
 	  To compile it as a module, choose M here.  If unsure, say Y.
 
+config IP_NF_NETBIOS_NS
+	tristate "NetBIOS name service protocol support (EXPERIMENTAL)"
+	depends on IP_NF_CONNTRACK && EXPERIMENTAL
+	help
+	  NetBIOS name service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating NetBIOS name service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address. When properly configured, the output
+	  of "ip address show" should look similar to this:
+
+	  $ ip -4 address show eth0
+	  4: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
+	      inet 172.16.2.252/24 brd 172.16.2.255 scope global eth0
+	  
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config IP_NF_TFTP
 	tristate "TFTP protocol support"
 	depends on IP_NF_CONNTRACK
net/ipv4/netfilter/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_IP_NF_AMANDA) += ip_conntra
 obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
 obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
+obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o
 
 # NAT helpers 
 obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o
#1 lore raw
Quoted 5 lines · Patrick McHardy

[NETFILTER]: Add NetBIOS name service helper

 net/ipv4/netfilter/Kconfig  |   19 +++++++++++++++++++
 net/ipv4/netfilter/Makefile |    1 +
 2 files changed, 20 insertions(+), 0 deletions(-)

Oops, I forgot to add the helper itself :) Updated patch attached.

[NETFILTER]: Add NetBIOS name service helper

---
commit 85bc351b1e912ddda397f10da5961b7b843c66b1
tree 2357ca08f9e7c1ac26701c7d24b709f4837a915c
parent d6d0e225ee3dd43d2a14fbd0aaded74bc7d45da1
author Patrick McHardy <[email protected]> Tue, 06 Sep 2005 20:09:02 +0200 committer Patrick McHardy <[email protected]> Tue, 06 Sep 2005 20:09:02 +0200

 net/ipv4/netfilter/Kconfig                   |   19 ++++
 net/ipv4/netfilter/Makefile                  |    1 
 net/ipv4/netfilter/ip_conntrack_netbios_ns.c |  131 ++++++++++++++++++++++++++
 3 files changed, 151 insertions(+), 0 deletions(-)
net/ipv4/netfilter/Kconfig +19 -0
@@ -85,6 +85,25 @@ config IP_NF_IRC
 
 	  To compile it as a module, choose M here.  If unsure, say Y.
 
+config IP_NF_NETBIOS_NS
+	tristate "NetBIOS name service protocol support (EXPERIMENTAL)"
+	depends on IP_NF_CONNTRACK && EXPERIMENTAL
+	help
+	  NetBIOS name service requests are sent as broadcast messages from an
+	  unprivileged port and responded to with unicast messages to the
+	  same port. This make them hard to firewall properly because connection
+	  tracking doesn't deal with broadcasts. This helper tracks locally
+	  originating NetBIOS name service requests and the corresponding
+	  responses. It relies on correct IP address configuration, specifically
+	  netmask and broadcast address. When properly configured, the output
+	  of "ip address show" should look similar to this:
+
+	  $ ip -4 address show eth0
+	  4: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 1000
+	      inet 172.16.2.252/24 brd 172.16.2.255 scope global eth0
+	  
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config IP_NF_TFTP
 	tristate "TFTP protocol support"
 	depends on IP_NF_CONNTRACK
net/ipv4/netfilter/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_IP_NF_AMANDA) += ip_conntra
 obj-$(CONFIG_IP_NF_TFTP) += ip_conntrack_tftp.o
 obj-$(CONFIG_IP_NF_FTP) += ip_conntrack_ftp.o
 obj-$(CONFIG_IP_NF_IRC) += ip_conntrack_irc.o
+obj-$(CONFIG_IP_NF_NETBIOS_NS) += ip_conntrack_netbios_ns.o
 
 # NAT helpers 
 obj-$(CONFIG_IP_NF_NAT_AMANDA) += ip_nat_amanda.o
net/ipv4/netfilter/ip_conntrack_netbios_ns.c new file +131 -0

131 lines not on this page · raw message

#2 lore raw
Quoted 3 lines · Patrick McHardy

[NETFILTER]: Add NetBIOS name service helper

Hi,
this attached patch fix the return valued when creating expectation failed.
Please apply.

regards,
Samir Bellabes

tree b731304f287168ee36e45517dffdf27ea9dfe47c
parent 48bc41a49c4f3aa760dff84e7f71437f5ed520fe
author Samir Bellabes <[email protected]> 1126061246 +0200 committer Samir Bellabes <[email protected]> 1126061246 +0200

[NETFILTER] Return NF_DROP if expectation failed for Netbios conntrack

Fix the returned value when it's not possible to allocate expectation or if ip_conntrack_expect_related() failed.

------------------------------------------------------------------------------

 ip_conntrack_netbios_ns.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

------------------------------------------------------------------------------

net/ipv4/netfilter/ip_conntrack_netbios_ns.c +3 -2
@@ -77,7 +77,7 @@ static int help(struct sk_buff **pskb,
 
 	exp = ip_conntrack_expect_alloc(ct);
 	if (exp == NULL)
-		goto out;
+		return NF_DROP;
 	memset(&exp->tuple, 0, sizeof(exp->tuple));
 	exp->tuple.src.ip         = iph->daddr & mask;
 	exp->tuple.dst.ip         = iph->saddr;
@@ -93,7 +93,8 @@ static int help(struct sk_buff **pskb,
 	exp->expectfn             = NULL;
 	exp->flags                = IP_CT_EXPECT_PERMANENT;
 
-	ip_conntrack_expect_related(exp);
+	if (ip_conntrack_expect_related(exp) != 0)
+		return NF_DROP;
 	ip_conntrack_expect_put(exp);
 
 	ip_ct_refresh_acct(ct, ctinfo, NULL, timeout * HZ);
maintainer
#3 lore raw

From: Samir Bellabes <[email protected]>
Subject: Re: [NETFILTER 2/8]: Add NetBIOS name service helper
Date: Wed, 07 Sep 2005 04:50:16 +0200

Quoted 6 lines

[NETFILTER] Return NF_DROP if expectation failed for Netbios conntrack

Fix the returned value when it's not possible to allocate expectation or if ip_conntrack_expect_related() failed.

Patrick, I've applied this, I hope you don't mind :)

#4 lore raw
Quoted 7 lines · David S. Miller

From: Samir Bellabes <[email protected]>
Subject: Re: [NETFILTER 2/8]: Add NetBIOS name service helper
Date: Wed, 07 Sep 2005 04:50:16 +0200

Quoted 2 lines

[NETFILTER] Return NF_DROP if expectation failed for Netbios conntrack

Quoted 7 lines
Quoted 4 lines

Fix the returned value when it's not possible to allocate expectation or if ip_conntrack_expect_related() failed.

Patrick, I've applied this, I hope you don't mind :)

Actually it was deliberate, I don't see a reason why the packet should be dropped, its best effort. Besides that the patch creates a reference leak, we always need to call ip_conntrack_expect_put. Please revert the patch. Thanks.

maintainer
#5 lore raw

From: Patrick McHardy <[email protected]>
Date: Wed, 07 Sep 2005 05:01:20 +0200

Quoted 4 lines

Actually it was deliberate, I don't see a reason why the packet should be dropped, its best effort. Besides that the patch creates a reference leak, we always need to call ip_conntrack_expect_put. Please revert the patch. Thanks.

Ok, will do.

#6 lore raw
In reply to Patrick McHardy
Quoted 8 lines · Patrick McHardy
Quoted 5 lines
Quoted 4 lines

[NETFILTER] Return NF_DROP if expectation failed for Netbios conntrack Fix the returned value when it's not possible to allocate expectation or if ip_conntrack_expect_related() failed.

Patrick, I've applied this, I hope you don't mind :)

Actually it was deliberate, I don't see a reason why the packet should be dropped, its best effort.

All conntracks are dropping packets, in that way. netbios_ns should do the same, or other conntracks should be patched.

Quoted 3 lines

Besides that the patch
creates a reference leak, we always need to call ip_conntrack_expect_put. Please revert the patch. Thanks.

You are right, i'm proposing this patch, which don't introduce the reference leak.

regards,
Samir Bellabes

tree 04acb82014fc0e82fa4c77dae5e2281e90b366c8
parent 48bc41a49c4f3aa760dff84e7f71437f5ed520fe
author Samir Bellabes <[email protected]> 1126085733 +0200 committer Samir Bellabes <[email protected]> 1126085733 +0200

[NETFILTER] Return NF_DROP if expectation failed for Netbios conntrack

Fix the returned value when it's not possible to allocate expectation or if ip_conntrack_expect_related() failed.

------------------------------------------------------------------------------

 ip_conntrack_netbios_ns.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

------------------------------------------------------------------------------

net/ipv4/netfilter/ip_conntrack_netbios_ns.c +7 -3
@@ -48,6 +48,7 @@ static int help(struct sk_buff **pskb,
 	struct rtable *rt = (struct rtable *)(*pskb)->dst;
 	struct in_device *in_dev;
 	u_int32_t mask = 0;
+	int ret = NF_ACCEPT;
 
 	/* we're only interested in locally generated packets */
 	if ((*pskb)->sk == NULL)
@@ -76,8 +77,10 @@ static int help(struct sk_buff **pskb,
 	BUG_ON(uh == NULL);
 
 	exp = ip_conntrack_expect_alloc(ct);
-	if (exp == NULL)
+	if (exp == NULL) {
+		ret = NF_DROP;
 		goto out;
+	}
 	memset(&exp->tuple, 0, sizeof(exp->tuple));
 	exp->tuple.src.ip         = iph->daddr & mask;
 	exp->tuple.dst.ip         = iph->saddr;
@@ -93,12 +96,13 @@ static int help(struct sk_buff **pskb,
 	exp->expectfn             = NULL;
 	exp->flags                = IP_CT_EXPECT_PERMANENT;
 
-	ip_conntrack_expect_related(exp);
+	if (ip_conntrack_expect_related(exp) !=0)
+		ret = NF_DROP;
 	ip_conntrack_expect_put(exp);
 
 	ip_ct_refresh_acct(ct, ctinfo, NULL, timeout * HZ);
 out:
-	return NF_ACCEPT;
+	return ret;
 }
 
 static struct ip_conntrack_helper helper = {
#7 lore raw
Quoted 7 lines · Samir Bellabes
Quoted 2 lines · Patrick McHardy

Actually it was deliberate, I don't see a reason why the packet should be dropped, its best effort.

All conntracks are dropping packets, in that way. netbios_ns should do the same, or other conntracks should be patched.

Dropping when NAT fails makes sense because the reply packet must be handled and the state is required for this. Dropping when setting up an expectation fails doesn't make any sense to me, the reply could still make it because for example there are no rules or it is accepted by the rulesset.

Connection tracking only does tracking, not filtering, and should only drop packets if necessary for accurate tracking.

Look at the FTP helper for example. It also tracks passive mode connections, which are in many cases allowed by the ruleset anyway. By dropping the packet we break what might work otherwise.

So I think changing the other helpers to only drop when really neccesary also makes sense.