Skip to contentSkip to conversation

: netfilter: ftp/irc/sane/sip/tftp: Fix the kernel panic when load these modules with duplicated ports

PATCH In review Feng Gao 2 participants 3 messages Sep 25, 2015 – Oct 21, 2015 3 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Feng Gao

author
#0 lore raw

PATCH 1/1 : netfilter: ftp/irc/sane/sip/tftp: Fix the kernel panic when load these modules with duplicated ports

Reset the helper->me to NULL when it fail to register helper. Then the fini function of these modules could avoid unregister wrong helper.

---
 net/netfilter/nf_conntrack_ftp.c  |    1 +
 net/netfilter/nf_conntrack_irc.c  |    7 +++++--
 net/netfilter/nf_conntrack_sane.c |    4 ++++
 net/netfilter/nf_conntrack_sip.c  |    1 +
 net/netfilter/nf_conntrack_tftp.c |    7 +++++--
 5 files changed, 16 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/net/netfilter/nf_conntrack_ftp.c
index b666959..fbc4b82 100644

net/netfilter/nf_conntrack_ftp.c +1 -0
@@ -630,6 +630,7 @@ static int __init nf_conntrack_ftp_init(void)
 				 ftp[i][j].tuple.src.l3num, ports[i]);
 			ret = nf_conntrack_helper_register(&ftp[i][j]);
 			if (ret) {
+				ftp[i][j].me = NULL;
 				printk(KERN_ERR "nf_ct_ftp: failed to

register"
" helper for pf: %d port: %d\n",
ftp[i][j].tuple.src.l3num,
ports[i]);

(quoted diff) +0 -0

b/net/netfilter/nf_conntrack_irc.c
index 0fd2976..7c99378 100644

net/netfilter/nf_conntrack_irc.c +1 -0
@@ -267,6 +267,7 @@ static int __init nf_conntrack_irc_init(void)
 
 		ret = nf_conntrack_helper_register(&irc[i]);
 		if (ret) {
+			irc[i].me = NULL;
 			printk(KERN_ERR "nf_ct_irc: failed to register

helper "
"for pf: %u port: %u\n", irc[i].tuple.src.l3num, ports[i]);
@@ -283,8 +284,10 @@ static void nf_conntrack_irc_fini(void)
{
int i;

- for (i = 0; i < ports_c; i++)
- nf_conntrack_helper_unregister(&irc[i]);
+ for (i = 0; i < ports_c; i++) {
+ if (irc[i].me)
+ nf_conntrack_helper_unregister(&irc[i]);
+ }
kfree(irc_buffer);
}

(quoted diff) +0 -0

b/net/netfilter/nf_conntrack_sane.c
index 4a2134f..f4986df 100644

net/netfilter/nf_conntrack_sane.c +3 -0
@@ -178,6 +178,9 @@ static void nf_conntrack_sane_fini(void)
 
 	for (i = 0; i < ports_c; i++) {
 		for (j = 0; j < 2; j++) {
+			if (!sane[i][j].me)
+				continue;
+
 			pr_debug("nf_ct_sane: unregistering helper for pf:

%d "
"port: %d\n", sane[i][j].tuple.src.l3num, ports[i]);
@@ -221,6 +224,7 @@ static int __init nf_conntrack_sane_init(void)
sane[i][j].tuple.src.l3num, ports[i]);
ret = nf_conntrack_helper_register(&sane[i][j]); if (ret) {
+ sane[i][j].me = NULL;
printk(KERN_ERR "nf_ct_sane: failed to "
"register helper for pf: %d port:
%d\n",
sane[i][j].tuple.src.l3num,
ports[i]);

(quoted diff) +0 -0

b/net/netfilter/nf_conntrack_sip.c
index 885b4ab..53cd48a 100644

net/netfilter/nf_conntrack_sip.c +1 -0
@@ -1665,6 +1665,7 @@ static int __init nf_conntrack_sip_init(void)
 
 			ret = nf_conntrack_helper_register(&sip[i][j]);
 			if (ret) {
+				sip[i][j].me = NULL;
 				printk(KERN_ERR "nf_ct_sip: failed to

register"
" helper for pf: %u port: %u\n", sip[i][j].tuple.src.l3num, ports[i]);

(quoted diff) +0 -0

b/net/netfilter/nf_conntrack_tftp.c
index e68ab4f..8255b21 100644

net/netfilter/nf_conntrack_tftp.c +5 -2
@@ -107,8 +107,10 @@ static void nf_conntrack_tftp_fini(void)
 	int i, j;
 
 	for (i = 0; i < ports_c; i++) {
-		for (j = 0; j < 2; j++)
-			nf_conntrack_helper_unregister(&tftp[i][j]);
+		for (j = 0; j < 2; j++) {
+			if (tftp[i][j].me)
+				nf_conntrack_helper_unregister(&tftp[i][j]);
+		}
 	}
 }
 
@@ -138,6 +140,7 @@ static int __init nf_conntrack_tftp_init(void)
 
 			ret = nf_conntrack_helper_register(&tftp[i][j]);
 			if (ret) {
+				tftp[i][j].me = NULL;
 				printk(KERN_ERR "nf_ct_tftp: failed to

register"
" helper for pf: %u port: %u\n",
tftp[i][j].tuple.src.l3num,
ports[i]);

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 10 lines · Feng Gao

Hi Pablo,

When execute " insmod nf_conntrack_ftp.ko ports=76,76,76", the kernel crashes immediately.
Because the old codes try to unregister the helper which is not registered successfully.
This bug has existed for a long time since the nf_conntrack_helper_register checked the duplicated entry.

I don't know if I should add the reproduce process in the commit comment.

That's good idea to insist on the fact that this bug is crashing the kernel, and that is not good.

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 3 lines · Feng Gao

Hi Pablo,

How about this patch? It will be applied?

Could you investigate if it would be possible to add a nf_conntrack_helpers_register()?

The idea is to have a native function that handles array of helpers. We have something similar for _hooks.

Moreover, reduce the length of your patch subject to ~80 chars if possible.

Thanks.